forked from cr4n5/XiaoYuanKouSuan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
84 lines (73 loc) · 2.79 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from mitmproxy import http
import json
from mitmproxy.tools.main import mitmdump
import sys
import threading
import os
import subprocess
import number_command
import time
import tkinter as tk
from tkinter import messagebox
import argparse
def request(flow: http.HTTPFlow) -> None:
pass
def response(flow: http.HTTPFlow) -> None:
print(f"Response: {flow.response.status_code} {flow.request.url}")
if "https://xyks.yuanfudao.com/leo-math/android/exams?" in flow.request.url:
answer = json.loads(flow.response.text)
print(json.dumps(answer, indent=4))
select_answer(answer, "练习")
elif "https://xyks.yuanfudao.com/leo-game-pk/android/math/pk/match?" in flow.request.url:
answer = json.loads(flow.response.text)
print(json.dumps(answer, indent=4))
select_answer(answer, "pk")
def answer_write(answer):
for i in range(len(answer)):
number_command.swipe_screen(answer[i])
time.sleep(0.3)
def select_answer(answer, type):
f = open("answer.txt", "w")
select_answer = []
if type == "练习":
for question in answer["questions"]:
answers = question["answers"]
for i in range(len(answers)):
if "." in answers[i]:
correct_answer = answers[i]
break
if i == len(answers) - 1:
correct_answer = answers[0]
select_answer.append(correct_answer)
print(correct_answer, end=" ")
f.write(str(correct_answer) + " ")
elif type == "pk":
for question in answer["examVO"]["questions"]:
answers = question["answers"]
for i in range(len(answers)):
if "." in answers[i]:
correct_answer = answers[i]
break
if i == len(answers) - 1:
correct_answer = answers[0]
select_answer.append(correct_answer)
print(correct_answer, end=" ")
f.write(str(correct_answer) + " ")
f.close()
threading.Thread(target=gui_answer, args=(select_answer,)).start()
def gui_answer(answer):
root = tk.Tk()
root.title("继续执行")
def on_button_click():
root.destroy()
answer_write(answer)
button = tk.Button(root, text="点击继续", command=on_button_click)
button.pack(pady=20)
root.mainloop()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Mitmproxy script")
parser.add_argument("-P", "--port", type=int, default=8080, help="Port to listen on")
parser.add_argument("-H", "--host", type=str, default="0.0.0.0", help="Host to listen on")
args = parser.parse_args()
sys.argv = ["mitmdump", "-s", __file__, "--listen-host", args.host, "--listen-port", str(args.port)]
mitmdump()