Browse Source

logbot saves post under local timezone now (which is the timezone of the server)

master
manetta 3 years ago
parent
commit
c13612a69d
  1. 12
      LogBot/logbot.py

12
LogBot/logbot.py

@ -2,7 +2,8 @@ import os
import re import re
import shutil import shutil
import urllib.request import urllib.request
from datetime import datetime from datetime import datetime, timezone
import pytz
from urllib.parse import urlparse from urllib.parse import urlparse
from mimetypes import guess_type from mimetypes import guess_type
import jinja2 import jinja2
@ -102,7 +103,9 @@ class Logbot(Bot):
if "@" in folder_name: # hacky if "@" in folder_name: # hacky
folder_name = self._parse_room_name(folder_name) folder_name = self._parse_room_name(folder_name)
feed_path = os.path.join(self.output, folder_name, "feed.rss.xml") feed_path = os.path.join(self.output, folder_name, "feed.rss.xml")
date = datetime.now() local_timezone = str(datetime.now(timezone.utc).astimezone().tzinfo)
date = datetime.now(pytz.timezone(local_timezone)).strftime("%a, %d %b %Y %H:%M:%S %Z") # logs are saved with local timezone
print(date)
template = jinja2.Template(open("template.rss").read()) # self.feedtemplate would be useful to have in the conf template = jinja2.Template(open("template.rss").read()) # self.feedtemplate would be useful to have in the conf
with open(feed_path, "w") as out: with open(feed_path, "w") as out:
feed = template.render( feed = template.render(
@ -110,7 +113,7 @@ class Logbot(Bot):
feed_path=os.path.join(self.baseurl, folder_name, "feed.rss.xml"), feed_path=os.path.join(self.baseurl, folder_name, "feed.rss.xml"),
title=self.db[message.room]["title"], title=self.db[message.room]["title"],
db=self.db[message.room], db=self.db[message.room],
date=date.strftime("%a, %d %b %Y %H:%M:%S +0100"), # timezone is hardcoded now date=date,
log_folder_url=os.path.join(self.baseurl, folder_name), log_folder_url=os.path.join(self.baseurl, folder_name),
) )
out.write(feed) out.write(feed)
@ -120,7 +123,8 @@ class Logbot(Bot):
"""Save new entry to database.""" """Save new entry to database."""
keys = [x for x in self.db[message.room]["messages"].keys()] keys = [x for x in self.db[message.room]["messages"].keys()]
keys.sort(key=int) keys.sort(key=int)
date = datetime.now().strftime("%a, %d %b %Y %H:%M:%S +0100") # timezone is hardcoded now local_timezone = str(datetime.now(timezone.utc).astimezone().tzinfo)
date = datetime.now(pytz.timezone(local_timezone)).strftime("%a, %d %b %Y %H:%M:%S %Z") # logs are saved with local timezone
if not keys: if not keys:
new_key = "0" new_key = "0"
else: else:

Loading…
Cancel
Save