def __init__(self): self.mysql_helper = MysqlHelper() self.headers = { 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36', # 'Cookie':'spversion=20130314; historystock=000760%7C*%7C300383; Hm_lvt_78c58f01938e4d85eaf619eae71b4ed1=1528699762,1528875973,1528878574,1528942207; Hm_lpvt_78c58f01938e4d85eaf619eae71b4ed1=1528948403; v=Ag0soJAFas3Nd87hRUPKBs8vHCKD6kG8yx6lkE-SSaQTRiNUFzpRjFtutWLc', # 'Referer':'http://stockpage.10jqka.com.cn/HQ_v4.html' } self.user_agent_list = [ "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; AcooBrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Acoo Browser; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506)", "Mozilla/4.0 (compatible; MSIE 7.0; AOL 9.5; AOLBuild 4337.35; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)", "Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 2.0.50727; Media Center PC 6.0)", "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 1.0.3705; .NET CLR 1.1.4322)", "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.2; .NET CLR 3.0.04506.30)", "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.3 (Change: 287 c9dfb30)", "Mozilla/5.0 (X11; U; Linux; en-US) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.6", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2pre) Gecko/20070215 K-Ninja/2.1.1", "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/20080705 Firefox/3.0 Kapiko/3.0", "Mozilla/5.0 (X11; Linux i686; U;) Gecko/20070322 Kazehakase/0.4.5", "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.8) Gecko Fedora/1.9.0.8-1.fc10 Kazehakase/0.5.6", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.20 (KHTML, like Gecko) Chrome/19.0.1036.7 Safari/535.20", "Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; fr) Presto/2.9.168 Version/11.52", ]
def __init__(self): self.mysql_helper = MysqlHelper() self.headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36', 'Cookie': 'spversion=20130314; historystock=000760%7C*%7C300383; Hm_lvt_78c58f01938e4d85eaf619eae71b4ed1=1528699762,1528875973,1528878574,1528942207; Hm_lpvt_78c58f01938e4d85eaf619eae71b4ed1=1528948403; v=Ag0soJAFas3Nd87hRUPKBs8vHCKD6kG8yx6lkE-SSaQTRiNUFzpRjFtutWLc', 'Referer': 'http://stockpage.10jqka.com.cn/HQ_v4.html' }
def login(username, password): helper = MysqlHelper(host="123.57.44.168", port=3306, user="******", password="******", db="python_test_01", charset="utf8") sql = "select * from t_user where username=%s and is_deleted = 'n'" result = helper.execute(sql, [username]) if result: for user in result: pwd_md5 = md5(password) if user.get("password") == pwd_md5: print("登录成功") else: print("用户名或密码错误!") else: print("用户名或密码错误!")
class PredictHandler(tornado.web.RequestHandler): executor = ThreadPoolExecutor(32) config_json = json.load(open('config.json', 'r', encoding='utf-8')) mysql2_config = config_json['mysql2'] host = mysql2_config.get('host') user = mysql2_config.get('user') password = mysql2_config.get('password') database_name = mysql2_config.get('database') port = mysql2_config.get('port') db = MysqlHelper(host, user, password, database_name, port=port) def set_default_headers(self): self.set_header("Access-Control-Allow-Origin", "*") # 这个地方可以写域名 self.set_header("Access-Control-Allow-Headers", "x-requested-with") self.set_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS') self.set_header('Content-Type', 'application/json;charset=UTF-8') self.set_header('Access-Control-Allow-Headers', 'Content-Type') ## 查询数据库的任务 @tornado.gen.coroutine def get(self): module_name = self.get_argument('module_name', 'AAA') date = datetime.now().strftime('%Y.%m.%d') f = query(index='vkit123-' + date, startTime='now-5m', endTime='now', module_name=module_name) if len(f) != 0: t2 = datetime.now().strftime('%Y-%m-%d %H:%M:%S') t1 = (datetime.datetime.now() - datetime.timedelta(minutes=5)).strftime("%Y-%m-%d %H:%M") result = predict_raw_xgb(f, t1, t2, module_name) self.write(result) # 处理OPTIONS请求 @tornado.gen.coroutine def options(self): pass
#encoding=utf8 from mysql import MysqlHelper # sql='select * from student' # # helper = MysqlHelper.MysqlHelper('localhost',3306,'test','root','root') # one = helper.get_all(sql) # print(one) # print(one) # sid = '121' # gn_name = 'll' # zdf = 1 # ctime = 1 # sql = 'insert into tan_plate values(null,%(sid)s,%(gn_name)s,%(zdf)s,%(ctime)s' # sql='select * from student' # print(sql) # params = {"sid": sid, "gn_name": gn_name, "zdf": zdf, 'ctime': ctime} # helper = MysqlHelper.MysqlHelper('localhost', 3306, 'mystock', 'root', 'root') # print(params) sid = 'aa' gn_name = 'bb' zdf = 1 ctime = 2 # sql = 'insert into tan_plate values(null,%(sid)s,%(gn_name)s,%(zdf)s,%(ctime)s)' # sql = "insert into tan_plate values(null,'aa','bb',3,4)" params = {"sid": sid, "gn_name": gn_name, "ctime": ctime, "zdf": zdf} helper = MysqlHelper.MysqlHelper('localhost', 3306, 'mystock', 'root', 'root') helper.insert(sql, params)
# -*- coding: utf-8 -*- import numpy as np import math import matplotlib.pyplot as plt from matplotlib.widgets import Slider, Button, RadioButtons from mysql.MysqlHelper import * from pylab import mpl import datetime from file_matplotib.help import * from datetime import timedelta, date mpl.rcParams['font.sans-serif'] = ['FangSong'] # 指定默认字体 mpl.rcParams['axes.unicode_minus'] = False # 解决保存图像是负号'-'显示为方块的问题 #### now = datetime.datetime.now() db = MysqlHelper() price, money, x, sname, sid, pzdf_max, pzdf_min, money_max, money_min, next_pzdf_min, next_pzdf_max, next_price, money_all_half_slope, price_all_half_slope = stock_info( 1, 1, 1) #算每个点到起始点的斜率 斜率money - 斜率price 越大 越值得买 #第一块 ax1 = plt.subplot2grid((9, 9), (0, 0), colspan=6, rowspan=6) title_str = "%s(%s)最高涨幅%s,最低涨幅%s,最大入单%s,最大出单%s" % ( sname, sid, pzdf_max, pzdf_min, money_max, money_min) ax1.set_title(title_str, fontsize=13) line_price, = plt.plot(x, price, color='red') line_money, = plt.plot(x, money, color='purple') #第二块 ax2 = plt.subplot2grid((9, 9), (0, 6), colspan=3, rowspan=3)
# -*- coding: utf-8 -*- import numpy as np import math import matplotlib.pyplot as plt from matplotlib.widgets import Slider, Button, RadioButtons from mysql.MysqlHelper import * from pylab import mpl import datetime from datetime import timedelta, date mpl.rcParams['font.sans-serif'] = ['FangSong'] # 指定默认字体 mpl.rcParams['axes.unicode_minus'] = False # 解决保存图像是负号'-'显示为方块的问题 #### now = datetime.datetime.now() print(now) db = MysqlHelper() sql = "select * from tan_stock_record where sid='002415' and date='2018-07-18'" stock_info = db.get_all(sql) price = [] money = [] x = [] xi = 0 price0 = 0 money0 = 0 for one_stock in stock_info: if xi == 0: price0 = one_stock[3] money0 = one_stock[8] - one_stock[9] + one_stock[10] - one_stock[11] #第一个点没有资金进入这个点就不要了 if money0 == 0: continue
class TaskHandler(tornado.web.RequestHandler): executor = ThreadPoolExecutor(32) config_json = json.load(open('config.json', 'r', encoding='utf-8')) mysql2_config = config_json['mysql2'] host = mysql2_config.get('host') user = mysql2_config.get('user') password = mysql2_config.get('password') database_name = mysql2_config.get('database') port = mysql2_config.get('port') db = MysqlHelper(host, user, password, database_name, port=port) def set_default_headers(self): self.set_header("Access-Control-Allow-Origin", "*") # 这个地方可以写域名 self.set_header("Access-Control-Allow-Headers", "x-requested-with") self.set_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS') self.set_header('Content-Type', 'application/json;charset=UTF-8') self.set_header('Access-Control-Allow-Headers', 'Content-Type') ## 查询数据库的任务 @tornado.gen.coroutine def get(self): # self.db = MysqlHelper(host, user, password, dbname, port=3313) self.db.connect() lst = self.db.get_all(sql="select * from task") list = [] for item in lst: dict = {} dict['name'] = item[1] dict['data'] = item[2] dict['startTime'] = item[3] dict['endTime'] = item[4] dict['algoType'] = item[5] dict['algo'] = item[6] dict['module'] = item[7] dict['status'] = item[8] list.append(dict) self.write(json.dumps(list, ensure_ascii=False)) ##创建任务 @tornado.gen.coroutine def post(self): jsonbyte = self.request.body jsonstr = jsonbyte.decode('utf-8') jsonobj = json.loads(jsonstr) obj = {} obj['name'] = jsonobj.get('name') obj['data'] = jsonobj.get('data') obj['startTime'] = jsonobj.get('startTime') obj['algoType'] = jsonobj.get('algoType') obj['algo'] = jsonobj.get('algo') obj['module'] = jsonobj.get('module') obj['status'] = jsonobj.get('status') sql = get_i_sql('task', obj) #print(sql) n = self.db.insert(sql) if (n == 1): _thread.start_new_thread( self.coreOperation, (obj['algo'], obj['name'], obj['data'], jsonobj.get('beginTime'), jsonobj.get("endTime"), jsonobj.get("module_name"))) retdata = {} retdata['ret'] = True retdata['status'] = 0 self.write(json.dumps(retdata, ensure_ascii=False)) @tornado.gen.coroutine def delete(self, id): self.db.connect() condition = {} condition['id'] = id sql = get_d_sql('task') self.db.delete(sql) # 处理OPTIONS请求 @tornado.gen.coroutine def options(self): pass
class StockHelper(): #获取股票的时间点-价格 def __init__(self): self.mysql_helper = MysqlHelper() self.headers = { 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36', # 'Cookie':'spversion=20130314; historystock=000760%7C*%7C300383; Hm_lvt_78c58f01938e4d85eaf619eae71b4ed1=1528699762,1528875973,1528878574,1528942207; Hm_lpvt_78c58f01938e4d85eaf619eae71b4ed1=1528948403; v=Ag0soJAFas3Nd87hRUPKBs8vHCKD6kG8yx6lkE-SSaQTRiNUFzpRjFtutWLc', # 'Referer':'http://stockpage.10jqka.com.cn/HQ_v4.html' } self.user_agent_list = [ "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; AcooBrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Acoo Browser; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506)", "Mozilla/4.0 (compatible; MSIE 7.0; AOL 9.5; AOLBuild 4337.35; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)", "Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 2.0.50727; Media Center PC 6.0)", "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 1.0.3705; .NET CLR 1.1.4322)", "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.2; .NET CLR 3.0.04506.30)", "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.3 (Change: 287 c9dfb30)", "Mozilla/5.0 (X11; U; Linux; en-US) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.6", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2pre) Gecko/20070215 K-Ninja/2.1.1", "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/20080705 Firefox/3.0 Kapiko/3.0", "Mozilla/5.0 (X11; Linux i686; U;) Gecko/20070322 Kazehakase/0.4.5", "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.8) Gecko Fedora/1.9.0.8-1.fc10 Kazehakase/0.5.6", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.20 (KHTML, like Gecko) Chrome/19.0.1036.7 Safari/535.20", "Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; fr) Presto/2.9.168 Version/11.52", ] def getStockPrciePoints(self,link,handler_obj={}): time_now = int(time.time()) cookie = "spversion=20130314; historystock=000760%7C*%7C300383; Hm_lvt_78c58f01938e4d85eaf619eae71b4ed1=1528699762,1528875973,1528878574,1528942207; Hm_lpvt_78c58f01938e4d85eaf619eae71b4ed1="+str(time_now)+"; v=Ag0soJAFas3Nd87hRUPKBs8vHCKD6kG8yx6lkE-SSaQTRiNUFzpRjFtutWLc" self.headers['Cookie'] = cookie # ua = random.choice(self.user_agent_list) # if ua: # self.headers["User-Agent"] = ua try: request = urllib.request.Request(link, headers=self.headers) httpproxy_handler = urllib.request.ProxyHandler(handler_obj) #socket.setdefaulttimeout(10) opener = urllib.request.build_opener(httpproxy_handler) response = opener.open(request) content = response.read().decode() return content except Exception as e: print(e) return None def getStockPrciePoints1(self,link,handler_obj={}): time_now = int(time.time()) #cookie = "spversion=20130314; historystock=000760%7C*%7C300383; Hm_lvt_78c58f01938e4d85eaf619eae71b4ed1=1528699762,1528875973,1528878574,1528942207; Hm_lpvt_78c58f01938e4d85eaf619eae71b4ed1="+str(time_now)+"; v=Ag0soJAFas3Nd87hRUPKBs8vHCKD6kG8yx6lkE-SSaQTRiNUFzpRjFtutWLc" self.headers['Cookie'] = 'searchGuide=sg; spversion=20130314; Hm_lvt_78c58f01938e4d85eaf619eae71b4ed1=1533263275,1533432205,1533469822,1533472700; Hm_lpvt_78c58f01938e4d85eaf619eae71b4ed1=1533472700; historystock=002815%7C*%7C002415%7C*%7C002563%7C*%7C600130%7C*%7C000801; v=AiUE6KiNkkJ8fvYeZV9tagXINOpcYtmcIxa9SicK4dxrPksc77LpxLNmzQW0' self.headers['Referer'] = 'http://stockpage.10jqka.com.cn/realHead_v2.html' self.headers['Host'] = 'd.10jqka.com.cn' # ua = random.choice(self.user_agent_list) # if ua: # self.headers["User-Agent"] = ua try: request = urllib.request.Request(link, headers=self.headers) httpproxy_handler = urllib.request.ProxyHandler(handler_obj) #socket.setdefaulttimeout(10) opener = urllib.request.build_opener(httpproxy_handler) response = opener.open(request) content = response.read().decode() return content except Exception as e: print(e) return None def getStockPrciePoints2(self,link,handler_obj={}): time_now = int(time.time()) #cookie = "spversion=20130314; historystock=000760%7C*%7C300383; Hm_lvt_78c58f01938e4d85eaf619eae71b4ed1=1528699762,1528875973,1528878574,1528942207; Hm_lpvt_78c58f01938e4d85eaf619eae71b4ed1="+str(time_now)+"; v=Ag0soJAFas3Nd87hRUPKBs8vHCKD6kG8yx6lkE-SSaQTRiNUFzpRjFtutWLc" self.headers['Cookie'] = 'searchGuide=sg; spversion=20130314; Hm_lvt_78c58f01938e4d85eaf619eae71b4ed1=1533263275,1533432205,1533469822,1533472700; Hm_lpvt_78c58f01938e4d85eaf619eae71b4ed1=1533472700; historystock=002815%7C*%7C002415%7C*%7C002563%7C*%7C600130%7C*%7C000801; v=Au3MQLBlSir0li5GbUqlUr1w_IJkSiM1q3-Fty_yLUzyYwP095ox7DvOlaW8' self.headers['Referer'] = 'http://stockpage.10jqka.com.cn/002815/' # ua = random.choice(self.user_agent_list) # if ua: # self.headers["User-Agent"] = ua try: request = urllib.request.Request(link, headers=self.headers) httpproxy_handler = urllib.request.ProxyHandler(handler_obj) #socket.setdefaulttimeout(10) opener = urllib.request.build_opener(httpproxy_handler) response = opener.open(request) content = response.read().decode() return content except Exception as e: print(e) return None def getStockPrciePoints3(self,link,handler_obj={}): time_now = int(time.time()) #cookie = "spversion=20130314; historystock=000760%7C*%7C300383; Hm_lvt_78c58f01938e4d85eaf619eae71b4ed1=1528699762,1528875973,1528878574,1528942207; Hm_lpvt_78c58f01938e4d85eaf619eae71b4ed1="+str(time_now)+"; v=Ag0soJAFas3Nd87hRUPKBs8vHCKD6kG8yx6lkE-SSaQTRiNUFzpRjFtutWLc" self.headers['Cookie'] = 'searchGuide=sg; spversion=20130314; Hm_lvt_78c58f01938e4d85eaf619eae71b4ed1=1533263275,1533432205,1533469822,1533472700; Hm_lpvt_78c58f01938e4d85eaf619eae71b4ed1=1533472700; historystock=002815%7C*%7C002415%7C*%7C002563%7C*%7C600130%7C*%7C000801; v=AkdmUmbj0LiK6FQ0-mBvYDOe1vASTB_MdSGftRk0Y8P9Q2nmIRyrfoXwL-Mq' self.headers['Referer'] = 'http://stockpage.10jqka.com.cn/HQ_v4.html' self.headers['Host'] = 'd.10jqka.com.cn' # ua = random.choice(self.user_agent_list) # if ua: # self.headers["User-Agent"] = ua try: request = urllib.request.Request(link, headers=self.headers) httpproxy_handler = urllib.request.ProxyHandler(handler_obj) #socket.setdefaulttimeout(10) opener = urllib.request.build_opener(httpproxy_handler) response = opener.open(request) content = response.read().decode() return content except Exception as e: print(e) return None #获取股票的时间-大中小单 def getStockMoneyPoints(self,link,handler_obj={}): ua = random.choice(self.user_agent_list) if ua: self.headers["User-Agent"] = ua today = datetime.now().strftime("%Y-%m-%d %H:%M:%S") try: request = urllib.request.Request(link, headers=self.headers) httpproxy_handler = urllib.request.ProxyHandler(handler_obj) opener = urllib.request.build_opener(httpproxy_handler) response = opener.open(request) content = response.read().decode() return content except Exception as e: #print(e) return None #获取可用ip def getUsefulIp(self): now_time = int(time.time()) dif_now_time = int(time.time()) - 80 ip_sql = "select * from ip where last_time<%s order by success_num desc limit 30" % (dif_now_time) ip_list = self.mysql_helper.get_all(ip_sql) return ip_list #更新ip使用过 def updateIpUse(self,ip): now_time = int(time.time()) update_sql = 'update ip set last_time=%s where ip="%s"' % (now_time, ip) return self.mysql_helper.update(update_sql) # def getWatchStock(self): sql = "select * from tan_stock where is_watch=1" list = self.mysql_helper.get_all(sql) return list; def insertStockRecord(self,sql): return self.mysql_helper.insert(sql) #远程获取ip def randomIp(self,server_ip='127.0.0.1'): res = urllib.request.urlopen('http://%s:12345/api/proxy/?count=1&scheme=HTTP&anonymity=anonymous'%server_ip) html = res.read().decode() json_content = json.loads(html) ip = json_content['data']['detail'][0]['ip'] scheme = json_content['data']['detail'][0]['scheme'] port = json_content['data']['detail'][0]['port'] return ip,port,scheme def randomIpFromDb(self): sql = "select * from ip where rate>0.5" all_ip = self.mysql_helper.get_all(sql) handler_obj_list = [] for one_ip in all_ip: ip = one_ip[1] port = one_ip[2] scheme = one_ip[3] handler_obj = {} handler_obj[scheme] = ip + ':' + port handler_obj_list.append(handler_obj) return handler_obj_list #更新失败或者成功的ip def updateIp(self,ip,port,scheme,is_success=0): sql_exists = "select * from ip where ip='%s'" % (ip); success_num,fail_num = 0,0 if is_success: success_num += 1 else: fail_num += 1 ip_exists = self.mysql_helper.get_one(sql_exists) time_now = int(datetime.now().timestamp()) if ip_exists is None: sql = 'insert ignore into ip values(null,%(ip)s,%(port)s,%(scheme)s,%(success_num)s,%(fail_num)s,%(rate)s,%(last_time)s)' params = {'ip': ip, 'port': port, 'scheme': scheme, 'success_num': success_num, 'fail_num': fail_num,'rate':0,'last_time':time_now} # ip是否存在,存在更新,失败录入 print(params) self.mysql_helper.insert(sql, params) else: #4,5,6,7 old_success_num = ip_exists[4] + success_num old_fail_num = ip_exists[5] + fail_num rate = old_success_num/(old_fail_num + old_success_num) sql = 'update ip set success_num=%s,fail_num=%s,rate=%s,last_time=%s where ip="%s"' % (old_success_num,old_fail_num,rate,time_now,ip) self.mysql_helper.update(sql) print(sql)
def stock_info(wn, sn, dayn): #now = datetime.datetime.now() - timedelta(days=4) now = datetime.datetime.now() this_week_start = now - timedelta(days=now.weekday()) day1 = this_week_start.strftime('%Y-%m-%d') day2 = (this_week_start + timedelta(days=1)).strftime('%Y-%m-%d') day3 = (this_week_start + timedelta(days=2)).strftime('%Y-%m-%d') day4 = (this_week_start + timedelta(days=3)).strftime('%Y-%m-%d') day5 = (this_week_start + timedelta(days=4)).strftime('%Y-%m-%d') weekday_arr = [0, day1, day2, day3, day4, day5] db = MysqlHelper() all_stock_sql = "select * from tan_stock where is_big=2" all_stock = db.get_all(all_stock_sql) stockn = int((wn - 1) * 10 + sn) sid = all_stock[stockn - 1][1] sname = all_stock[stockn - 1][2] sql = "select * from tan_stock_record where sid='%s' and date='%s'" % ( sid, weekday_arr[dayn]) stock_info = db.get_all(sql) if len(stock_info) == 0: #return price, money, x, sname, sid, pzdf_max, pzdf_min, money_max, money_min, next_pzdf_min, next_pzdf_max, next_price return [], [], [], sname, sid, 0, 0, 0, 0, 0, 0, [], (0, 0), (0, 0) price = [] money = [] x = [] xi = 0 price_min = 9999999 price_max = -9999999 money_min = 9999999 money_max = -99999999 price_all_half_slope = (0, 0) money_all_half_slope = (0, 0) # 只为了得出最大值和最小值 pre = 0 for one_stock in stock_info: # 占多少格 pre = one_stock[7] temp_price = one_stock[3] temp_money = (one_stock[9] - one_stock[10] + one_stock[11] - one_stock[12]) / 10000 if temp_price > price_max: price_max = temp_price if temp_price < price_min: price_min = temp_price if temp_money > money_max: money_max = temp_money if temp_money < money_min: money_min = temp_money pzdf_min = round((price_min - pre) / pre * 100, 1) pzdf_max = round((price_max - pre) / pre * 100, 1) #计算斜率 for one_stock in stock_info: xi += 1 x.append(xi) # 占多少格 temp_price = one_stock[3] temp_money = (one_stock[9] - one_stock[10] + one_stock[11] - one_stock[12]) / 10000 price.append(realPoint(price_min, price_max, temp_price)) money.append(realPoint(money_min, money_max, temp_money)) #获取第二天股价的最高涨幅和最低涨幅 if dayn == 5: next_pzdf_min, next_pzdf_max = 0, 0 next_price = [] else: sql = "select * from tan_stock_record where sid='%s' and date='%s'" % ( sid, weekday_arr[dayn + 1]) stock_info = db.get_all(sql) price_max = -9999999 price_min = 9999999 # 只为了得出最大值和最小值 pre = 0 for one_stock in stock_info: # 占多少格 pre = one_stock[7] temp_price = one_stock[3] if temp_price > price_max: price_max = temp_price if temp_price < price_min: price_min = temp_price #100等分 next_price = [] for one_stock in stock_info: # 占多少格 next_price.append(realPoint(price_min, price_max, one_stock[3])) next_pzdf_min = round((price_min - pre) / pre * 100, 1) next_pzdf_max = round((price_max - pre) / pre * 100, 1) #price,money是计算好的斜率 money_all_half_slope = all_half_slope(x, money) price_all_half_slope = all_half_slope(x, price) return price, money, x, sname, sid, pzdf_max, pzdf_min, money_max, money_min, next_pzdf_min, next_pzdf_max, next_price, money_all_half_slope, price_all_half_slope
def stock_today(sn=1): offset = sn - 1 today = datetime.datetime.now().strftime('%Y-%m-%d') today = '2018-09-14' sql = "SELECT * from tan_stock_content WHERE date='%s' order by id desc LIMIT %s,1" % ( today, offset) # print(sql) db = MysqlHelper() stock_info = db.get_one(sql) price_content = stock_info[2] money_content = stock_info[3] sid = stock_info[1] key = 'hs_%s' % (sid) price_dict = decode_stock_json(price_content) money_dict = decode_stock_json(money_content) price_data = price_dict[key]['data'].split(';') is_stop = price_dict[key]['stop'] #停牌 if is_stop: #price, money, x, sname, sid, pzdf_max, pzdf_min,money_max, money_min, money_all_half_slope, price_all_half_slope sql = "select * from tan_stock where sid='%s'" % (sid) stock = db.get_one(sql) sname = stock[2] return [], [], [], '%s停牌' % (sname), sid, 0, 0, 0, 0, (0, 0), (0, 0) pre = float(price_dict[key]['pre']) money_data = money_dict[key]['data'].split(';') #price所有价格集合,所有money集合 price = [] money = [] x = [] xi = 0 price_min = 9999999 price_max = -9999999 money_min = 9999999 money_max = -99999999 price_all_half_slope = (0, 0) money_all_half_slope = (0, 0) # 只为了得出最大值和最小值 for i in range(len(price_data)): xi += 1 x.append(xi) price_temp_arr = price_data[i].split(',') temp_price = float(price_temp_arr[1]) money_temp_arr = money_data[i].split(',') temp_money = (float(money_temp_arr[1]) - float(money_temp_arr[2]) + float(money_temp_arr[3]) - float(money_temp_arr[4])) / 1000 if temp_price > price_max: price_max = temp_price if temp_price < price_min: price_min = temp_price if temp_money > money_max: money_max = temp_money if temp_money < money_min: money_min = temp_money pzdf_min = round((price_min - pre) / pre * 100, 1) pzdf_max = round((price_max - pre) / pre * 100, 1) for i in range(len(price_data)): #第i个点 #股价 price_temp_arr = price_data[i].split(',') temp_price = float(price_temp_arr[1]) #大单 money_temp_arr = money_data[i].split(',') temp_money = (float(money_temp_arr[1]) - float(money_temp_arr[2]) + float(money_temp_arr[3]) - float(money_temp_arr[4])) / 1000 price.append(realPoint(price_min, price_max, temp_price)) money.append(realPoint(money_min, money_max, temp_money)) sql = "select * from tan_stock where sid='%s'" % (sid) stock = db.get_one(sql) sname = stock[2] money_all_half_slope = all_half_slope(x, money) price_all_half_slope = all_half_slope(x, price) return price, money, x, sname, sid, pzdf_max, pzdf_min, money_max, money_min, money_all_half_slope, price_all_half_slope
import time