From 92ced4c91bd6cbe86a4ed245da6b8c649d375fd4 Mon Sep 17 00:00:00 2001 From: Miroslavsckaya Date: Sun, 10 Jul 2022 17:40:19 +0300 Subject: [PATCH] Fix representation date in FeedItem (#38) Reviewed-on: https://git.skobk.in/Miroslavsckaya/tg_rss_bot/pulls/38 Reviewed-by: Alexey Skobkin --- README.md | 7 +++++++ rss.py | 5 +++-- telegram.py | 7 +++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index be1998b..2439a59 100644 --- a/README.md +++ b/README.md @@ -37,3 +37,10 @@ export TELEGRAM_TOKEN=xxx export DATABASE_PATH=./database.db python bot.py ``` +## Running the update + +```shell +export TELEGRAM_TOKEN=xxx +export DATABASE_PATH=./database.db +python update.py +``` \ No newline at end of file diff --git a/rss.py b/rss.py index eeeaa01..d591843 100644 --- a/rss.py +++ b/rss.py @@ -1,5 +1,6 @@ from logging import Logger - +from datetime import datetime +from time import mktime from feedparser import FeedParserDict, parse @@ -9,7 +10,7 @@ class FeedItem: self.title = item.get('title', '') self.description = item.get('summary', '') if 'published' in item: - self.date = item.published_parsed + self.date = datetime.fromtimestamp(mktime(item.published_parsed)) else: self.date = None diff --git a/telegram.py b/telegram.py index 7860b45..27e44dd 100644 --- a/telegram.py +++ b/telegram.py @@ -1,7 +1,6 @@ import time - -from bleach.sanitizer import Cleaner from logging import Logger +from bleach.sanitizer import Cleaner from telebot import TeleBot from telebot.handler_backends import BaseMiddleware from telebot.types import Message @@ -164,8 +163,8 @@ class Notifier: def __format_message(self, item: FeedItem) -> str: return ( - # TODO: Return date when FeedItem starts to return formattable datetime object - f"{item.title}\n\n" + f"{item.title}\n" + f"{item.date.strftime('%m.%d.%Y %H:%M')}\n\n" f"{self.__sanitize_html(item.description)}" )