Created
May 26, 2017 14:25
-
-
Save ustc-zzzz/021bfde436a4e613e9630d444b28dfea to your computer and use it in GitHub Desktop.
listen_minecraft_insider.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import requests | |
import smtplib | |
from email.mime.text import MIMEText | |
from email.header import Header | |
def send_email(url): | |
print('Something happened. ') | |
mail_addr = '[email protected]' | |
mail_password = '############' | |
msg = MIMEText('https://minecraft.net' + url, 'plain', 'utf-8') | |
msg['Subject'] = Header('Update Minecraft Insider as quickly as possible', 'utf-8') | |
msg['From'] = '"zzzz\'s server" <%s>' % mail_addr | |
msg['To'] = 'zzzz <%s>' % mail_addr | |
server = smtplib.SMTP_SSL('mail.ustc.edu.cn', 465) | |
server.login(mail_addr, mail_password) | |
server.sendmail(mail_addr, [mail_addr], msg.as_string()) | |
server.quit() | |
def main(): | |
url = 'https://minecraft.net/zh-hans/api/tiles/category/Insider' | |
req = requests.get(url) | |
json = req.json()['result'] | |
old_urls = [''] | |
try: | |
with open('article_urls.txt', 'r') as file: | |
old_urls = file.readlines() | |
except IOError: | |
pass | |
with open('article_urls.txt', 'w') as file: | |
for i in json: | |
file.write(i['url'] + '\n') | |
if old_urls[0] != json[0]['url'] + '\n': | |
send_email(json[0]['url']) | |
else: | |
print('Nothing happened. ') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment