-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathupdate_category_info.py
57 lines (40 loc) · 1.85 KB
/
update_category_info.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
52
53
54
55
56
57
#coding=utf8
import logging
import string
from google.appengine.api.labs import taskqueue
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
import stock
class UpdateCategoryInfoHandler(webapp.RequestHandler):
def get(self):
taskqueue.add(url='/tasks/updateallcategoryinfo',
queue_name='updatecategoryinfo',
method='GET')
class UpdateAllCategoryInfoHandler(webapp.RequestHandler):
def get(self):
with open('config/category') as file:
for line in file.readlines():
fields = line.split()
taskqueue.add(url='/tasks/updatesinglecategoryinfo',
queue_name='updatecategoryinfo',
method='GET',
params={'ticker' : fields[0],
'category' : fields[1],
'subcategory' : fields[2]})
class UpdateSingleCategoryInfoHandler(webapp.RequestHandler):
def get(self):
ticker = self.request.get('ticker')
category = self.request.get('category')
subcategory = self.request.get('subcategory')
entry = stock.get(ticker)
entry.category = category
entry.subcategory = subcategory
stock.put(ticker, entry)
application = webapp.WSGIApplication([('/tasks/updatecategoryinfo', UpdateCategoryInfoHandler),
('/tasks/updateallcategoryinfo', UpdateAllCategoryInfoHandler),
('/tasks/updatesinglecategoryinfo', UpdateSingleCategoryInfoHandler)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == '__main__':
main()