-
Notifications
You must be signed in to change notification settings - Fork 0
/
web_service.py
164 lines (129 loc) · 3.43 KB
/
web_service.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# -*- coding: utf-8 -*-
'''
Created on 2014/6/9
@author: fpy
'''
from flask import Flask
from flask import request
from flask import render_template
from PyDbLite import Base
from stock_profile import *
from flask import Markup
from cindy import *
import markdown
app = Flask(__name__)
'''
@app.route('/')
def index():
username = request.cookies.get('Username')
if username is None:
return 'Hello, ALF'
else:
return 'Hello, Java'
'''
@app.route('/welcome', methods=['POST'])
def welcome():
db = Base('alf.db')
db.create('name','pwd',mode="open") #override
user = request.form['Username']
passwd = request.form['password1']
db.insert(name=user,pwd=passwd)
db.commit()
return 'welcome ' + user
def run():
sa = StockActor()
batch = CsvBatchCommander('alf.csv', sa)
@app.route('/alf', methods=['POST'])
def alf():
db = Base('alf.db')
db.open()
user = request.form['Username']
pwd = request.form['password']
user_verf = [r['password'] for r in db if r['name'] == user]
if len(user_verf) > 0:
if user_verf[0] == pwd:
return 'Hello, ' + user
else:
return 'Who are you!!!'
@app.route('/reg')
def signup():
return render_template('signup.html')
@app.route('/login')
def login():
return render_template('login.html')
@app.route('/users')
def users():
db = Base('alf.db')
db.open()
users = []
for r in db:
n = r['name']
p = r['pwd']
users.append((n, p))
return render_template('user.html', users=users)
@app.route('/stock/<stockid>')
def show_stock_profile(stockid):
# show the user profile for that stock
stock = Stock_Profile(stockid)
return render_template('stock.html', stock=stock)
@app.route('/buy')
def buy():
# show the user profile for that stock
sm = StockManager()
stock = Stock_Profile('2002')
current = stock.get_result(0)[0]
db = Base('overall.db')
db.open()
stocks = [r for r in db if (r['buy']==1) and (r['date']==current)]
return render_template('buy.html', stocks=stocks)
@app.route('/sell')
def sell():
# show the user profile for that stock
sm = StockManager()
stock = Stock_Profile('2002')
current = stock.get_result(0)[0]
db = Base('overall.db')
db.open()
stocks = [r for r in db if r['sell']==1 and (r['date']==current)]
return render_template('buy.html', stocks=stocks)
@app.route('/host')
def host():
# show the user profile for that stock
db = Base('overall.db')
db.open()
#stocks = [r for r in db if r['state']==1]
stocks = [r for r in db]
return render_template('all.html', stocks=stocks)
@app.route('/')
def frontpage():
run()
return render_template('frontpage.html')
@app.route('/help')
def helps():
return render_template('help.html', **locals())
def helps_old():
content = """
Quick Start
=======
Search
-------
* Enter the stock id
* Click the search icon
Buy Signals
----------
* List all the stocks (the subset of All My Fav) with buy signal
Sell Signals
----------
* List all the stocks transited from buy signal to sell signal
All My Fav
----------
* List all stocks you like
"""
content = Markup(markdown.markdown(content))
return render_template('help_old.html', **locals())
@app.errorhandler(500)
def page_not_found(e):
return render_template('500.html'), 500
if __name__ == '__main__':
app.debug = True
app.run(host='0.0.0.0')