Created
July 11, 2015 13:10
-
-
Save aoli-al/19c84ac62a13d3775c5c to your computer and use it in GitHub Desktop.
score bomb!
This file contains hidden or 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
import requests | |
import os.path | |
import sys | |
import json | |
CONFIG_FILE = "./score_bomb.json" | |
GRADE_FILE = "./grade.json" | |
if not os.path.isfile(CONFIG_FILE): | |
data = {} | |
data['student_id'] = input("Please input your student id:") | |
data['password'] = input("Please input your password:") | |
data['token'] = input("Please input your Pushbullet token:") | |
with open(CONFIG_FILE, 'w') as config: | |
json.dump(data, config) | |
config.close() | |
config_data = {} | |
try: | |
with open(CONFIG_FILE, 'r') as config: | |
config_data = json.load(config) | |
except: | |
print("Failed load config file") | |
sys.exit() | |
para = {} | |
para['stuid'] = config_data['student_id'] | |
para['pwd'] = config_data['password'] | |
score_url = "https://m.zjuqsc.com/api/v2/jw/chengji" | |
r = requests.get(score_url, params=para) | |
res = json.loads(r.text) | |
if not os.path.isfile(GRADE_FILE): | |
with open(GRADE_FILE, "w") as f: | |
json.dump(res, f) | |
f.close() | |
notification_data = {} | |
notification_data['title'] = '测试推送' | |
notification_data['body'] = '' | |
notification_data['type'] = 'note' | |
notification_headers = { | |
'Authorization': 'Bearer ' + config_data['token'] | |
} | |
requests.post("https://api.pushbullet.com/v2/pushes", data=notification_data, headers=notification_headers) | |
with open(GRADE_FILE, "r") as f: | |
try: | |
grade_data = json.load(f) | |
print(grade_data['junji_array']) | |
f.close() | |
except ValueError: | |
os.remove(GRADE_FILE) | |
sys.exit() | |
if grade_data['junji_array'][0]['总学分'] != res['junji_array'][0]['总学分']: | |
with open(GRADE_FILE, "w") as f: | |
json.dump(res, f) | |
f.close() | |
notification_data = {} | |
notification_data['title'] = '您有一门新的成绩,请查收' | |
notification_data['body'] = '' | |
notification_data['type'] = 'note' | |
notification_headers = { | |
'Authorization': 'Bearer ' + config_data['token'] | |
} | |
requests.post("https://api.pushbullet.com/v2/pushes", data=notification_data, headers=notification_headers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment