def get(self): #提取爬虫设置信息 #?setInfo={'spiderName': "ceshi2", 'spiderTag': 'webPage', 'spiderUrl': "", "spiderRule": "", 'isValid':'False', 'isDel':'True', "timeSet" : "* * * * *", 'mark':'测试设置' } #?setInfo={'spiderName': "sh000001", 'spiderTag': 'quote', 'spiderUrl': "", "spiderRule": "", 'isValid':'True', 'isDel':'False', "timeSet" : "* 9-20 * * 1-6", 'mark':'测试设置' } params = request.args.get('setInfo', "{}") setInfo = myData_Json.Trans_ToJson(params) #setInfo = myData_Trans.Tran_ToDict(params) bRes = not (setInfo.get("spiderName", "") == "") bRemove = myData_Trans.To_Bool(setInfo.get('isDel', "False")) if(setInfo.get("timeSet", None) == None): setInfo['timeSet'] = "* 9-15 * * 1-5" if(bRes and bRemove): bRes = setsSpider._Remove(setInfo['spiderName']) bRes = setsSpider._Find(setInfo["spiderName"]) == None else: bRes = setsSpider._Edit(setInfo) pMsg = copy.deepcopy(gol._Get_Setting('Return_strFormat', {})) if(bRes): pMsg['result'] = True spiderInfo = setsSpider._Find(setInfo["spiderName"]) if(bRemove != True and spiderInfo != None): if(spiderInfo.isValid and not spiderInfo.isDeled): pMsg['datas'] = [spiderInfo.ToDict()] #return myData_Json.Trans_ToJson_str(pMsg) #使用jsonify来讲定义好的数据转换成json格式,并且返回给前端 return jsonify(pMsg)
def _GetParamValues_ByJson(self, strParams, default): #循环提取项 pValues = [] nIndex = 0 for strParam in strParams: default_Value = 0 if (len(default) > nIndex): default_Value = default[nIndex] nIndex += 1 #判断是否有=好,无的为布尔类型 value = "" if (strParam in self.__dict__): value = self.__dict__[strParam] #未设置则修正为默认 if (value == ""): value = default_Value #value解析为Json,直接转换为List if (type(value) == str): pJson = myData_Json.Trans_ToJson(value) #print(pJson) if (type(pJson) == list): pValues.append(pJson) else: pValues.append(default_Value) else: pValues.append(default_Value) return pValues
def stockSetQuery_risk(): #载入配置 usrID = request.args.get('usrID', "") stockName = request.args.get('stockName', "") stockTag = request.args.get('stockTag', "") #筛选 res = {"success": 1, "data": "", "msg": ""} try: #strUrl = "http://" + request.remote_addr + ":8669/zxcAPI/robot" #实际网络地址在阿里云有问题,原因未明 strUrl = "http://127.0.0.1:8669/zxcAPI/robot" strPath = F'stock/QuoteSetRisk/Query?usrID={usrID}&code_id={stockTag}&code_name={stockName}' #设置查询接口执行 pWeb = myWeb_urlLib.myWeb(strUrl, bPrint=False) strReturn = pWeb.Do_API_get(strPath, "zxcAPI-py") print("查询结果:\n", strUrl, "--\n", strReturn, "\n") jsonRes = myData_Json.Trans_ToJson(strReturn) res['data'] = jsonRes['text'] res['success'] = int(jsonRes['result']) except Exception as err: res['success'] = 0 res['msg'] = str(err) return myData_Json.Trans_ToJson_str(res)
def stockSetQuery_info(): #载入配置 stockName = request.args.get('stockName', "") stockTag = request.args.get('stockTag', "").split('.') usrID = request.args.get('usrID', "") #筛选 res = {"success": 1, "data": "", "msg": ""} try: #strUrl = "http://" + request.remote_addr + ":8669/zxcAPI/robot" #实际网络地址在阿里云有问题,原因未明 strUrl = "http://127.0.0.1:8669/zxcAPI/robot" strPath = 'stock/QuoteSetInfo/Query?stockName=' + stockName + "&exType=" + stockTag[ 0] + "&stockID=" + stockTag[1] + "&usrID=" + usrID #设置查询接口执行 pWeb = myWeb_urlLib.myWeb(strUrl, bPrint=False) strReturn = pWeb.Do_API_get(strPath, "zxcAPI-py") print("查询结果:\n", strUrl, "--\n", strReturn, "\n") jsonRes = myData_Json.Trans_ToJson(strReturn) #结果处理 res['data'] = jsonRes['text'] res['success'] = int(jsonRes['result']) except Exception as err: res['success'] = 0 res['msg'] = str(err) return myData_Json.Trans_ToJson_str(res)
def stockQuoteSet(usrID, plat): form = stockQuoteSetForm() #生成form实例,给render_template渲染使用 if form.validate_on_submit(): #调用form实例里面的validate_on_submit()功能,验证数据是否安全,如是返回True,默认返回False #添加订单 #strUrl = "http://" + request.remote_addr + ":8669/zxcAPI/robot" strUrl = "http://127.0.0.1:8669/zxcAPI/robot" #实际网络地址在阿里云有问题,原因未明 if form.save.data: # 保存按钮被单击 editInfo = {} # 特殊同步 usrIDs = { usrID : plat} #if(usrID == '茶叶一主号' or usrID == '老婆'): # usrIDs["茶叶一主号"] = plat # usrIDs["老婆"] = plat editInfo[form.monitorHourly.label.text] = {'isValid': form.monitorHourly.data, 'msgUsers': usrIDs, 'mark' :""} editInfo[form.monitorRise_Fall.label.text] = {'isValid': form.monitorRise_Fall.data, 'msgUsers': usrIDs, 'mark' :""} strPath = 'stock/QuoteSet?extype=' + form.exType.data + "&code_id=" + form.code_id.data + "&code_name=" + "&editInfo=" + str(editInfo) #+ form.code_name.data elif form.remove.data: # 移除按钮被单击 strPath = 'stock/QuoteSet?extype=' + form.exType.data + "&code_id=" + form.code_id.data + "&code_name=" + "&removeSet=True" + "&usrID=" + usrID #修改接口执行 pWeb = myWeb_urlLib.myWeb(strUrl, bPrint=False) strReturn = pWeb.Do_API_get(strPath, "zxcAPI-py") jsonRes = myData_Json.Trans_ToJson(strReturn) #结果处理 return jsonRes['text'] return render_template('stockQuoteSet.html', title = 'Stock QuoteSet', form = form, usrName_Nick = usrID, usrPlat = plat)
def getOptInfos_Month(self, nameETF="50ETF"): url = F"http://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionService.getStockName?exchange=null&cate={nameETF}" req = urllib.request.Request(url) res_data = urllib.request.urlopen(req) res = res_data.read().decode(encoding="gbk") jsonRes = myData_Json.Trans_ToJson(res) return jsonRes['result']['data']["stockId"], jsonRes['result']['data'][ "contractMonth"]
def stockQuoteSet_risk(usrID, plat): #载入配置 stockName = request.args.get('code_name', "") stockID = request.args.get('code_id', "") stockDate = request.args.get('dateTag', "") #纠正风控账户名 if (usrID == '@*股票监测--自选行情'): usrID = '@*风控监测--股票' if (usrID == '@*股票监测--期权行情'): usrID = '@*风控监测--期权' if (usrID.count('股票监测') == 1): usrID = usrID.replace('股票监测', '风控监测') form = stockQuoteSetRiskForm() #生成form实例,给render_template渲染使用 if (True): if (form.deltaProfit.data == None or form.deltaProfit.data == 0): form.deltaProfit.data = 0.0025 if (form.stopProfit.data == None): form.stopProfit.data = 0.06 form.stopProfit_Retreat.data = 0.01 form.stopProfit_Trade.data = 0.2 if (form.stopLoss.data == None): form.stopLoss.data = -0.02 form.stopLoss_Retreat.data = 0.01 form.stopLoss_Trade.data = 0.2 if form.validate_on_submit( ): #调用form实例里面的validate_on_submit()功能,验证数据是否安全,如是返回True,默认返回False #添加订单 #strUrl = "http://" + request.remote_addr + ":8669/zxcAPI/robot" strUrl = "http://127.0.0.1:8669/zxcAPI/robot" #实际网络地址在阿里云有问题,原因未明 if form.save.data: # 保存按钮被单击 editInfo = {} # 特殊同步 usrIDs = {usrID: plat} #editInfo[form.monitorRisk.label.text] = {'isValid': form.monitorRisk.data, 'msgUsers': usrIDs, 'mark' :""} strPath = F'stock/QuoteSetRisk?usrID={usrID}&code_id={stockID}&code_name={stockName}&dateTag={form.stockDate.data}&removeSet=False&stockPrice={form.stockPrice.data}&stockNum={form.stockNum.data}' #&setInfo=' + "{}" elif form.remove.data: # 移除按钮被单击 strPath = F'stock/QuoteSetRisk?usrID={usrID}&code_id={stockID}&code_name={stockName}&dateTag={form.stockDate.data}&removeSet=True' #修改接口执行 pWeb = myWeb_urlLib.myWeb(strUrl, bPrint=False) strReturn = pWeb.Do_API_get(strPath, "zxcAPI-py") jsonRes = myData_Json.Trans_ToJson(strReturn) #结果处理 return jsonRes['text'] return render_template('stockQuoteSetRisk.html', title='Stock QuoteSetRisk', form=form, usrName_Nick=usrID, usrPlat=plat, code_id=stockID, code_name=stockName)
def stockSetQuery(usrID): #strUrl = "http://" + request.remote_addr + ":8669/zxcAPI/robot" #实际网络地址在阿里云有问题,原因未明 strUrl = "http://127.0.0.1:8669/zxcAPI/robot" strPath = 'stock/QuoteSet/Query?usrID=' + usrID #设置查询接口执行 pWeb = myWeb_urlLib.myWeb(strUrl, bPrint=False) strReturn = pWeb.Do_API_get(strPath, "zxcAPI-py") print("查询结果:\n", strUrl, "--\n", strReturn, "\n") jsonRes = myData_Json.Trans_ToJson(strReturn) #结果处理 jsonRetrun = myData_Json.Json_Object(jsonRes['text']) return jsonRetrun.ToString()
def initParam_str(self, param): #json参数转换为列表 dictParam = myData_Json.Trans_ToJson(param) return self.initParam(dictParam)
def _Done_Text_set风控(self, cmd, cmds = [], usrInfo = {}): if(cmd == "风控"): #解析参数 样例:"@¥*风控 sh.10002626 50ETF沽8月3400 10股 1240元" lstInd = ["风控"] stockPrice = 0 stockNum = 0 for x in cmds: strPrice = self.Matching_set(x, "元") if(strPrice != ""): stockPrice = float(strPrice) lstInd.append(x); continue; strNum = self.Matching_set(x, "股") if(strNum != ""): stockNum = float(strNum) lstInd.append(x); continue; for x in lstInd: cmds.remove(x) #提取股票信息 pStocks = gol._Get_Value('setsStock', None) codeID = self.CheckName_set(cmds[0].strip()) codeName = "" if(len(cmds) > 1): codeName = self.CheckName_set(cmds[1].strip()) lstStock = pStocks._Find(codeID, codeName, "***", useFuzzy = False) if(len(lstStock) != 1): lstStock = pStocks._Find(codeName, codeID, "***", useFuzzy = False) if(len(lstStock) != 1): return "股票代码、名称检索结果不唯一,无法操作!" pStock = lstStock[0] code_id = pStock.extype + '.' + pStock.code_id usrID = "@*" + usrInfo.get('groupName', '') if(usrID == "@*"): usrID = usrInfo.get('usrNameNick', '') #纠正风控账户名 usrID_risk = usrID if(usrID_risk == '@*股票监测--自选行情'): usrID_risk = '@*风控监测--股票' if(usrID_risk == '@*股票监测--期权行情'): usrID_risk = '@*风控监测--期权' if(usrID_risk.count('股票监测') == 1): usrID_risk = usrID_risk.replace('股票监测', '风控监测') stockDate = myData_Trans.Tran_ToDatetime_str(None, "%Y-%m-%d") #组装设置请求参数 strUrl = "http://127.0.0.1:8669/zxcAPI/robot" #实际网络地址在阿里云有问题,原因未明 strPath = F'stock/QuoteSetRisk?usrID={usrID_risk}&code_id={code_id}&code_name={pStock.code_name}&dateTag={stockDate}&removeSet=False&stockPrice={stockPrice}&stockNum={stockNum}' #&setInfo=' + "{}" #修改接口执行 pWeb = myWeb_urlLib.myWeb(strUrl, bPrint=False) strReturn = pWeb.Do_API_get(strPath, "zxcAPI-py") jsonRes = myData_Json.Trans_ToJson(strReturn) strReturn = myData.iif(jsonRes['result'], jsonRes['text'], jsonRes['err']) #设置账号风控有效 if(jsonRes['result']): editInfo = {} editInfo["风控监测"] = {'msgUsers': {usrID : "wx,True"}, 'mark' :""} strPath = F'stock/QuoteSet?extype={pStock.extype}&code_id={pStock.code_id}&code_name={pStock.code_name}&editInfo={str(editInfo)}' #+ form.code_name.data #修改接口执行 strReturn2 = pWeb.Do_API_get(strPath, "zxcAPI-py") jsonRes = myData_Json.Trans_ToJson(strReturn2) strReturn = myData.iif(jsonRes['result'], strReturn, jsonRes['err']) myDebug.Debug(strReturn) return strReturn