-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhandle_requests.py
More file actions
executable file
·52 lines (38 loc) · 1.28 KB
/
Copy pathhandle_requests.py
File metadata and controls
executable file
·52 lines (38 loc) · 1.28 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
#!/usr/bin/env python3
import requests
import json
def request_code(token):
payload = {'token': token}
url = 'https://api.codenation.dev/v1/challenge/dev-ps/generate-data'
r = requests.get(url, params=payload)
try:
r.raise_for_status()
except requests.exceptions.HTTPError as e:
print(e)
print('GET BODY:', r.json())
exit()
data = r.json()
with open('answer.json', 'w') as f:
json.dump(data, f)
return {'text': data['cifrado'], 'rotations': data['numero_casas']}
def update_answer(decoded, cryptographic_summary):
jsonFile = open('answer.json', 'r')
data = json.load(jsonFile)
jsonFile.close()
data['decifrado'] = decoded
data['resumo_criptografico'] = cryptographic_summary
jsonFile = open('answer.json', 'w+')
jsonFile.write(json.dumps(data))
jsonFile.close
def post_answer(token):
payload = {'token': token}
url = 'https://api.codenation.dev/v1/challenge/dev-ps/submit-solution'
answer = {'answer': open('answer.json', 'rb')}
r = requests.post(url, params=payload, files=answer)
try:
r.raise_for_status()
except requests.exceptions.HTTPError as e:
print(e)
print('POST BODY:', r.json())
exit()
print('OK: ', r.json())