From 3e16943f326460cb6a7a909ed00f1dd7a57697f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaume=20Delcl=C3=B2s=20Coll?= Date: Thu, 29 Oct 2020 17:10:54 +0100 Subject: [PATCH] timezone info --- README.md | 1 + setup.py | 1 + ttbp/atom.py | 11 +++++++---- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 61c6113..f10cb38 100644 --- a/README.md +++ b/README.md @@ -238,6 +238,7 @@ instance of this yourself) * [six](https://pypi.python.org/pypi/six) * [colorama](https://pypi.python.org/pypi/colorama) * [feedgen](https://pypi.python.org/pypi/feedgen) +* [dateutil](https://pypi.python.org/pypi/python-dateutil) ### contributing diff --git a/setup.py b/setup.py index a02f2e6..8e2ec14 100644 --- a/setup.py +++ b/setup.py @@ -22,6 +22,7 @@ setup( 'colorama', 'six', 'feedgen', + 'python-dateutil', ], include_package_data = True, entry_points = { diff --git a/ttbp/atom.py b/ttbp/atom.py index 46cc255..0d542b5 100644 --- a/ttbp/atom.py +++ b/ttbp/atom.py @@ -38,7 +38,7 @@ import os import mistune import datetime import stat -import time +from dateutil import tz def publish_atom(entry_filenames, settings): fg = FeedGenerator() @@ -50,6 +50,7 @@ def publish_atom(entry_filenames, settings): fg.link(href=url+'/', rel='alternate') fg.link(href=url+'/atom.xml', rel='self') fg.language('en') # TODO: feels language should be configurable + fg.updated(datetime.datetime.now(tz.tzlocal())) for filename in sorted(entry_filenames): date = util.parse_date(filename) @@ -68,11 +69,13 @@ def publish_atom(entry_filenames, settings): fe.author(name=config.USER) fe.content(html, type="html") try: # crashing because of an invalid date would be sad - fe.published("-".join(date)+"T00:00:00Z") + year, month, day = [int(x) for x in date] + fe.published(datetime.datetime(year, month, day, + tzinfo=tz.tzlocal())) stats = os.stat(path) updated = datetime.datetime.fromtimestamp(stats[stat.ST_MTIME], - datetime.timezone.utc) - fe.updated(updated.strftime('%Y-%m-%dT%H:%M:%SZ')) + tz.tzlocal()) + fe.updated(updated) except ValueError: pass outfile = os.path.join(config.WWW, 'atom.xml')