Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import narwal
- import feedparser
- import time
- import calendar
- class vari():
- r = narwal.Reddit(user_agent='RSS Bot')
- time.sleep(3)
- #rssbot
- bot_usr = ['User1', 'User2', 'User3', 'User4']
- bot_pss = ['Pass1', 'Pass2', 'Pass3', 'Pass4']
- bot_rss = ['http://feed1.com/rss', 'http://feed2.com/rss', 'http://feed3.com/rss', 'http://feed4.com/rss']
- bot_sr = ['Subreddit1', 'Subreddit2', 'Subreddit3', 'Subreddit4']
- last_check = time.gmtime()
- #Enum Broadcast Type
- class BCType:
- Info=1
- Alert=2
- Login=3
- Post=4
- Sleep=5
- #Broadcast
- def Broadcast(BCType, message):
- if (BCType == 1):
- print '[INFO] ' + message
- elif (BCType == 2):
- print '[ALERT] ' + message
- elif (BCType == 3):
- print '[LOGIN] ' + message
- elif (BCType == 4):
- print '[POST] ' + message
- elif (BCType == 5):
- print '[SLEEP] ' + message
- #Login
- def Login(Username, Password):
- vari.r.login(Username, Password)
- time.sleep(3)
- if (vari.r.logged_in == False):
- Broadcast(BCType.Login, 'Login fail as ' + Username)
- time.sleep(90)
- Login(Username, Password)
- Broadcast(BCType.Login, 'Login as ' + Username)
- #RSSCheck
- def RSSPost():
- curr_bot = 0
- while (curr_bot < len(vari.bot_usr)):
- Broadcast(BCType.Info, 'Checking bot ' + vari.bot_usr[curr_bot])
- to_post = []
- feed = feedparser.parse(vari.bot_rss[curr_bot])
- for e in feed.entries:
- try:
- if (calendar.timegm(e.published_parsed) > calendar.timegm(vari.last_check)):
- to_post.append(e)
- except:
- pass
- if (len(to_post) > 0):
- Login(vari.bot_usr[curr_bot], vari.bot_pss[curr_bot])
- for e in to_post:
- try:
- r.submit_link(vari.bot_sr[curr_bot], e.title, e.link)
- Broadcast(BCType.Post, vari.bot_usr[curr_bot] + ' Posted ' + e.title)
- time.sleep(60)
- except:
- pass
- curr_bot += 1
- vari.last_check = time.gmtime()
- #Main#
- while (True):
- #RSSbot
- try:
- RSSPost()
- except:
- Broadcast(BCType.Alert, 'RSSbot exception')
- vari.last_check = time.gmtime()
- #Sleep
- Broadcast(BCType.Sleep, 'Sleeping for 30min...')
- time.sleep(1800)
- #
- #Done
- Broadcast(BCType.Alert, 'Program Done...')
Advertisement
Advertisement