forked from yiransheng/Option-Quotes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.py
More file actions
72 lines (61 loc) · 2.1 KB
/
admin.py
File metadata and controls
72 lines (61 loc) · 2.1 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
import datetime
import sys
import os
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app
from django.utils import simplejson
import urllib2
###########
from models import *
from queries import *
import request
import defs
class MainPage(request.WebPageHandler):
def get(self):
stocks = Stock.get_all()
template_values = {
'title': defs.APP_NAME,
'external': OPTIONS_CHAIN_HTML,
'stocks': stocks,
}
self.response.out.write(self.render_template('admin.html', \
template_values))
class ModifyStockInfo(request.WebPageHandler):
def post(self):
symbol = self.request.get('symbol')
action = self.request.get('action')
if action == '2':
self.update_all()
self.redirect('/admin/')
if action == '3':
stock = Stock.get(symbol)
if stock:
stock.delete()
self.redirect('/admin/')
if action == '1':
cboeQuery = Cboe(symbol, True, True)
stock = Stock.get(cboeQuery.stock.symbol)
if stock:
stock.cboe_id = cboeQuery.stock.cboe_id
stock.exp_months = cboeQuery.stock.exp_months
else:
stock = cboeQuery.stock
stock.put()
self.redirect('/admin/')
def update_all(self):
stocks = Stock.get_all()
for stock in stocks:
cboeQuery = Cboe(stock.symbol, True, True)
stock.cboe_id = cboeQuery.stock.cboe_id
stock.exp_months = cboeQuery.stock.exp_months
stock.put()
application = webapp.WSGIApplication(
[('/admin/?', MainPage),
('/admin/modify/?', ModifyStockInfo),
],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()