diff options
author | lassulus <lassulus@googlemail.com> | 2014-01-09 18:35:14 +0100 |
---|---|---|
committer | lassulus <lassulus@googlemail.com> | 2014-01-09 18:35:14 +0100 |
commit | f1491bbc2003de22d5436d8fea0ce6eb80db8dd3 (patch) | |
tree | bdeae374cfe7d6e8642a76f2c9903c135ebc30fc /ircbot | |
parent | d8764b3327cfe772965b3f4a947071159a1d6161 (diff) |
ircbot: shortenurl function
Diffstat (limited to 'ircbot')
-rwxr-xr-x | ircbot/contoller.py | 1 | ||||
-rwxr-xr-x | ircbot/rssbot.py | 17 |
2 files changed, 15 insertions, 3 deletions
diff --git a/ircbot/contoller.py b/ircbot/contoller.py index 1d9347c3..bf4dd578 100755 --- a/ircbot/contoller.py +++ b/ircbot/contoller.py @@ -116,7 +116,6 @@ class commands(): return 'bot not found' - feedfile = 'new_feeds' url_shortener = 'http://wall' init_channels = ['#news'] 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'): |