-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFetch.py
More file actions
39 lines (37 loc) · 1.01 KB
/
Fetch.py
File metadata and controls
39 lines (37 loc) · 1.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
import requests, json
tokens = []
def main(ipaddress):
global Tokens
s = requests.Session()
while True:
try:
res = s.get('http://'+ipaddress+':5000/json')
break
except:
pass
json_dict = res.json()
index = 0
capToken = 'temp'
while True:
try:
capToken = json_dict['tokens'][index]
except IndexError:
index = 0
while True:
try:
res = s.get('http://'+ipaddress+':5000/json')
break
except:
pass
json_dict = res.json()
pass
if capToken in tokens or capToken in json_dict['used']:
index = index + 1
elif capToken == 'temp':
pass
elif capToken == '':
index = index + 1
else:
tokens.append(capToken)
s.post('http://'+ipaddress+':5000/used', data = {'usedtoken':capToken})
return(capToken)