-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
63 lines (57 loc) · 2.01 KB
/
Copy pathapp.py
File metadata and controls
63 lines (57 loc) · 2.01 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
import requests as re
from delete import *
import pprint
import json
import sys
langs = ['en-US', 'de-DE', 'es-ES', 'es-MX', 'fr-FR', 'it-IT', 'ja-JP', 'pl-PL', 'pt-BR', 'ru-RU']
index = 0
if len(sys.argv) > 0:
if sys.argv[1] in langs:
index = langs.index(sys.argv[1])
print("Getting a JSON for the " + langs[index] + " indexuage")
url = 'https://api.gwentapi.com/v0/cards'
print('Getting the Amount of Cards of Database')
pag = re.get(url)
if pag.status_code != 200:
print(pag.status_code)
else:
limit = pag.json()['count']
url += "?limit=" + str(limit) + '&index=' + langs[index]
pag = re.get(url)
if pag.status_code != 200:
print(pag.status_code)
else:
with open('aux.json', 'w') as arquivo:
arquivo.write(json.dumps(pag.json()["results"]))
size = limit
aux = json.load(open('aux.json', 'r'))
file = open('cards.json', 'w')
file.write('['), file.close()
for i in range(size):
print("Making the request for : " + aux[i]['name'])
cart = re.get(aux[i]['href'])
with open("cards.json", 'a')as file:
if i < (size - 1):
print("Writing the request for : " + aux[i]['name'] + " in file.")
file.write(json.dumps(cart.json()) + ",")
else:
print("Writing the request for : " + aux[i]['name'] + " in file.")
file.write(json.dumps(cart.json()) + "]")
cartas = json.load(open('cards.json', 'r'))
file = open('variations.json', 'w')
file.write('['), file.close()
for i in range(size):
print('Getting Variations for: ' + cartas[i]['name'])
var = re.get(cartas[i]['variations'][0]['href'])
with open('variations.json', 'a') as file:
if i < (size - 1):
print('writing variations for :' + cartas[i]['name'])
file.write(json.dumps(var.json()) + ',')
else:
print('writing variations for :' + cartas[i]['name'])
file.write(json.dumps(var.json()) + ']')
print('CLEANING THE THE JSONS')
clean_cards('cards.json')
clean_variations('variations.json')
delete('aux.json')
print('Done!')