Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ustc-zzzz/021bfde436a4e613e9630d444b28dfea to your computer and use it in GitHub Desktop.
Save ustc-zzzz/021bfde436a4e613e9630d444b28dfea to your computer and use it in GitHub Desktop.
listen_minecraft_insider.py
#!/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 = 'zzzz@mail.ustc.edu.cn'
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