-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathetroGetter.py
More file actions
91 lines (72 loc) · 2.61 KB
/
etroGetter.py
File metadata and controls
91 lines (72 loc) · 2.61 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
from urllib.parse import urlparse
import requests
from requests.exceptions import HTTPError
def get_set_from_etro(url):
if(url == ""):
return ""
return_list = {'WD': 0, 'Int': 0, 'DH': 0, 'Crit': 0, 'Det': 0, 'Sps': 0}
gearset = urlparse(url).path.split('/')[2]
new_url = 'https://etro.gg/api/gearsets/'+gearset+'/'
try:
response = requests.get(new_url)
response.raise_for_status()
json_response = response.json()
except HTTPError as http_err:
print(f'HTTP error occurred: {http_err}')
except Exception as err:
print(f'Other error occurred: {err}')
else:
# return response
for i in json_response['totalParams']:
if i['name'] == 'Weapon Damage':
return_list['WD']=i['value']
if i['name'] == 'INT':
return_list['Int']=i['value']
if i['name'] == 'DH':
return_list['DH']=i['value']
if i['name'] == 'CRT':
return_list['Crit']=i['value']
if i['name'] == 'DET':
return_list['Det']=i['value']
if i['name'] == 'SPS':
return_list['Sps']=i['value']
return return_list
# %%
import coreapi
def get_set_from_etro2(url):
if(url == ""):
return ""
return_list = {'WD': 0, 'Int': 0, 'DH': 0, 'Crit': 0, 'Det': 0, 'Sps': 0}
# Initialize a client & load the schema document
client = coreapi.Client()
schema = client.get("https://etro.gg/api/docs/")
# Interact with the API endpoint
action = ["gearsets", "read"]
params = {
"id": url.split('/')[-1],
}
try:
result = client.action(schema, action, params=params)
except HTTPError as http_err:
print(f'HTTP error occurred: {http_err}')
except Exception as err:
print(f'Other error occurred: {err}')
else:
for i in result['totalParams']:
if i['name'] == 'Weapon Damage':
return_list['WD']=i['value']
if i['name'] == 'INT':
return_list['Int']=i['value']
if i['name'] == 'DH':
return_list['DH']=i['value']
if i['name'] == 'CRT':
return_list['Crit']=i['value']
if i['name'] == 'DET':
return_list['Det']=i['value']
if i['name'] == 'SPS':
return_list['Sps']=i['value']
return return_list
# a = get_set_from_etro2('https://etro.gg/gearset/d6c0b7f7-21c4-451c-88f0-ddb867bd19d3')
# path = 'https://etro.gg/gearset/bdf03606-6cf5-41fb-ad39-fe5a58ca7e72'
# a = get_set_from_etro2(path)
# print(a)