Advertisement
Guest User

Untitled

a guest
Oct 24th, 2012
896
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.44 KB | None | 0 0
  1. import narwal
  2. import feedparser
  3. import time
  4. import calendar
  5. class vari():
  6.     r = narwal.Reddit(user_agent='RSS Bot')
  7.     time.sleep(3)
  8.     #rssbot
  9.     bot_usr = ['User1', 'User2', 'User3', 'User4']
  10.     bot_pss = ['Pass1', 'Pass2', 'Pass3', 'Pass4']
  11.     bot_rss = ['http://feed1.com/rss', 'http://feed2.com/rss', 'http://feed3.com/rss', 'http://feed4.com/rss']
  12.     bot_sr = ['Subreddit1', 'Subreddit2', 'Subreddit3', 'Subreddit4']
  13.     last_check = time.gmtime()
  14. #Enum Broadcast Type
  15. class BCType:
  16.     Info=1
  17.     Alert=2
  18.     Login=3
  19.     Post=4
  20.     Sleep=5
  21. #Broadcast
  22. def Broadcast(BCType, message):
  23.     if (BCType == 1):
  24.         print '[INFO] ' + message
  25.     elif (BCType == 2):
  26.          print '[ALERT] ' + message
  27.     elif (BCType == 3):
  28.          print '[LOGIN] ' + message
  29.     elif (BCType == 4):
  30.          print '[POST] ' + message
  31.     elif (BCType == 5):
  32.          print '[SLEEP] ' + message
  33. #Login
  34. def Login(Username, Password):
  35.     vari.r.login(Username, Password)
  36.     time.sleep(3)
  37.     if (vari.r.logged_in == False):
  38.         Broadcast(BCType.Login, 'Login fail as ' + Username)
  39.         time.sleep(90)
  40.         Login(Username, Password)
  41.     Broadcast(BCType.Login, 'Login as ' + Username)
  42. #RSSCheck
  43. def RSSPost():
  44.     curr_bot = 0
  45.     while (curr_bot < len(vari.bot_usr)):
  46.         Broadcast(BCType.Info, 'Checking bot ' + vari.bot_usr[curr_bot])
  47.        
  48.         to_post = []
  49.        
  50.         feed = feedparser.parse(vari.bot_rss[curr_bot])
  51.         for e in feed.entries:
  52.             try:
  53.                 if (calendar.timegm(e.published_parsed) > calendar.timegm(vari.last_check)):
  54.                     to_post.append(e)
  55.             except:
  56.                 pass
  57.         if (len(to_post) > 0):
  58.             Login(vari.bot_usr[curr_bot], vari.bot_pss[curr_bot])
  59.             for e in to_post:
  60.                 try:
  61.                     r.submit_link(vari.bot_sr[curr_bot], e.title, e.link)
  62.                     Broadcast(BCType.Post, vari.bot_usr[curr_bot] + ' Posted ' + e.title)
  63.                     time.sleep(60)
  64.                 except:
  65.                     pass
  66.         curr_bot += 1
  67.     vari.last_check = time.gmtime()
  68. #Main#
  69. while (True):
  70.     #RSSbot
  71.     try:
  72.         RSSPost()
  73.     except:
  74.         Broadcast(BCType.Alert, 'RSSbot exception')
  75.         vari.last_check = time.gmtime()
  76.     #Sleep
  77.     Broadcast(BCType.Sleep, 'Sleeping for 30min...')
  78.     time.sleep(1800)
  79.     #
  80. #Done
  81. Broadcast(BCType.Alert, 'Program Done...')
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement