-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_snapshot.py
51 lines (41 loc) · 1.41 KB
/
get_snapshot.py
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
import os
import requests
import json
from bs4 import BeautifulSoup
def read_data(id):
id = str(id)
try:
with open('./db/'+id+'.json', 'r') as f:
return json.loads(f.readline())
except:
return {}
def write_data(id,db):
id = str(id)
with open('./db/'+id+'.json', 'w') as f:
f.write(json.dumps(db))
import requests
def get_snapshot():
for cp,dir,files in os.walk('./db/'):
for file in files:
if file.endswith('.json'):
user = file[:-len('.json')]
db = read_data(user)
list = []
print(db)
if len(db.keys()) > 0:
for i in db.keys():
wallet = db[i]['wallet']
yesterday = db[i]['yesterday']
slp = requests.get(f'https://game-api.skymavis.com/game-api/clients/{wallet}/items/1').json()['total']
if slp >= yesterday:
slp_new = slp-yesterday
else:
slp_new = slp
db[i]['slp'].append(slp_new)
db[i]['yesterday'] = slp
if len(db[i]['slp']) > 14:
db[i]['slp'] = db[i]['slp'][-14:]
list.append((i,slp_new))
write_data(user,db)
pass
get_snapshot()