diff --git a/bot.py b/bot.py index c7c52c3..f98e71b 100644 --- a/bot.py +++ b/bot.py @@ -66,7 +66,7 @@ def __handle_msg(self, msg): # Print last 25 news. elif msg == "!last": answer = "" - for entry in self.__db.get_latest_news()[::-1]: + for entry in self.__db.get_latest_news(self.__config.feedlimit)[::-1]: answer += "#" + Colours(self.num_col,str(entry[0])).get() + ": " + entry[1] + ", " + Colours('',str(entry[2])).get() + ", " + Colours(self.date,entry[3]).get() + "\n" # Print last 25 news for a specific feed @@ -76,7 +76,7 @@ def __handle_msg(self, msg): feedid = int(msg.replace("!lastfeed","").strip()) except: return Colours('1',"Wrong command: ").get() + msg + ", use: !lastfeed " - for entry in self.__db.get_news_from_feed(feedid)[::-1]: + for entry in self.__db.get_news_from_feed(feedid, self.__config.feedlimit)[::-1]: answer += "#" + Colours(self.num_col,str(entry[0])).get() + ": " + entry[1] + ", " + Colours('',str(entry[2])).get() + ", " + Colours(self.date,str(entry[3])).get() + "\n" # Else tell the user how to use the bot @@ -150,8 +150,8 @@ def __help_msg(self): class Bot(object): def __init__(self): - self.__db = FeedDB() self.__config = Config() + self.__db = FeedDB(self.__config) self.__irc = IRCBot(self.__config, self.__db, self.on_started) self.__threads = [] self.__connected = False @@ -211,7 +211,6 @@ def __fetch_feed(self, feed_info): is_new = self.__db.insert_news(feed_info[0], newstitle, newsitem.link, newsdate) if is_new: self.__irc.post_news(feed_info[1], newstitle, newsurl, newsdate) - print "Updated: " + feed_info[1] except Exception as e: print e diff --git a/config.py.sample b/config.py.sample index 99da000..fb023b1 100644 --- a/config.py.sample +++ b/config.py.sample @@ -20,3 +20,4 @@ class Config(object): self.feedname = '2' self.shorturls = False self.dateformat = '%Y-%m-%d %H:%M:%S %z' + self.feedlimit = 10 diff --git a/db.py b/db.py index 6e4aa8b..2b817cf 100644 --- a/db.py +++ b/db.py @@ -5,9 +5,10 @@ import os class FeedDB(object): - def __init__(self): + def __init__(self, config): self.__db_path = "./feeds.db" self.__db_worker = None + self.__config = config self.__initiate_db() def __initiate_db(self):