-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
118 lines (96 loc) · 3.48 KB
/
run.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
# -*- coding:utf-8 -*-
from flask import Flask, request, session, g, redirect, url_for, abort, \
render_template, send_file
import tushare as ts
import datetime
from urllib import quote
import os
app = Flask(__name__)
UPLOAD_FOLDER='upload'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
basedir = os.path.abspath(os.path.dirname(__file__))
def getYearQuarter(datePicker=None):
if datePicker:
[year, quarterStr] = datePicker.split(" ")
quarter = int(quarterStr[1])
else:
now = datetime.datetime.now()
quarter = (now.month / 3) if now.month % 3 == 0 else now.month / 3 + 1
year = now.year
return [year, quarter]
def export(exportType, datePicker):
sb = None
[year, quarter] = getYearQuarter(datePicker)
if exportType == "report":
name = "业绩报表"
sb = ts.get_report_data(year, quarter)
elif exportType == "profit":
name = "盈利能力报表"
sb = ts.get_profit_data(year, quarter)
elif exportType == "operation":
name = "营运能力报表"
sb = ts.get_operation_data(year, quarter)
elif exportType == "growth":
name = "成长能力报表"
sb = ts.get_growth_data(year, quarter)
elif exportType == "debtpaying":
name = "偿债能力报表"
sb = ts.get_debtpaying_data(year, quarter)
elif exportType == "cashflow":
name = "现金流量报表"
sb = ts.get_cashflow_data(year, quarter)
filename = quote(name + str(year) + "Q" +str(quarter) + ".xlsx")
filepath = os.path.join(basedir, app.config['UPLOAD_FOLDER'], filename)
sb.to_excel(filepath)
rtn = send_file(filepath, as_attachment=True)
rtn.headers['Content-Disposition'] += "; filename*=utf-8''%s" % (filename)
return rtn
@app.route('/')
def hello_world():
return render_template('stock_basics.html')
#return 'Hello World!'
@app.route('/stock/basics')
def stock_basics():
return render_template('stock_basics.html')
@app.route('/stock/basics/export', methods=['POST'])
def stock_basics_export():
date = ""
year = ""
quarter = ""
quarters = {'Q1': '0331', 'Q2': '0630', 'Q3': '0930', 'Q4': '1231'}
datePicker = request.form['datePicker']
if datePicker:
[year, quarter] = datePicker.split(" ")
date = year + quarters.get(quarter)
filename = quote("股票列表"+str(year)+str(quarter)+".xlsx")
filepath = os.path.join(basedir, app.config['UPLOAD_FOLDER'], filename)
sb = ts.get_stock_basics(date)
sb.to_excel(filepath)
rtn = send_file(filepath, as_attachment=True)
rtn.headers['Content-Disposition']+="; filename*=utf-8''%s"%(filename)
return rtn
@app.route('/stock/report')
def stock_report():
return render_template('stock_report.html')
@app.route('/stock/profit')
def stock_profit():
return render_template('stock_profit.html')
@app.route('/stock/operation')
def stock_operation():
return render_template('stock_operation.html')
@app.route('/stock/growth')
def stock_growth():
return render_template('stock_growth.html')
@app.route('/stock/debtpaying')
def stock_debtpaying():
return render_template('stock_debtpaying.html')
@app.route('/stock/cashflow')
def stock_cashflow():
return render_template('stock_cashflow.html')
@app.route('/stock/export/<exportType>', methods=['GET', 'POST'])
def stock_export(exportType):
datePicker = request.form['datePicker']
rtn = export(exportType, datePicker)
return rtn
if __name__ == '__main__':
app.run(debug=True)