Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from lxml import html
- import requests
- import praw
- import time
- def RSIAnnounce():
- # Pulling announcement from RSI webpage.
- #######################################
- print "Pulling data from RSI..."
- page = requests.get('https://www.robertsspaceindustries.com/')
- tree = html.fromstring(page.text)
- # Ensuring that if there is no annoucement the program reacts accordingly.
- try:
- caption = tree.xpath('//*[@id="global-notification"]/a/div[1]/div')[0].text_content() #HTML location of data
- announce_check = True
- except IndexError:
- print "No announcement!"
- announce_check = False
- caption = "No announcement"
- try:
- link = tree.xpath('//*[@id="global-notification"]/a/@href')
- except IndexError:
- print "No link!"
- link = "https://www.robertsspaceindustries.com"
- string_link = ''.join(link)
- ########################################
- # Preping and downloading data to reddit wiki.
- ########################################
- announcement = "[**From CIG**: %s](%s#announcebot) \n \n [](http://www.bot.com)" % (caption, string_link)
- #logging into reddit and downloading sidebar.
- r = praw.Reddit(user_agent = "Sidebar updater for /r/starcitzen by /u/Jumbify")
- r.login(username="USERNAME HERE", password = "PASSWORD HERE", disable_warning = True)
- sub = "starcitizen"
- settings = r.get_settings(sub)
- sidebar_contents = settings['description']
- sidebar_split = sidebar_contents.split("[](http://www.bot.com)", 1)
- del sidebar_split[0]
- sidebar_contents = ''.join(sidebar_split)
- if announce_check == True:
- final_string = announcement + sidebar_contents
- else:
- no_annoucement = "[](https://www. NO ANNOUNCEMENT CURRENTLY) \n \n [](http://www.bot.com)"
- final_string = no_annoucement + sidebar_contents
- r.update_settings(r.get_subreddit(sub), description=final_string)
- ########################################
- print "RSIAnnounce complete..."
- if __name__ == "__main__":
- RSIAnnounce()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement