""" @author: GideonSenku, modified by pysta @file: SurgeToJs.py @createTime: 2020-05-01 æ¬èæ¬ç¨ä½æ²çº¿åé 读,ç»åAPP:py3ä½¿ç¨ 1ãç»éè¦é 读çè´¦å·ä¸ãäºãä¸.....,ç论æ é 2ãSurgeæå è®°å½æ¾å°https://apiwz.midukanshu.com/user/readTimeBase/readTimeéæ©è¯¥è®°å½å¯¼åº,使ç¨pythonista3è¿è¡miduRead.py 3ãå¨Surge->èæ¬->æ°å¢, èæ¬å:èªå®ä¹ä¸è¦éå¤å°±å¥½, èæ¬ç±»åéæ©Cron, cron表达å¼: */1 * * * * èæ¬ä½ç½®->æ¬å° 4ãç¼è¾èæ¬:è´´è´´py3çç»æ """ import zipfile import json import appex import clipboard import console def get_request_data(path): with zipfile.ZipFile(path, 'r') as z: with z.open('model.json') as f: data = json.load(f) if 'request.dump' in z.namelist(): with z.open('request.dump') as f: body = str(f.read(), encoding='utf-8') data['requestBody'] = body return data path = appex.get_file_path() data = get_request_data(path) body = data.get('requestBody', '') url = data['URL'] method = data['method'].lower() headers = {k: v for k, v in [ i.split(': ', 1) for i in data['requestHeader'].split('\r\n')[1:] if i]} js = """ // èµèµ:é请ç `A1040276307` // 龿¥`http://html34.qukantoutiao.net/qpr2/bBmQ.html?pid=5eb14518` // åå¦å±±æ³ -> æç¹å¸ const cookieName = '米读é 读æ¶é¿' const signinfo = {} const senku = init() // å¼å¯debug模å¼,æ¯æ¬¡èæ¬æ§è¡ä¼æ¾ç¤ºéç¥,é»è®¤false const debug = false debug ? senku.setdata('true', 'debug') : senku.setdata('false', 'debug') """ js = js + f''' const urlVal = {json.dumps(url)} const bodyVal = {json.dumps(body)} const headerVal = {json.dumps(headers, indent=4)} const request = {{ url: urlVal, headers: headerVal, body: bodyVal }} ''' js = js + """ ; (sign = async () => { senku.log(`ð ${cookieName}`) await readTime() showmsg() senku.done() })().catch((e) => senku.log(`â ${cookieName} ç¾å°å¤±è´¥: ${e}`), senku.done()) // é 读æ¶é¿ function readTime() { return new Promise((resolve, reject) => { senku.post(request, (error, response, data) => { try { senku.log(`â ${cookieName} readTime - response: ${JSON.stringify(response)}`) signinfo.readTime = JSON.parse(data) resolve() } catch (e) { senku.msg(cookieName, `é 读æ¶é¿: 失败`, `说æ: ${e}`) senku.log(`â ${cookieName} readTime - ç¾å°å¤±è´¥: ${e}`) senku.log(`â ${cookieName} readTime - response: ${JSON.stringify(response)}`) resolve() } }) }) } function showmsg() { let subTitle = '' let detail = '' if (signinfo.readTime && signinfo.readTime.code == 0) { const coin = signinfo.readTime.data.coin const readTotalMinute = signinfo.readTime.data.readTotalMinute const total_coin = signinfo.readTime.data.total_coin coin == 0 ? detail += `` : detail += `ãé 读æ¶é¿ãè·å¾${coin}ð°` readTotalMinute ? detail += ` é 读æ¶é¿${readTotalMinute / 2}åé,该账æ·:${total_coin}ð°` : detail += `该账æ·:${total_coin}ð°` } else if (signinfo.readTime.code != 0) { detail += `ãé 读æ¶é¿ãé误代ç ${signinfo.readTime.code},é误信æ¯${signinfo.readTime.message}` senku.msg(cookieName, subTitle, detail) } else { detail += 'ãé 读æ¶é¿ã失败' senku.msg(cookieName, subTitle, detail) } if (senku.getdata('debug') == 'true' || detail && signinfo.readTime.data.readTotalMinute % 60 == 0) { senku.msg(cookieName, subTitle, detail) } else if (senku.getdata('debug') == 'true' || signinfo.readTime.data.readTotalMinute % 60 == 0) { senku.msg(cookieName, 'é è¯»ç»æ', 'æ¶é´æªå°') } } function init() { isSurge = () => { return undefined === this.$httpClient ? false : true } isQuanX = () => { return undefined === this.$task ? false : true } getdata = (key) => { if (isSurge()) return $persistentStore.read(key) if (isQuanX()) return $prefs.valueForKey(key) } setdata = (key, val) => { if (isSurge()) return $persistentStore.write(key, val) if (isQuanX()) return $prefs.setValueForKey(key, val) } msg = (title, subtitle, body) => { if (isSurge()) $notification.post(title, subtitle, body) if (isQuanX()) $notify(title, subtitle, body) } log = (message) => console.log(message) get = (url, cb) => { if (isSurge()) { $httpClient.get(url, cb) } if (isQuanX()) { url.method = 'GET' $task.fetch(url).then((resp) => cb(null, resp, resp.body)) } } post = (url, cb) => { if (isSurge()) { $httpClient.post(url, cb) } if (isQuanX()) { url.method = 'POST' $task.fetch(url).then((resp) => cb(null, resp, resp.body)) } } done = (value = {}) => { $done(value) } return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done } } """ print(js) clipboard.set(js) console.hud_alert('Copyed!')