This repository was archived by the owner on Aug 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreset_database.py
More file actions
143 lines (125 loc) · 3.44 KB
/
reset_database.py
File metadata and controls
143 lines (125 loc) · 3.44 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import requests
import json
from application import db
from application.settingssecrets import JUDGE0_AUTHN_TOKEN, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_BUCKET_NAME
from application.models.general import *
import boto3
try:
db.session.commit()
except Exception as e:
db.session.rollback()
status = [
{
"id": 1,
"description": "In Queue"
},
{
"id": 2,
"description": "Processing"
},
{
"id": 3,
"description": "Accepted"
},
{
"id": 4,
"description": "Wrong Answer"
},
{
"id": 5,
"description": "Time Limit Exceeded"
},
{
"id": 6,
"description": "Compilation Error"
},
{
"id": 7,
"description": "Runtime Error (SIGSEGV)"
},
{
"id": 8,
"description": "Runtime Error (SIGXFSZ)"
},
{
"id": 9,
"description": "Runtime Error (SIGFPE)"
},
{
"id": 10,
"description": "Runtime Error (SIGABRT)"
},
{
"id": 11,
"description": "Runtime Error (NZEC)"
},
{
"id": 12,
"description": "Runtime Error (Other)"
},
{
"id": 13,
"description": "Internal Error"
},
{
"id": 14,
"description": "Exec Format Error"
}
]
s3 = boto3.resource('s3', aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
bucket = s3.Bucket(AWS_BUCKET_NAME)
classes = Class_.query.all()
for class_ in classes:
for problem in class_.problems:
for input_file in problem.input_files:
s3.Object(AWS_BUCKET_NAME, input_file.file_path).delete()
for output_file in problem.output_files:
s3.Object(AWS_BUCKET_NAME, output_file.file_path).delete()
for submission in problem.submissions:
s3.Object(AWS_BUCKET_NAME, submission.file_path).delete()
db.session.remove()
db.drop_all()
db.create_all()
base_url = 'https://judge0-fhwnc7.vishnus.me'
languages = requests.get(f'{base_url}/languages/', headers={'X-Auth-Token': JUDGE0_AUTHN_TOKEN})
languages = json.loads(languages.text)
for l in languages:
l_id = l['id']
if int(l_id) == 89:
continue
l_name = l['name']
lang = requests.get(f'{base_url}/languages/{l_id}', headers={'X-Auth-Token': JUDGE0_AUTHN_TOKEN})
lang = json.loads(lang.text)
l_file_ext = lang['source_file'].split('.')[-1]
lang_db = Language(number=l_id, name=l_name, file_extension=l_file_ext)
if l_id == 49 or l_id == 50 or l_id == 48 or l_id == 75:
lang_db.short_name = 'c'
elif l_id == 71:
lang_db.short_name = 'python'
elif l_id == 52 or l_id == 53 or l_id == 54 or l_id == 76:
lang_db.short_name = 'cc'
elif l_id == 51:
lang_db.short_name = 'csharp'
elif l_id == 67:
lang_db.short_name = 'pascal'
elif l_id == 62:
lang_db.short_name = 'java'
elif l_id == 55:
lang_db.short_name = 'lisp'
elif l_id == 61:
lang_db.short_name = 'haskell'
elif l_id == 59:
lang_db.short_name = 'fortran'
elif l_id == 69:
lang_db.short_name = 'prolog'
elif l_id == 63:
lang_db.short_name = 'javascript'
elif l_id == 84:
lang_db.short_name = 'vb'
db.session.add(lang_db)
for s in status:
status_db = Status(number=s['id'], name=s['description'])
db.session.add(status_db)
db.session.commit()
db.session.close()