diff --git a/tgarchive/__init__.py b/tgarchive/__init__.py index dc67f22..8ce3f56 100644 --- a/tgarchive/__init__.py +++ b/tgarchive/__init__.py @@ -7,7 +7,7 @@ from .db import DB -__version__ = "1.0.0" +__version__ = "1.1.0" logging.basicConfig(format="%(asctime)s: %(message)s", level=logging.INFO) @@ -37,6 +37,7 @@ "telegram_url": "https://t.me/{id}", "per_page": 1000, "show_sender_fullname": False, + "timezone": "", "site_name": "@{group} (Telegram) archive", "site_description": "Public archive of @{group} Telegram messages.", "meta_description": "@{group} {date} Telegram message archive.", @@ -153,7 +154,7 @@ def main(): logging.info("building site") config = get_config(args.config) - b = Build(config, DB(args.data), args.symlink) + b = Build(config, DB(args.data, config["timezone"]), args.symlink) b.load_template(args.template) if args.rss_template: b.load_rss_template(args.rss_template) diff --git a/tgarchive/build.py b/tgarchive/build.py index 2dc971b..f8be742 100644 --- a/tgarchive/build.py +++ b/tgarchive/build.py @@ -6,7 +6,6 @@ import re import shutil import magic -from datetime import timezone from feedgen.feed import FeedGenerator from jinja2 import Template @@ -143,8 +142,8 @@ def _build_rss(self, messages, rss_file, atom_file): e = f.add_entry() e.id(url) e.title("@{} on {} (#{})".format(m.user.username, m.date, m.id)) - e.published(m.date.replace(tzinfo=timezone.utc)) e.link({"href": url}) + e.published(m.date) media_mime = "" if m.media and m.media.url: diff --git a/tgarchive/db.py b/tgarchive/db.py index 11c6793..a5fd519 100644 --- a/tgarchive/db.py +++ b/tgarchive/db.py @@ -4,7 +4,7 @@ import sqlite3 from collections import namedtuple from datetime import datetime -import json +import pytz from typing import Iterator schema = """ @@ -60,8 +60,9 @@ def _page(n, multiple): class DB: conn = None + tz = None - def __init__(self, dbfile): + def __init__(self, dbfile, tz=None): # Initialize the SQLite DB. If it's new, create the table schema. is_new = not os.path.isfile(dbfile) @@ -72,6 +73,9 @@ def __init__(self, dbfile): # by its row number and a limit multiple. self.conn.create_function("PAGE", 2, _page) + if tz: + self.tz = pytz.timezone(tz) + if is_new: for s in schema.split("##"): self.conn.cursor().execute(s) @@ -225,6 +229,13 @@ def _make_message(self, m) -> Message: description=desc, thumb=media_thumb) + date = pytz.utc.localize(date) if date else None + edit_date = pytz.utc.localize(edit_date) if edit_date else None + + if self.tz: + date = date.astimezone(self.tz) if date else None + edit_date = edit_date.astimezone(self.tz) if edit_date else None + return Message(id=id, type=typ, date=date, diff --git a/tgarchive/example/config.yaml b/tgarchive/example/config.yaml index 7d840b5..d7e7e12 100644 --- a/tgarchive/example/config.yaml +++ b/tgarchive/example/config.yaml @@ -61,6 +61,11 @@ telegram_url: "https://t.me/{id}" # phonebook for users who are in your phonebook. show_sender_fullname: False +# Timezone to apply on timestamps when building the site. If no value +# is specified, all timestamps are in UTC: +# Eg: US/Eastern Asia/Kolkata +timezone: "" + publish_rss_feed: True rss_feed_entries: 100 # Show Latest N messages in the RSS feed.