-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapi_handler.py
46 lines (30 loc) · 1.16 KB
/
api_handler.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
# coding: utf-8
import webapp2
from google.appengine.api import urlfetch
from google.appengine.api import memcache
import json
from fetch_config import config as fetch_config
import lib
class ApiHandler(webapp2.RequestHandler):
def get(self, cluster_id=None):
cluster_attrs = fetch_config[cluster_id]
result = urlfetch.fetch(cluster_attrs['url'])
# appids = result.content.split('|')
appids = lib.getAppidFromINI(result.content)
appid_dict = memcache.get_multi(appids)
response_dict = {
"available": [],
"over_quota": [],
}
for appid, val in appid_dict.iteritems():
if val is True:
response_dict['available'].append(appid)
elif val is False:
response_dict['over_quota'].append(appid)
response_dict['status_msg'] = "今日还剩 %dGB/%dGB 流量" % (len(response_dict['available']), len(appids))
response_json = json.dumps(response_dict, ensure_ascii=False)
self.response.write(response_json)
app = webapp2.WSGIApplication([
# (r'/api', ApiHandler),
(r'/api/(.*)', ApiHandler)
], debug=True)