/
aliyun.py
168 lines (154 loc) · 4.25 KB
/
aliyun.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
165
166
167
168
# -*- coding: utf-8 -*-
from Tkinter import *
import tkMessageBox
import re,os,sys
import MySQLdb
import matplotlib.pyplot as plt
root=Tk()
root.title("盈亏表")
root.geometry('600x400')
'''
#connect mysql
try:
save=MySQLdb.connect(host='10.3.247.91',user='root',passwd='mysql',db='cal_stock')
#save.query("grant all on *.* to 'root'@'10.2.48.100' identified by 'mysql'")
except Exception,e:
print e
sys.exit()
cursor=save.cursor()
#cursor.execute('insert into stock(b_price,s_price,num,profit) values (1,2,100.0,20)')
#cursor.execute("grant all on *.* to 'root'@'10.2.48.100'")
'''
#make windows
text1=Label(root,text="买入价位:")
text1.pack()
t1_text=StringVar()
t1=Entry(root,textvariable=t1_text)
t1_text.set("")
t1.pack()
text2=Label(root,text="卖出价位:")
text2.pack()
t2_text=StringVar()
t2=Entry(root,textvariable=t2_text)
t2_text.set("")
t2.pack()
text3=Label(root,text="交易总量:")
text3.pack()
t3_text=StringVar()
t3=Entry(root,textvariable=t3_text)
t3_text.set("")
t3.pack()
text4=Label(root,text="费率(万分之2.5 请填写2.5):")
text4.pack()
t4_text=StringVar()
t4=Entry(root,textvariable=t4_text)
t4_text.set("")
t4.pack()
def click():
try:
t1=t1_text.get()
t2=t2_text.get()
t3=t3_text.get()
t4=t4_text.get()
a1=float(t1)
a2=float(t2)
a3=float(t3)
a4=float(t4)
# num=a1+(float(a2)-1)*a3
# sum=(a1+num)/2*a2
sum=(a2-a1)*a3
string=str("您目前的盈亏为 %f" % sum)
print "您目前的盈亏为 %f" % sum
tkMessageBox.showinfo(title='结果',message=string)
try:
save=MySQLdb.connect(host='rm-bp12a3q2p8q14i0yk.mysql.rds.aliyuncs.com',user='re5sh0bjj8',passwd='Mysqlweb20',db='re5sh0bjj8')
#save.query("grant all on *.* to 'root'@'10.2.48.100' identified by 'mysql'")
except Exception,e:
print e
sys.exit()
cursor=save.cursor()
action="insert into n_stock(b_price,s_price,num,profit) values (%f,%f,%f,%f)" % (a1,a2,a3,sum)
try:
cursor.execute(action)
except Exception,e:
print e
cursor.close()
save.commit()
save.close()
except:
out=str("请确认输入的是数字而不是其他字符!!!")
print "请确认输入的是数字而不是其他字符!!!"
tkMessageBox.showinfo(title="警告",message=out)
def dex():
try:
t1=t1_text.get()
t2=t2_text.get()
t3=t3_text.get()
t4=t4_text.get()
a1=float(t1)
a2=float(t2)
a3=float(t3)
a4=float(t4)
# num=a1+(float(a2)-1)*a3
# sum=(a1+num)/2*a2
sum=(a2-a1)*a3-10-a2*a3*a4/10000
string=str("您目前的盈亏为 %f" % sum)
print "您目前的盈亏为 %f" % sum
tkMessageBox.showinfo(title='结果',message=string)
try:
save=MySQLdb.connect(host='rm-bp12a3q2p8q14i0yk.mysql.rds.aliyuncs.com',user='re5sh0bjj8',passwd='Mysqlweb20',db='re5sh0bjj8')
#save.query("grant all on *.* to 'root'@'10.2.48.100' identified by 'mysql'")
except Exception,e:
print e
sys.exit()
cursor=save.cursor()
action="insert into stock(b_price,s_price,num,rate,profit) values (%f,%f,%f,%f,%f)" % (a1,a2,a3,a4,sum)
try:
cursor.execute(action)
except Exception,e:
print e
cursor.close()
save.commit()
save.close()
except:
out=str("请确认输入的是数字而不是其他字符!!!")
print "请确认输入的是数字而不是其他字符!!!"
tkMessageBox.showinfo(title="警告",message=out)
def analysis():
try:
save=MySQLdb.connect(host='rm-bp12a3q2p8q14i0yk.mysql.rds.aliyuncs.com',user='re5sh0bjj8',passwd='Mysqlweb20',db='re5sh0bjj8')
#save.query("grant all on *.* to 'root'@'10.2.48.100' identified by 'mysql'")
except Exception,e:
print e
sys.exit()
cursor=save.cursor()
action="select id,profit from stock"
try:
cursor.execute(action)
except Exception,e:
print e
num=cursor.fetchall()
cursor.close()
save.commit()
save.close()
x=[]
y=[]
i=0
while i>=0:
try:
a=num[i][0]
print a
b=num[i][1]
print b
x.append(a)
y.append(b)
i+=1
except IndexError:
break
print x,y
plt.plot(x,y)
plt.show()
Button(root,text='submit',command=click).pack()
Button(root,text='submit(含手续费)',command=dex).pack()
Button(root,text='analysis',command=analysis).pack()
root.mainloop()