Export database

Signed-off-by: András Schmelczer <andras@schmelczer.dev>
This commit is contained in:
Andras Schmelczer 2022-03-20 09:20:03 +01:00
parent 365a8f3914
commit 1279724ee3
No known key found for this signature in database
GPG key ID: 39260B5B0614A13E
2 changed files with 6872 additions and 0 deletions

6842
fizika.json Normal file

File diff suppressed because it is too large Load diff

30
sql2json.py Normal file
View file

@ -0,0 +1,30 @@
import re
import json
regex = r"\((\d+), '(.*?)', '(.*?)', '(.*?)', '(.*?)', '(.*?)', '(.*?)', (\d), '(.+?)', '(.*?)'\)"
sql = open('db/fizika.sql')
lines = sql.readlines()
result = []
for line in lines:
match = re.match(regex, line)
if match:
id, source, description, a, b, c, d, correct, type, image = match.groups()
image = f'{image}.{"png" if int(id) > 435 else "JPG"}' if image != '' else None
result.append({
"id": int(id),
"source": source,
"description": description,
"a": a,
"b": b,
"c": c,
"d": d,
"correct": int(correct),
"type": type,
"image": image,
})
json.dump(result, open('fizika.json', 'w+'), indent=2)