human readeable time.

This commit is contained in:
Gaël Honorez
2024-01-02 18:30:54 +01:00
parent 2db0a6543f
commit cfe4c70a32

View File

@@ -58,6 +58,23 @@ class SubStackTask:
LOG.info("Adding feed " + feed.url)
def format_duration(self, seconds):
days, seconds = divmod(seconds, 86400)
hours, seconds = divmod(seconds, 3600)
minutes, seconds = divmod(seconds, 60)
parts = []
if days > 0:
parts.append(f"{days} days")
if hours > 0:
parts.append(f"{hours} hours")
if minutes > 0:
parts.append(f"{minutes} minutes")
if seconds > 0:
parts.append(f"{seconds} seconds")
return ', '.join(parts) if parts else '0 seconds'
def get_fr_date(self):
# Mapping of English month names to French
months_en_to_fr = {
@@ -82,7 +99,8 @@ class SubStackTask:
while sleep_seconds > 0:
# Check if the remaining time is a multiple of 3600 seconds
LOG.info(f"Waiting for {sleep_seconds} seconds for next scan")
formatted_duration = self.format_duration(sleep_seconds)
LOG.info(f"Waiting for {formatted_duration} seconds for next scan")
# Wait for some time before checking again
await asyncio.sleep(min(sleep_seconds, 5 * 60))
@@ -104,6 +122,9 @@ class SubStackTask:
LOG.info("Running daily task : " + str(title_post))
ff = r'/data/feeds.txt'
if os.path.isfile(ff) is False:
ff = r'x:\substack\feeds.txt'
self.feeds = []
with open(ff) as file:
lines = [line.rstrip() for line in file]
@@ -210,6 +231,8 @@ async def main(login, password, account):
feeds = []
ff = r'/data/feeds.txt'
if os.path.isfile(ff) is False:
ff = r'x:\substack\feeds.txt'
with open(ff) as file:
lines = [line.rstrip() for line in file]