-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAeAPI.py
More file actions
82 lines (70 loc) · 1.92 KB
/
AeAPI.py
File metadata and controls
82 lines (70 loc) · 1.92 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
import threading
import json
import urllib.request
import urllib.parse
class AeAPI:
url = "http://ae27ff.localhost/api/"
appname = 'Unknown-PyAeAPI-App'
appid = ''
appver = '1.0'
apiver='1.0'
@classmethod
def query_preparedata(cls,data_fields):
if data_fields is None:
return None
json_fields = {k: json.dumps(v) for k,v in data_fields.items()}
return urllib.parse.urlencode(json_fields).encode('utf-8');
@classmethod
def query(cls,qname,fields={},data_fields={}):
result = {}
try:
fields['query']=qname
fields['appid']=cls.appid
arguments = urllib.parse.urlencode(fields)
qurl = cls.url + "?"+ arguments
req = urllib.request.Request(
qurl,
data=cls.query_preparedata(data_fields),
headers={
'User-Agent':'PyAeAPI/'+cls.apiver+' '+cls.appname+'/'+cls.appver,
"Content-Type": "application/x-www-form-urlencoded"
}
)
result = json.loads(urllib.request.urlopen(req).read().decode('utf-8'))
except Exception as e:
result={'neterror':True,'error':e}
else:
result['neterror']=False;
return result
@classmethod
def usersonrank(cls,rank):
return cls.query('usersonrank',{'rank':rank})
@classmethod
def progressions(cls,user='*',limit=100):
return cls.query('progressions',{'user':user,'limit':limit})
@classmethod
def lastrankup(cls):
return cls.query('lastrankup')
@classmethod
def userrank(cls,user):
return cls.query('userrank',{'user':user})
@classmethod
def bulkrank(cls,users):
return cls.query('bulkrank',{},{'users':users});
@classmethod
def activity(cls,days=None):
if days is None:
return cls.query('activity')
return cls.query('activity',{'days':days})
# timer_func = None
# def timershim():
# if AeAPI.timer_func is not None:
# print('run timer')
# AeAPI.timer_func()
# threading.Timer(60, AeAPI.timershim).start()
#
#
# def timer(timerfunc):
# print('set timer func')
# AeAPI.timer_func = timerfunc
# AeAPI.timershim()