Exemple #1
0
    def OnHandleMsg(self, msg):
        if (msg == None): return None

        #必须有处理消息存在
        strMsg = msg.get('msg', "")
        if (strMsg != ""):
            #拆分'\n'取行最大
            lines = strMsg.split('\n')
            nLen = 0
            for x in lines:
                nLength = len(x)
                if (nLength > nLen): nLen = nLength
            # nMax = myData.iif(nLen > 15, 40, 32)
            nMax = myData.iif(nLen > 15, 32, 32)

            #尾部标签
            msgTag = msg.get('msgTag', "")
            strTag = "  --zxcRobot(" + msgTag + ")  " + myData_Trans.Tran_ToTime_str(
                None, '%H:%M:%S')
            strTag = strTag.replace("()", "")
            strTag = (nMax - len(strTag)) * " " + strTag
            msg["msg"] = strMsg + "\n" + strTag

            #消息管理器处理消息
            self.usrMMsg.OnHandleMsg(msg)
            return True
        return None
    def Done_Swap_MsgOut(self, msg, isGroup=False):
        if (msg or len(msg) > 1):
            myDebug.Debug("消息接收::", msg['Text'])
            if (str(msg['Text']) == '[]'): return
            if (msg.get('Type', "") == 'System'): return

            #特殊消息处理
            try:
                destPath = ""
                dtTime = myData_Trans.Tran_ToTime_byInt(
                    myData_Trans.To_Int(str(msg.get('CreateTime', 0))))
                msgType = msg['MsgType']
                if (msgType == 3):  # 图片
                    destPath = self.dirPic + "Temps/" + msg.fileName
                    msg.download(destPath)
                    time.sleep(1)
                elif (msgType == 49):  # 文件
                    destPath = self.dirFile + "Temps/" + msg.fileName
                    msg.download(destPath)
                    time.sleep(1)

                #组装消息内容
                wxMsg = self.pMMsg.OnCreatMsg()
                wxMsg['usrID'] = msg['User']['UserName']
                wxMsg['usrName'] = msg['User']['NickName']
                wxMsg['usrNameNick'] = msg['User']['RemarkName']
                wxMsg['groupID'] = myData.iif(isGroup, msg['User']['UserName'],
                                              "")
                if (wxMsg['groupID'] != ""):
                    wxMsg['usrNameNick'] = msg['ActualNickName']
                    if (wxMsg['usrNameNick'] == ""):
                        if (msg['FromUserName'] == self.usrName):
                            wxMsg['usrNameNick'] = self.usrName_Alias
                wxMsg['msgID'] = msg['MsgId']
                wxMsg['msgType'] = msg['Type'].upper()
                wxMsg['msg'] = msg['Text']
                wxMsg['msgContent'] = msg.get('Content', '')
                wxMsg['usrPlat'] = "wx"
                wxMsg['msgTime'] = myData_Trans.Tran_ToTime_str(dtTime)
                if (destPath != ""):
                    wxMsg['msg'] = destPath

                #保存
                if (msgType == 1 or msgType == 10002):
                    if (wxMsg['msg'] != ""):
                        self.swapOut.SwapData_Out(wxMsg)
            except Exception as ex:
                myError.Error(ex)
        return
Exemple #3
0
    def setTime(self):
        self.dtDay = myData_Trans.Tran_ToTime_str(None, "%Y-%m-%d")  #当前天
        self.startTime = myData_Trans.Tran_ToDatetime(self.dtDay +
                                                      " 9:26:30")  #起始时间
        self.endTime = myData_Trans.Tran_ToDatetime(self.dtDay +
                                                    " 11:30:30")  #结束时间
        self.endTime2 = myData_Trans.Tran_ToDatetime(self.dtDay +
                                                     " 15:16:00")  #结束时间--收盘
        self.timeIntervals = 0

        #时间段监测
        tNow = datetime.datetime.now()
        if (tNow.hour > 15):
            self.timeIntervals = 1
        return (self.startTime < tNow and tNow < self.endTime2)
Exemple #4
0
    def _Done_Image(self, Text, msgID="", usrInfo={}):
        #图片判别,只处理手机截图(图片行列比)

        #提取图片内容,ORC通用识别
        #Text = "E:\\myCode\\zxcProj\\src\\Zxc.Python\\zxcPy.All.Base\\Temps\\Images\\Test.png"
        txtInfo = myAI_Baidu.ORC(Text, "", out_debug=False)
        myDebug.Debug(str(txtInfo))

        #按文字内容组合定义图片类型
        dictInfos = {'收益率': "", '日期': ""}
        num = txtInfo['wordText'].count('资产分析')
        if (num >= 1):
            # 使用文字匹配方式解析
            year = myData_Trans.Tran_ToTime_str(None, "%Y")
            if (txtInfo['wordText'].count('同花顺-资产分析') == 1):  #同花顺截图
                #'u中国联通令\n下午3:10\n64%\n同花顺-资产分析\n2019-01-01~2019-08-27\n分享\n本月\n近三月\n近半年\n今年\n近两年\n30.0%\n10.0%\n0.0%\n-10.0%\n01-01\n04-01\n07-01\n我上证○深证○创业板○上证50\nC沪深30中证500收益走势\n今年跑嬴上证指数\n23.03%\n我\n3940%\n上证\n16.37%\n深证\n30.43%\n创业板\n30.19%'
                ind = txtInfo['words'].index('我')
                if (ind > 0):
                    txt = txtInfo['words'][ind + 1]
                    dictInfos['收益率'] = float(txt.replace('%', "")) / 100
                    if (txt.count('.') == 0):
                        dictInfos['收益率'] = dictInfos['收益率'] / 100  #小数点未正确识别修正

                    # 提取日期
                    lst = [n for n in txtInfo['words'] if n.count(year) == 2]
                    if (len(lst) == 1):
                        times = lst[0].split('~')
                        if (times[0][0:10] == year + "-01-01"):  #日期校检,必须当年开始
                            dictInfos['日期'] = myData_Trans.Tran_ToDatetime(
                                times[1], '%Y-%m-%d')
                pass
            else:  #君弘截图
                #'10:09:1l\n(80\n资产分析\n20190101~20190828\n今年收益率17.48%\n今日本月近三个月近半年今年2018\n30%\n20%\n2019.01.31\n我:-0.11\n10%\n上证:3.64%\n10%\n01.31\n03.29\n05.31\n07.31\n●我○上证深证○创业\n1.46%\n跑赢上证\n1.46%\n跑输深证\n-12.56%\n跑输创业\n-12.47%\n资产分析\n证券分析\n月度分析\n账单'
                # 提取今年收益率
                lst = [n for n in txtInfo['words'] if n.count('今年收益率') == 1]
                if (len(lst) == 1):
                    txt = lst[0]
                    dictInfos['收益率'] = float(
                        txt.replace('今年收益率', "").replace('%', "")) / 100
                    if (txt.count('.') == 0):
                        dictInfos['收益率'] = dictInfos['收益率'] / 100  #小数点未正确识别修正

                    # 提取日期
                    lst = [n for n in txtInfo['words'] if n.count(year) == 2]
                    if (len(lst) == 1):
                        times = lst[0].split('~')
                        if (times[0][0:8] == year + "0101"):  #日期校检,必须当年开始
                            dictInfos['日期'] = myData_Trans.Tran_ToDatetime(
                                times[1], '%Y%m%d')
                pass
            if (dictInfos['收益率'] == 0): return ""

            # 修正日期为字符串、收益率格式等
            usrName = usrInfo.get('usrNameNick', "")
            usrProfit = dictInfos['收益率']
            if (dictInfos.get('日期', "") != ""):
                dictInfos['日期-前'] = myData_Trans.Tran_ToDatetime_str(
                    dictInfos['日期'] + datetime.timedelta(days=1), '%Y-%m-%d')
                dictInfos['日期'] = myData_Trans.Tran_ToDatetime_str(
                    dictInfos['日期'], '%Y-%m-%d')
            if (dictInfos.get('收益率', "") != ""):
                dictInfos['收益率'] = str(
                    Decimal((usrProfit * 100)).quantize(Decimal('0.00'))) + "%"

            #记录信息
            pDB = gol._Get_Setting('zxcdbStockReturns')
            lstQuery = pDB.Query("isDel==False && 日期>=" + dictInfos['日期-前'],
                                 "日期", True)
            if (len(lstQuery) > 0): return ""  #必须比已有日期大
            myDebug.Debug(
                pDB.Add_Row(
                    {
                        '用户名': usrName,
                        '收益': usrProfit,
                        '日期': dictInfos['日期']
                    }, True))

            #组装返回
            lstR = pDB.Get_Ranks(usrName, True)
            if (len(lstR) < 1):
                return "@" + usrName + " 收益信息记录失败!当前收益率:" + dictInfos[
                    '收益率'] + "."
            dicRand = lstR[0]
            strRank = " 您的收益排名:第 " + dicRand['ranking'] + ", 收益率:" + dicRand[
                'profit'] + " "
            return "@" + usrName + " " + strRank
        return ""
Exemple #5
0
        nDigit = myData.iif(bIndex, 3, 2)
        strUnit = myData.iif(bIndex, "", "元")
        price = myData.iif(bOpt == False, lstValue[1], lstValue[1] * 10000)
        strMsg = self.name + ":" + str(round(price, nDigit)) + strUnit
           
        #涨跌标识    
        dValue_N = self.priceRiseFall
        strTag0 = myData.iif(dValue_N >=0, "涨", "跌")
        strTag0 = myData.iif(dValue_N ==0, "平", strTag0) 
             
        dRF = dValue_N * 100
        strMsg += ", " + strTag0 + str(round(dRF,2)) + "%."  
        return strMsg

    #输出
    def Print(self):
        myDebug.Debug(self.toString())
        myDebug.Debug(self.toJsonstr())



#主启动程序
if __name__ == "__main__":
    pData = Data_Stock()
    
    pData.name = "建设银行"
    pData.date = myData_Trans.Tran_ToTime_str(None, "%Y-%m-%d")
    pData.time = myData_Trans.Tran_ToTime_str(None, "%H:%M:%S")
    pData.Print()