Last active
August 18, 2020 14:54
-
-
Save mosaicer/f664e02f1fd57bee04a8fbb3196ba20c to your computer and use it in GitHub Desktop.
「夏のきらら検定 in アルティメットクイズ」の自動正答送信スクリプト
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 js2py | |
| import requests | |
| def get_commom_url(): | |
| # https://c-static.asfes.jp/include_121/front2/js/common.js | |
| return js2py.eval_js(""" | |
| var COMMON_URL = { | |
| urlAddCacheMeasure : function (url) { | |
| var parse = this.urlParse(url); | |
| var time = this.getUnixTime(); | |
| parse["d"] = time; | |
| return this.getUrl(url) + "?" + this.urlStringify(parse); | |
| }, | |
| getUnixTime : function () { | |
| var date = new Date(); | |
| return date.getTime(); | |
| }, | |
| getUrl : function (url) { | |
| url = url || location.href; | |
| if (url.indexOf("?") == -1) { | |
| return url; | |
| } | |
| return url.substring(0, url.indexOf("?")); | |
| }, | |
| urlParse : function (url, sep, eq, isDecode) { | |
| url = url || location.href; | |
| sep = sep || '&'; | |
| eq = eq || '='; | |
| if (url.indexOf("?") == -1) { | |
| return {}; | |
| } else { | |
| url = url.substring(url.indexOf("?") + 1, url.length) | |
| } | |
| var decode = (isDecode) ? decodeURIComponent : function(a) { return a; }; | |
| return url.split(sep).reduce(function(obj, v) { | |
| var pair = v.split(eq); | |
| obj[pair[0]] = decode(pair[1]); | |
| return obj; | |
| }, {}); | |
| }, | |
| urlStringify : function (value, sep, eq, isEncode) { | |
| sep = sep || '&'; | |
| eq = eq || '='; | |
| var encode = (isEncode) ? encodeURIComponent : function(a) { return a; }; | |
| return Object.keys(value).map(function(key) { | |
| return key + eq + encode(value[key]); | |
| }).join(sep); | |
| }, | |
| stringify : function (data) { | |
| return JSON.stringify(data); | |
| } | |
| }; | |
| """) | |
| # reference: | |
| # - https://c-static.asfes.jp/include_121/front2/js/app.quz.js | |
| # - QUZ_CONFIG from https://www.asfes.jp/game/kirarafantasia/quz-1555-q1q/quizform/ | |
| def fetch_quiz_data(): | |
| url = common_url.urlAddCacheMeasure('https://www.asfes.jp/game/kirarafantasia/quz-1555-q1q/quizform/q/') | |
| response = requests.get(url) | |
| return response.json() | |
| def fetch_answer_datas(payload_length, quz_id): | |
| answers = [] | |
| for i in range(payload_length): | |
| answer_data = fetch_answer_data(quz_id, i + 1) | |
| answers.append(int(answer_data['answer'])) | |
| return answers | |
| def fetch_answer_data(quz_id, number): | |
| url = common_url.urlAddCacheMeasure('https://www.asfes.jp/game/kirarafantasia/quz-1555-q1q/quizform/a/') | |
| response = requests.post(url, {'quz_id': quz_id, 'number': number}) | |
| return response.json() | |
| def send_answers(quz_id, answers): | |
| url = common_url.urlAddCacheMeasure('https://www.asfes.jp/game/kirarafantasia/quz-1555-q1q/quiz/') | |
| response = requests.post(url, {'quz_id':quz_id, 'ans':common_url.stringify(answers)}) | |
| return response | |
| if __name__ == '__main__': | |
| common_url = get_commom_url() | |
| quiz_data = fetch_quiz_data() | |
| quz_id = quiz_data['quz_id'] | |
| print('quz_id: {}'.format(quz_id)) | |
| answers = fetch_answer_datas(len(quiz_data['payload']), quz_id) | |
| print('answers: {}'.format(answers)) | |
| response = send_answers(quz_id, answers) | |
| print('status_code: {}, url: {}'.format(response.status_code, response.url)) | |
| # print(response.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment