forked from Petrosz007/jog_quiz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.py
45 lines (35 loc) · 1.09 KB
/
convert.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
import requests
import re
import json
import codecs
# r = requests.get("https://pastebin.com/raw/kGcxffi3")
# questions = r.text
# matches = re.finditer(r"([0-9]{1,})\.\r\n(.*)\r\na\)\s(.*)\r\nb\)\s(.*)\r\nc\)\s(.*)\r\nd\)\s(.*)\r", questions)
# out = {}
# for m in matches:
# question = {
# "question": m.group(2),
# "a": m.group(3),
# "b": m.group(4),
# "c": m.group(5),
# "d": m.group(6),
# "answer": 'x'
# }
# out[m.group(1)] = question
# with open('Jog_tesztkerdesek.txt', 'r') as file:
# questions = file.readlines()
# print(question)
out = {}
r = requests.get("https://pastebin.com/raw/Y7KKHXQK")
out = json.loads(r.text)
# print(questions)
r = requests.get("https://pastebin.com/raw/4JQ3AELx")
answers = r.text
matches = re.finditer(r"([0-9]{1,})\s(\w)", answers)
for m in matches:
if m.group(1) in out:
out[m.group(1)]["answer"] = m.group(2).lower()
print(len(out.items()))
file = codecs.open("data.json", "w", "utf-8")
file.write(json.dumps(out, ensure_ascii=False))
file.close()