Fix date representation in FeedItem #38

Merged
Miroslavsckaya merged 5 commits from fix_date_in_FeedItem into master 2022-07-10 14:40:20 +00:00
3 changed files with 13 additions and 6 deletions

View file

@ -37,3 +37,10 @@ export TELEGRAM_TOKEN=xxx
export DATABASE_PATH=./database.db
python bot.py
```
## Running the update
```shell
export TELEGRAM_TOKEN=xxx

It's better to also show which env variables are needed as it's showed above.

It's better to also show which env variables are needed as it's showed above.
export DATABASE_PATH=./database.db
python update.py
```

5
rss.py
View file

@ -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

View file

@ -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"<strong><a href=\"{item.url}\">{item.title}</a></strong>\n\n"
f"<strong><a href=\"{item.url}\">{item.title}</a></strong>\n"
f"{item.date.strftime('%m.%d.%Y %H:%M')}\n\n"
f"{self.__sanitize_html(item.description)}"
)