Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import time
import re
import feedparser
import datetime
import dateutil.parser
from colour import Colours
from db import FeedDB
from config import Config
Expand All @@ -22,6 +24,7 @@ def __init__(self, config, db, on_connect_cb):
self.date = self.__config.date
self.feedname = self.__config.feedname
self.shorturls = self.__config.shorturls
self.dateformat = self.__config.dateformat

def on_welcome(self, connection, event):
"""Join the correct channel upon connecting"""
Expand Down Expand Up @@ -179,12 +182,20 @@ def __fetch_feed(self, feed_info):
else:
newsurl = newsitem.link

# Try to get the published date. Otherwise set it to 'no date'
# Try to get the published or updated date. Otherwise set it to 'no date'
try:
newsdate = newsitem.published
# Get date and parse it
newsdate = dateutil.parser.parse(newsitem.published)
# Format date based on 'dateformat' in config.py
newsdate = newsdate.strftime(self.__config.dateformat)

except Exception as e:
try:
newsdate = newsitem.updated
# Get date and parse it
newsdate = dateutil.parser.parse(newsitem.updated)
# Format date based on 'dateformat' in config.py
newsdate = newsdate.strftime(self.__config.dateformat)

except Exception as e:
newsdate = "no date"

Expand Down
1 change: 1 addition & 0 deletions config.py.sample
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ class Config(object):
self.date = '8'
self.feedname = '2'
self.shorturls = False
self.dateformat = '%Y-%m-%d %H:%M:%S %z'
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jaraco.logging==1.3.1
jaraco.stream==1.1
jaraco.text==1.6.3
more-itertools==2.2
python-dateutil==2.5.3
pytz==2016.4
six==1.10.0
git+https://github.com/palantir/sqlite3worker#egg=sqlite3worker
Expand Down