Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import requests
- import bs4
- import time
- reddit = praw.Reddit(client_id = '*********',
- client_secret = '*******************',
- username = 'IsLinkDownBot',
- password = '********',
- user_agent = 'IsLinkDown v1.0')
- def is_link_down(link):
- """
- Checks downforeveryoneorjustme.com to find out if the link is down or not.
- If an error occurs, waits for 30 minutes and tries again.
- """
- try:
- link = link.lower()
- url = "http://www.downforeveryoneorjustme.com/{}".format(link)
- response = requests.get(url)
- soup = bs4.BeautifulSoup(response.text, 'html.parser')
- for p_tag in soup.find_all('p'):
- result = str(p_tag.contents[0]).strip()
- if result == "It's just you.":
- result += link + " is up for everybody else."
- elif result == "It's not just you!":
- result += link + " is down for everybody else."
- break
- return result
- except:
- time.sleep(1800)
- is_link_down(link)
- while True:
- """
- Checks every 30 minutes for new mentions of /u/IsLinkDownBot by any Redditor.
- If it has been mentioned, replies with the message.
- """
- for mention in reddit.inbox.mentions():
- with open("mentions_replied_to.txt", "r") as f:
- mentions_replied_to = f.read()
- mentions_replied_to = mentions_replied_to.split("\n")
- mentions_replied_to = list(filter(None, mentions_replied_to))
- if mention not in mentions_replied_to:
- #mention body = '/u/IsLinkDownBot google.com'
- link = str(mention.body).replace('/u/IsLinkDownBot','') #' google.com'
- link = link.strip() #'google.com'
- message = is_link_down(link)
- mention.reply(message)
- #Adding mention ID to the list.
- mentions_replied_to.append(mention)
- with open("mentions_replied_to.txt", "w") as f:
- for mentionid in mentions_replied_to:
- f.write(str(mentionid) + "\n")
- f.close()
- time.sleep(1800)
Add Comment
Please, Sign In to add comment