daily pastebin goal
83%
SHARE
TWEET

Untitled

a guest Jun 8th, 2017 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Author: Ben Wright
  2. # Date: 5th August 2010
  3. # License: MIT
  4. # Description: A simple rss to twitter rss parser.
  5.  
  6. import feedparser
  7. import twitter
  8. import sys
  9. import time
  10.  
  11. class RSSParser:
  12.   def __init__(self, feed):
  13.     self.feed = feed
  14.     data = feedparser.parse(self.feed)
  15.     self.posts = [(e.title, e.link) for e in data.entries]
  16.     self.update()
  17.   def posts(self):
  18.     return self.posts
  19.   def new_posts(self):
  20.     return self.new_posts
  21.   def update(self):
  22.     print '[Parsing] ' + self.feed
  23.     data = feedparser.parse(self.feed)
  24.     links = [(e.title, e.link) for e in data.entries]
  25.     self.new_posts = list(set(self.posts)-set(links))+list(set(links)-set(self.posts))
  26.     self.posts = links
  27.     print '[Parsing Done]'
  28.  
  29.  
  30. class TwitterBot:
  31.   def __init__(self, username, password):
  32.     self.api = twitter.Api(username=username, password=password)
  33.   def post(self, message):
  34.     print '[Tweeting] ' + message
  35.     self.api.PostUpdate(message)
  36.     print '[Sleeping] 2 Minutes'
  37.     time.sleep(2*60)
  38.        
  39. def main():
  40.   pool = [RSSParser(line[:-1]) for line in open('pool.txt', 'r')]
  41.   twitter_bot = TwitterBot('username', 'password')
  42.   while True:
  43.     for feed in pool:
  44.       feed.update()
  45.       for post in feed.new_posts():
  46.         twitter_bot.post(post[0] + ' ' + post[1])
  47.     print "[Sleeping] 15 Minutes"
  48.     time.sleep(15*60)
  49.  
  50. if __name__ == "__main__":
  51.   main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top