Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Sean Nendoroid Checker
- A dumb web page checker - checks if a value on a webpage has changed.
- Built to monitor Sean Shin's figure collection - primarily so he can be judged
- Author: Samuel Pell
- """
- import requests as req
- import sys
- import smtplib
- from email.mime.text import MIMEText
- USER = ""
- URL = "https://myfigurecollection.net/profile/sparky"
- PASSWORD = ""
- RECIPIENT = ""
- SEARCH_TERM = "owned ({})"
- FILENAME = 'prev_nendroid_count.txt'
- def get_page(url):
- try:
- response = req.request('GET', url)
- return response.content
- except req.exceptions.ConnectionError:
- sys.exit("Error")
- def send_email(current, prev):
- msg = MIMEText("Sean now has {} nendoroids, this is up from {} previously.\n- With Love, your ever vigilant,\n\nBot-chan".format(current, prev))
- msg['From'] = USER
- msg['Subject'] = "!!Nendoroid Alert!!"
- msg['To'] = RECIPIENT
- s = smtplib.SMTP(host='smtp.gmail.com', port=587)
- s.starttls()
- s.login(USER, PASSWORD)
- s.send_message(msg)
- s.quit()
- def main():
- #Get the previous recorded number
- file = open(FILENAME, 'r')
- prev = int(file.readline())
- file.close()
- #Get the web page to check
- web_page = get_page(URL)
- web_page = str(web_page).lower()
- isFound = web_page.find(SEARCH_TERM.format(prev));
- #If you cant find your search string, that indicates
- #Sean has got more nendroids.
- if isFound == -1:
- #Find out how many more...
- start = web_page.find("owned (")
- fin = web_page.find(")", start)
- new = int(web_page[start + len("owned ("):fin])
- #Write the new figure figure
- file = open(FILENAME, 'w')
- file.write(str(new))
- file.close()
- #Alert Sam
- print("The number owned has changed, sending email...")
- send_email(new, prev)
- print("email sent :)")
- else:
- print("Sean hasn't got any more nendroids.")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement