summaryrefslogtreecommitdiffstats
path: root/ircbot
diff options
context:
space:
mode:
authorlassulus <lassulus@googlemail.com>2014-01-09 20:27:00 +0100
committerlassulus <lassulus@googlemail.com>2014-01-09 20:27:00 +0100
commit35406d4fc7bf83c954b225747ac6c13a6aad2994 (patch)
tree6bd3a5e1e97c61ab1ecd1f670eb27bbadf0a90e7 /ircbot
parent1b3abcd0e37f2c3730ab05062f6b0275429a3522 (diff)
ircbot: better looping
Diffstat (limited to 'ircbot')
-rwxr-xr-xircbot/rssbot.py52
1 files changed, 28 insertions, 24 deletions
diff --git a/ircbot/rssbot.py b/ircbot/rssbot.py
index 45af1dc3..79276a3a 100755
--- a/ircbot/rssbot.py
+++ b/ircbot/rssbot.py
@@ -41,26 +41,28 @@ class RssBot(irc.bot.SingleServerIRCBot):
self.loop = False
def updateloop(self):
- try:
- self.feed = feedparser.parse(self.url)
- except:
- print(self.name + ': rss timeout occured')
- for entry in self.feed.entries:
- self.oldnews.append(entry.link)
+ while True:
+ try:
+ self.feed = feedparser.parse(self.url)
+ for entry in self.feed.entries:
+ self.oldnews.append(entry.link)
+ break
+ except:
+ print(self.name + ': rss timeout occured')
while self.loop:
try:
self.feed = feedparser.parse(self.url)
+ for entry in self.feed.entries:
+ if not entry.link in self.oldnews:
+ #try:
+ # self.send(entry.title + " " + entry.link + " com: " + entry.comments)
+ #except AttributeError:
+ shorturl = self.shortenurl(entry.link)
+ self.sendall(entry.title + ' ' + shorturl)
+ self.oldnews.append(entry.link)
+ self.lastnew = datetime.now()
except:
print(self.name + ': rss timeout occured')
- for entry in self.feed.entries:
- if not entry.link in self.oldnews:
- #try:
- # self.send(entry.title + " " + entry.link + " com: " + entry.comments)
- #except AttributeError:
- shorturl = self.shortenurl(entry.link)
- self.send(entry.title + ' ' + shorturl)
- self.oldnews.append(entry.link)
- self.lastnew = datetime.now()
sleep(self.to)
def shortenurl(self, url):
@@ -72,25 +74,27 @@ class RssBot(irc.bot.SingleServerIRCBot):
print('url shortener error')
sleep(1)
- def last(self, num):
- for feed in reversed([x for x in reversed(self.feed.entries)][:num]):
- self.send(feed.title + ' ' + self.shortenurl(feed.link))
+ def last(self, target, num):
+ for feed in [x for x in self.feed.entries][:num]:
+ self.send(target, feed.title + ' ' + self.shortenurl(feed.link))
+
+ def sendall(self, string):
+ for chan in self.channels:
+ self.send(chan, string)
- def send(self, string):
+ def send(self, target, string):
if self.connection.connected:
for line in string.split('\n'):
if len(line) < 450:
- for chan in self.channels:
- self.connection.privmsg(chan, line)
+ self.connection.privmsg(target, line)
+ sleep(1)
else:
space = 0
for x in range(math.ceil(len(line)/400)):
oldspace = space
space = line.find(" ", (x+1)*400, (x+1)*400+50)
- for chan in self.channels:
- self.connection.privmsg(chan, line[oldspace:space])
+ self.connection.privmsg(target, line[oldspace:space])
sleep(1)
- sleep(1)
else:
self.connection.reconnect()
sleep(1)