summaryrefslogtreecommitdiffstats
path: root/ircbot/rssbot.py
diff options
context:
space:
mode:
authorlassulus <lassulus@googlemail.com>2014-01-09 18:35:14 +0100
committerlassulus <lassulus@googlemail.com>2014-01-09 18:35:14 +0100
commitf1491bbc2003de22d5436d8fea0ce6eb80db8dd3 (patch)
treebdeae374cfe7d6e8642a76f2c9903c135ebc30fc /ircbot/rssbot.py
parentd8764b3327cfe772965b3f4a947071159a1d6161 (diff)
ircbot: shortenurl function
Diffstat (limited to 'ircbot/rssbot.py')
-rwxr-xr-xircbot/rssbot.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/ircbot/rssbot.py b/ircbot/rssbot.py
index 225e6f13..45af1dc3 100755
--- a/ircbot/rssbot.py
+++ b/ircbot/rssbot.py
@@ -57,12 +57,25 @@ class RssBot(irc.bot.SingleServerIRCBot):
#try:
# self.send(entry.title + " " + entry.link + " com: " + entry.comments)
#except AttributeError:
- shorturl = subprocess.check_output(["curl", "-sS", "-F", "uri=" + entry.link, self.url_shortener]).decode()
- self.send(entry.title + " " + shorturl.strip('\n').strip('\r') + '#' + entry.link.partition('://')[2].partition('/')[0])
+ 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):
+ while True:
+ try:
+ shorturl = subprocess.check_output(["curl", "-sS", "-F", "uri=" + url, self.url_shortener]).decode().strip('\n').strip('\r') + '#' + url.partition('://')[2].partition('/')[0]
+ return shorturl
+ except:
+ 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 send(self, string):
if self.connection.connected:
for line in string.split('\n'):