예제 #1
0
파일: mailfun.py 프로젝트: heart5/everwork
def mailfun(txtorfile, tonotek=False):
    cfpew, cfpewpath = getcfp('everwork')
    host = cfpew.get('gmail', 'host')
    username = cfpew.get('gmail', 'username')
    password = cfpew.get('gmail', 'password')
    # print(f"{username}")
    yag_imap_connecttion = yagmail.SMTP(user=username,
                                        password=password,
                                        host=host)
    mail2lst = re.split('[,,]', getinivaluefromnote('mail', 'mailto'))
    if tonotek:
        mail2lst.append(getinivaluefromnote('mail', 'mailtonote'))
        print(mail2lst)
    subject = str(txtorfile)
    if os.path.exists(subject):
        print(f"{subject}是个文件")
        if subject.endswith('.txt'):
            flhd = open(txtorfile, 'r')
            txtcontent = flhd.read()
            flhd.close()
        else:
            txtcontent = subject
        contents = [txtcontent, str(txtorfile)]
    else:
        contents = [txtorfile]
        subject = txtorfile[:30]
    # print(f"{mail2lst}")
    yag_imap_connecttion.send(mail2lst, subject, contents)
    yag_imap_connecttion.close()
예제 #2
0
def getdelta():
    """
    从网络配置笔记中获取时间间隔(用于判断宕机时间,逻辑上不完全准确,取经验值)
    """
    if (delta := getinivaluefromnote('freemem', getdeviceid())) is not None:
        print(delta)
        delta = [int(x) for x in delta.split(',')]
        deltatime = pd.Timedelta(minutes=delta[0], seconds=delta[1])
예제 #3
0
def showwcsimply(inputdb: pd.DataFrame):
    frdfromdb = inputdb.copy(deep=True)
    # 用nickname填充remarkname为空的记录
    frdfromdb['remarkname'] = frdfromdb[['nickname', 'remarkname']].apply(
        lambda x: x.nickname if x.remarkname == '' else x.remarkname, axis=1)
    # 只保留明白含义的列值
    frdfromdb.drop_duplicates([
        'nickname', 'remarkname', 'contactflag', 'signature', 'starfriend',
        'province', 'city'
    ],
                              keep='first',
                              inplace=True)
    # 找出最近n天内有过更改的联系人清单,n从动态配置文件中获取,不成功则设置-1
    if (wcrecentdays := getinivaluefromnote('webchat', 'wcrecentdays')):
        pass
예제 #4
0
파일: webchat.py 프로젝트: heart5/everwork
def add_friend(msg):
    # 如何不是指定的数据分析中心和主账户,则不打招呼
    thisid = getdeviceid()
    houseid = getinivaluefromnote('webchat', 'datahouse')
    mainaccount = getinivaluefromnote('webchat', 'mainaccount')
    helloword1 = getinivaluefromnote('webchat', 'helloword1')
    helloword2 = getinivaluefromnote('webchat', 'helloword2')
    men_wc = getcfpoptionvalue('everwebchat', get_host_uuid(), 'host_nickname')
    if (thisid != str(houseid) or (men_wc != mainaccount)):
        print(f"不是数据分析中心也不是主账号【{mainaccount}】,不用打招呼哟")
        return
    msg.user.verify()
    msg.user.send(f'Nice to meet you!\n{helloword1}\n{helloword2}')
    writefmmsg2txtandmaybeevernotetoo(msg)
    log.info(msg)
예제 #5
0
파일: webchat.py 프로젝트: heart5/everwork
def showmsgexpanddictetc(msg):
    """
    列印dict中的所有属性和值,对于dict类型的子元素,则再展开一层
    """
    # print(msg)
    for item in msg:
        # print(item)
        # if item.lower().find('name') < 0:
        # continue
        print(f'{item}\t{type(msg[item])}', end='\t')
        if type(msg[item]) in [dict, itchat.storage.templates.Chatroom,
                               itchat.storage.templates.User]:
            print(len(msg[item]))
            for child in msg[item]:
                childmsg = msg[item][child]
                print(f'\t{child}\t{type(childmsg)}', end='\t')
                if type(childmsg) in [dict, itchat.storage.templates.User,
                                      itchat.storage.templates.ContactList]:
                    lenchildmsg = len(childmsg)
                    print(lenchildmsg)
                    lmt = getinivaluefromnote('webchat', 'itemshowinmsg')
                    shownum = lmt if lenchildmsg > lmt else lenchildmsg
                    print(f'\t\t{childmsg[:shownum]}')
                    # print(f'\t\t{childmsg}')
                else:
                    print(f'\t\t{childmsg}')

        else:
            print(msg[item])
예제 #6
0
파일: webchat.py 프로젝트: heart5/everwork
def sharing_reply(msg):
    sendernick = getsendernick(msg)
    innermsg = formatmsg(msg)

    # showmsgexpanddictetc(msg)
    # 处理火界麻将战绩网页
    # http://zj.lgmob.com/h5_whmj_qp/fks0_eb81c193dea882941fe13dfa5be24a11.html
    # ptn = re.compile("h5_whmj_qp/fks0_")
    # http://s0.lgmob.com/h5_whmj_qp/zhanji/index.php?id=fks0_eb81c193dea882941fe13dfa5be24a11
    # ptn = re.compile("h5_whmj_qp/zhanji/index.php\\?id=")
    men_wc = getcfpoptionvalue('everwebchat', get_host_uuid(), 'host_nickname')
    msgurl = msg['Url']
    print(msgurl)
    if (ulst := splitmjurlfromtext(msgurl)) and (len(ulst) > 0):
        if getinivaluefromnote("game", "forceupdateexcel"):
            descstr = ''
            for sp in ulst:
                tmpurl, tmpdescstr = geturlcontentwrite2excel(men_wc, sp)
                descstr += tmpdescstr
        else:
            descstr = updateurllst(men_wc, ulst)
        outstr = f"【Text】信息中发现新的火界麻将战绩网页链接并处理:\t{descstr}"
        itchat.send_msg(f'({sendernick})' + outstr)
        makemsg2write(innermsg, outstr)
        makemsg2write(innermsg, msgurl)
예제 #7
0
    def with_logging(*args, **kwargs):
        if getinivaluefromnote('everwork', 'logdetails'):
            log.info(f'{func.__name__}函数被调用,参数列表:{args}')
        else:
            print(f'{func.__name__}函数被调用,参数列表:{args}')

        return func(*args, **kwargs)
예제 #8
0
def updateurl2excelandini(ownername, url):
    """
    处理url,提取网页内容,有效数据写入数据文件,并更新相应配套ini辅助文件
    """
    #     ptn = re.compile("(http://.+?h5_whmj_qp/(?:zhanji/index.php\\?id=|fks0_)\S+)\s*")
    ptn = getinivaluefromnote('game', 'ptn')
    if (urlst := re.findall(ptn, url)):
        url = urlst[0]
예제 #9
0
def checkptn():
    #     ptnstr = "(http://.+?tcloudbaseapp.com/port.html\?j=\S+)\s*"

    ptnstr = getinivaluefromnote('game', 'ptn')
    ptnstr
    ptn = re.compile(ptnstr)
    ptn
    teststr = "(http://cloud1.tcloudbaseapp.com/port.html?j=afjoajoa)"
    re.findall(ptn, teststr)
예제 #10
0
파일: webchat.py 프로젝트: heart5/everwork
def formatmsg(msg):
    """
    格式化并重构msg,获取合适用于直观显示的用户名,对公众号和群消息特别处置
    """
    timetuple = time.localtime(msg['CreateTime'])
    timestr = time.strftime("%Y-%m-%d %H:%M:%S", timetuple)
    # print(msg['CreateTime'], timetuple, timestr)
    men_wc = getcfpoptionvalue('everwebchat', get_host_uuid(), 'host_nickname')
    # 信息延时登记入专门数据库文件
    dbname = touchfilepath2depth(getdirmain() / "data" / "db" /
                                 f"wcdelay_{men_wc}.db")
    inserttimeitem2db(dbname, msg['CreateTime'])
    # owner = itchat.web_init()
    meu_wc = getcfpoptionvalue('everwebchat', get_host_uuid(), 'host_username')
    send = (msg['FromUserName'] == meu_wc)
    if 'NickName' in msg["User"].keys():
        showname = msg['User']['NickName']
        if len(msg['User']['RemarkName']) > 0:
            showname = msg['User']['RemarkName']
    elif 'UserName' in msg['User'].keys():
        showname = msg['User']['UserName']
    elif 'userName' in msg['User'].keys():
        showname = msg['User']['userName']
    else:
        showname = ""
        log.warning(f"NickName或者UserName或者userName键值不存在哦")
        showmsgexpanddictetc(msg)

    # 过滤掉已经研究过属性公众号信息,对于尚未研究过的显示详细信息
    ignoredmplist = getinivaluefromnote('webchat', 'ignoredmplist')
    imlst = re.split('[,,]', ignoredmplist)
    ismp = type(msg['User']) == itchat.storage.MassivePlatform
    if ismp and (showname not in imlst):
        showmsgexpanddictetc(msg)
        # print(f"{showname}\t{imlst}")

    # 处理群消息
    if type(msg['User']) == itchat.storage.templates.Chatroom:
        isfrom = msg['FromUserName'].startswith('@@')
        isto = msg['ToUserName'].startswith('@@')
        # qunmp = isfrom or isto
        # showmsgexpanddictetc(msg)
        if isfrom:
            # print(f"(群)\t{msg['ActualNickName']}", end='')
            showname += f"(群){msg['ActualNickName']}"
        elif isto:
            # print(f"(群)\t{msg['User']['Self']['NickName']}", end='')
            showname += f"(群){msg['User']['Self']['NickName']}"
        # print(f"\t{msg['Type']}\t{msg['MsgType']}\t{msg['Text']}")
        # print(f"\t{send}\t{msg['Type']}\t{msg['Text']}")
    fmtext = msg['Text']

    finnalmsg = {'fmId': msg['MsgId'], 'fmTime': timestr, 'fmSend': send,
                 'fmSender': showname, 'fmType': msg['Type'], 'fmText': fmtext}

    return finnalmsg
예제 #11
0
def finance2note(srccount, rstdf, mingmu, mingmu4ini, title):
    print(f"df索引名称为:{rstdf.index.name}")
    noteguid = getinivaluefromnote('webchat', mingmu)
    count_zdzz = getcfpoptionvalue('everwebchat', 'finance', mingmu4ini)
    if not count_zdzz:
        count_zdzz = 0
    # print(f"{count_zdzz}")

    rstdf.fillna('None', inplace=True)
    colstr = f'{rstdf.index.name}\t' + '\t'.join(list(rstdf.columns)) + '\n'
    itemstr = colstr
    for idx in rstdf.index:
        itemstr += str(idx) + '\t' + '\t'.join(rstdf.loc[idx]) + '\n'
    # print(f"{itemstr}")
    notecontent = "<pre>" + itemstr + "</pre>"
    finance2note4debug = getinivaluefromnote('webchat', 'finance2note4debug')
    # print(f"{type(finance2note4debug)}\t{finance2note4debug}")
    if (srccount != count_zdzz) or finance2note4debug:  # or True:
        imglist2note(get_notestore(), [], noteguid, title, notecontent)
        setcfpoptionvalue('everwebchat', 'finance', mingmu4ini, f"{srccount}")
        log.info(f"成功更新《{title}》,记录共有{rstdf.shape[0]}条")
예제 #12
0
파일: pdtools.py 프로젝트: heart5/everwork
def lststr2img(inputcontent,
               fontpath=dirmainpath / 'font' / 'msyh.ttf',
               title=None,
               showincell=False,
               fontsize=12,
               dpi=300,
               debug=False):
    if type(inputcontent) == str:
        dflines = inputcontent.split('\n')
    elif type(inputcontent) == list:
        dflines = inputcontent
    else:
        logstr = f"传入参数类型为:\t{type(inputcontent)},既不是str也不是list,暂不做处理返回None"
        log.critical(logstr)
        return

    rows = len(dflines)
    collenmax = max([len(x) for x in dflines])
    print(f"行数和行最长长度(字符):\t{(rows, collenmax)}")
    font = ImageFont.truetype(str(fontpath), fontsize)
    print(str(fontpath))
    colwidthmax = max([font.getsize(x)[0] for x in dflines])
    rowwidth = max([font.getsize(x)[1] for x in dflines])
    print(
        f"行高度、所有行总高度和所有列宽度(像素):\t{(rowwidth, rowwidth * len(dflines), colwidthmax)}"
    )

    print(f"画布宽高(像素):\t{(colwidthmax, rowwidth * len(dflines))}")
    im = Image.new("RGB", (colwidthmax, rowwidth * len(dflines)),
                   (255, 255, 255))
    dr = ImageDraw.Draw(im)

    i = 0
    for line in dflines:
        dr.text((0, 0 + rowwidth * i), line, font=font, fill="#000000")
        i += 1

    if not debug:
        if (notedpi := getinivaluefromnote('webchat', 'imgdpi')):
            dpi = notedpi
예제 #13
0
파일: webchat.py 프로젝트: heart5/everwork
def text_reply(msg):
    sendernick = getsendernick(msg)
    innermsg = formatmsg(msg)
    soup, items = soupclean2item(msg['Content'])

    # 是否在清单中
    mp4txtlist = re.split('[,,]', getinivaluefromnote('webchat', 'mp4txtlist'))
    cleansender = re.split("\\(群\\)", innermsg['fmSender'])[0]
    if cleansender in mp4txtlist:
        itemstr = '\n'
        for item in items:
            itemstr += item.title.string + '\n'
        # 去掉尾行的回车
        itemstr = itemstr[:-1]
        innermsg['fmText'] = itemstr

    writefmmsg2txtandmaybeevernotetoo(innermsg)

    # 特定指令则退出
    if msg['Text'] == '退出小元宝系统':
        log.info(f"根据指令退出小元宝系统")
        itchat.logout()

    # 处理火界麻将战绩网页
    men_wc = getcfpoptionvalue('everwebchat', get_host_uuid(), 'host_nickname')
#     ptn = re.compile("h5_whmj_qp/(zhanji/index.php\\?id=|fks0_)")
    msgtxt = msg['Text']
    if (ulst := splitmjurlfromtext(msgtxt)) and (len(ulst) > 0):
        if getinivaluefromnote("game", "forceupdateexcel"):
            descstr = ''
            for sp in ulst:
                tmpurl, tmpdescstr = geturlcontentwrite2excel(men_wc, sp)
                descstr += tmpdescstr
        else:
            descstr = updateurllst(men_wc, ulst)
        outstr = f"【Text】信息中发现新的火界麻将战绩网页链接并处理:\t{descstr}"
        # log.info(outstr)
        itchat.send_msg(sendernick + outstr)
        makemsg2write(innermsg, outstr)
        makemsg2write(innermsg, msgtxt)
예제 #14
0
def pinpaifenxido():
    cnx = lite.connect(dbpathquandan)
    dataokay(cnx)
    readinifromnote()
    namestr = 'brand'
    cfpininote, cfpininotepath = getcfp('everinifromnote')
    if cfpininote.has_option(namestr, 'brandcount'):
        brandcount = cfpininote.getint(namestr, 'brandcount')
    else:
        brandcount = 5
    fenbuorquyu = getinivaluefromnote('brand', 'fenbuorquyu')
    pinpaifenxi(cnx, daysbefore=5, brandnum=brandcount, fenbu=fenbuorquyu)
    cnx.close()
예제 #15
0
def chuliquandan():
    """
    处理全单文件
    """
    workpath = dirmainpath / 'data/work'
    khqdnamelst = [x for x in os.listdir(workpath) if x.find('全单统计管理') >= 0]
    # print(khqdnamelst)
    # 对获取的合格文件根据时间进行排序,升序
    khqdnamelst.sort(key=lambda fn: os.path.getmtime(workpath / fn))
    newestonlyname = khqdnamelst[-1]
    newestfn = workpath / newestonlyname
    targetfn = dirmainpath / 'data' / '全单统计管理最新.xlsm'
    cfpdata, cfpdatapath = getcfp('everdata')
    if not cfpdata.has_section('dataraw'):
        cfpdata.add_section('dataraw')
        cfpdata.write(open(cfpdatapath, 'w', encoding='utf-8'))
    if not cfpdata.has_option('dataraw', 'quandannewestname'):
        cfpdata.set('dataraw', 'quandannewestname', '')
        cfpdata.write(open(cfpdatapath, 'w', encoding='utf-8'))
    if cfpdata.get('dataraw', 'quandannewestname') != newestonlyname:
        shutil.copy(newestfn, targetfn)
        cfpdata.set('dataraw', 'quandannewestname', newestonlyname)
        cfpdata.write(open(cfpdatapath, 'w', encoding='utf-8'))
        log.info(f"《全单统计管理》有新文件:{newestonlyname}")
    cnx = lite.connect(dbpathquandan)
    if gengxinfou(targetfn, cnx, 'fileread'):  # or True:
        # workbook = xlrd.open_workbook(targetfn, encoding_override="cp936")
        # workbook = xlrd.open_workbook(targetfn)
        # sheet = workbook.sheet_by_name('全单统计管理')
        # # sheet的名称,行数,列数
        # print (sheet.name,sheet.nrows,sheet.ncols)
        # datafromsheet = [sheet.row_values(i, 0 ,sheet.ncols) for i in
        # range(0, sheet.nrows)]
        # # print(datafromsheet[:5])
        # df = pd.DataFrame(datafromsheet[1:], columns=datafromsheet[0])
        # df = df.loc[:, ['往来单位全名', '往来单位编号', '联系人', '联系电话', '地址']]
        df = pd.read_excel(targetfn,
                           sheet_name='全单统计管理',
                           parse_dates=['订单日期', '送达日期', '收款日期'])
        print(df)
        itemnumberfromnote = getinivaluefromnote('datasource',
                                                 'randomnumber4customer')
        itemnunber2show = len(
            df) if len(df) < itemnumberfromnote else itemnumberfromnote
        print(df.loc[random.sample(range(0, len(df)), itemnunber2show), :])
        df.to_sql(name='quandantjgl', con=cnx, if_exists='replace')
        log.info(f"写入{len(df)}条记录到quandantjgl数据表中")
        # read_excel()对于无指定编码的excel文件读取时一直无法解决编码的问题
        # df = pd.read_excel(targetfn, encoding='cp936')
        # print(df)
    cnx.close()
예제 #16
0
def getresult(resultdf, prefix, args):
    number2showinapp = getinivaluefromnote('datasource', 'number2showinapp')
    if resultdf.shape[0] > number2showinapp:
        excelwriter = pd.ExcelWriter(validfilename(prefix, args))
        ixmaxcount = 0
        for ix in set(resultdf.index):
            ixcount = resultdf.loc[ix].shape[0]
            # print(f"{ix}\t{ixcount}")
            if ixcount > ixmaxcount:
                ixmaxcount = ixcount
        print(f"最大条目数为:{ixmaxcount}")
        maxcount2split = getinivaluefromnote('webchat', 'maxcount2split')
        if ixmaxcount > maxcount2split:
            for ix in set(resultdf.index):
                df2sheet = resultdf.loc[ix]
                if type(df2sheet) == pd.core.series.Series:
                    # 复制结构相同的DataFrame,并追加数据(类型是Series)
                    dftmp = pd.DataFrame(columns=resultdf.columns)
                    df2sheet = dftmp.append(df2sheet)
                    # print(f"{df2sheet}")
                df2sheet.to_excel(excelwriter,
                                  sheet_name=str(ix).replace('*', '').strip(),
                                  index=False)
        else:
            resultdf.to_excel(excelwriter)
        excelwriter.save()
        rdffile = os.path.abspath(excelwriter)
        rdfstr = resultdf[:number2showinapp].to_string(
        ) + f"\n...\n共有{resultdf.shape[0]}条结果,更多信息请查看表格附件"
    else:
        rdffile = None
        if resultdf.shape[0] == 0:
            rdfstr = '没有符合条件的查询结果'
        else:
            rdfstr = f"找到{resultdf.shape[0]}条记录\n" + resultdf.to_string()

    return rdffile, rdfstr
예제 #17
0
파일: chuqin.py 프로젝트: heart5/everwork
def zonghetongji():
    qdlst = chuqinjiluzhengli()
    # print(qdlst)
    biaoti = qdlst[-1][0]
    print(biaoti)
    jilusdf = qdlst[-1][4]
    ptnsep = re.compile('[,,]')
    jslst = re.split(ptnsep, getinivaluefromnote('xingzheng', '计时工'))
    xzlst = re.split(ptnsep, getinivaluefromnote('xingzheng', '行政岗位'))
    for name in jilusdf.columns:
        if name in jslst:
            chugongtianshu: int
            fenzhongleiji: int
            gongshi: int
            chugongtianshu, fenzhongleiji, gongshi = tongjichuqinjishigong(
                jilusdf[name])
            print(f"计时工\t{name}\t{chugongtianshu}\t{fenzhongleiji}\t{gongshi}")
        elif name in xzlst:
            tongjichuqinixingzheng(jilusdf[name])
            print(f"行政岗位\t{name}")
        else:
            print(f"正常岗位\t{name}")
    # print(qdlst)
    return jilusdf
예제 #18
0
    def wrapper(*args, **kwargs):
        start = time.time()
        result = func(*args, **kwargs)
        end = time.time()
        timelen = end - start
        if timelen >= (60 * 60):
            timelenstr = f'{int(timelen / (60 * 60))}小时{int((timelen % (60*60)) / 60)}分钟{timelen % (60*60) % 60:.2f}秒'
        elif timelen >= 60:
            timelenstr = f'{int(timelen / 60)}分钟{timelen % 60:.2f}秒'
        else:
            timelenstr = f'{timelen % 60:.2f}秒'
        if getinivaluefromnote('everwork', 'logdetails'):
            log.info(f"{func.__name__}\t{timelenstr}")
        else:
            print(f"{func.__name__}\t{timelenstr}")

        return result
예제 #19
0
def splitmjurlfromtext(incontent: str):
    """
    从输入文本中提取有效的url链接,返回包含有效链接的list
    **正则中的贪婪和非贪婪搞得一头包,慎之慎之**
    """
    # http://s0.lgmob.com/h5_whmj_qp/zhanji/index.php?id=fks0_eb81c193dea882941fe13dfa5be24a11
    # ptn = re.compile("h5_whmj_qp/zhanji/index.php\\?id=")
    #  '微信【Text】信息中发现新的火界麻将战绩网页链接并处理,房间号为:\t806666\thttp://s0.lgmob.com/h5_whmj_qp/zhanji/index.php?id=fks0_9b8bd588d1d44ae2867aa1319241881b'
    # ptn = re.compile("h5_whmj_qp/(zhanji/index.php\\?id=|fks0_)")
    # reg .+? 限制为非贪婪模式,用于提取文本多个有效连接
    #     ptn = re.compile("(http://.+?h5_whmj_qp/(?:zhanji/index.php\\?id=|fks0_)\S+)\s*")
    ptnfromnote = getinivaluefromnote('game', 'ptn')
    ptn = re.compile("r" + f"{ptnfromnote}")
    # rstlst = [inurl for inurl in vurl if (vurl := re.findall(ptn, incontent))]
    if (vurl := re.findall(ptn, incontent)):
        print(ptn)
        print(incontent)
        return [url for url in vurl]
예제 #20
0
def log2note(noteguid, loglimit, levelstr='', notetitle='everwork日志信息'):
    namestr = 'everlog'

    if levelstr == 'CRITICAL':
        levelstrinner = levelstr + ':'
        levelstr4title = '严重错误'
        countnameinini = 'everlogcc'
    else:
        levelstrinner = levelstr
        levelstr4title = ''
        countnameinini = 'everlogc'

    # log.info(getdirmain())
    pathlog = getdirmain() / 'log'
    files = os.listdir(str(pathlog))
    loglines = []
    for fname in files[::-1]:
        # log.info(fname)
        if not fname.startswith('everwork.log'):
            log.warning(f'文件《{fname}》不是合法的日志文件,跳过。')
            continue
        with open(pathlog / fname, 'r', encoding='utf-8') as flog:
            charsnum2showinline = getinivaluefromnote('everlog',
                                                      'charsnum2showinline')
            # print(f"log行最大显示字符数量为:\t{charsnum2showinline}")
            loglines = loglines + [line.strip()[:charsnum2showinline]
                                   for line in flog if line.find(levelstrinner) >= 0]

    ptn = re.compile('\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}')
    tmlst = [pd.to_datetime(re.match(ptn, x).group())
             for x in loglines if re.match(ptn, x)]
    loglines = [x for x in loglines if re.match(ptn, x)]
    logsr = pd.Series(loglines, index=tmlst)
    logsr = logsr.sort_index()
    # print(logsr.index)
    # print(logsr)
    loglines = list(logsr)
    # log.info(loglines[:20])
    # print(len(loglines))
    print(f'日志的{levelstr4title}记录共有{len(loglines)}条,只取时间最近的{loglimit}条')
    if not (everlogc := getcfpoptionvalue(namestr, namestr, countnameinini)):
        everlogc = 0
예제 #21
0
파일: webchat.py 프로젝트: heart5/everwork
def newchatnote():
    """
    构建新的聊天记录笔记(置于笔记本《notification》中)并返回
    """
    note_store = get_notestore()
    # parentnotebook = \
    # note_store.getNotebook('4524187f-c131-4d7d-b6cc-a1af20474a7f')
    parentnotebook = \
        note_store.getNotebook(getinivaluefromnote(
            'notebookguid', 'notification'))
    evernoteapijiayi()
    note = ttypes.Note()
    note.title = f"微信({getowner()['User']['NickName']})记录:" \
                 f"{time.strftime('%Y-%m-%d_%H:%M:%S', time.localtime(time.time()))}"
    print(note.title)
    token = getcfpoptionvalue('everwork', 'evernote', 'token')
    notechat = makenote(token, note_store, note.title, notebody='',
                        parentnotebook=parentnotebook)

    return notechat
예제 #22
0
파일: pystudy.py 프로젝트: heart5/everwork
       'address':'shanghai'}
 
# 将字典的key转换成列表
lst = list(dit)
print(lst)  # ['name', 'age', 'gender', 'address']
 
# 将字典的value转换成列表
lst2 = list(dit.values())
print(lst2)
# -
# ### 列印字典中的值

# 显示所有key和value
for key, value in dit.items():
    print(key, type(value), value)

print("Home is hopeful.")

# ## configparse


# option name是支持包含空格的字符串的

import pathmagic
with pathmagic.context():
    from func.logme import log
    from func.evernttest import getinivaluefromnote
getinivaluefromnote('game', 'alles gut')


예제 #23
0
def findnewthenupdatenote(qrfile: str,
                          cfpfile,
                          cfpsection,
                          pre,
                          desc,
                          sendmail=False,
                          sendsms=False):
    """
    发现文件内容更新就更新至相应笔记,并视情况发送短信提醒

    :param qrfile: 文件名称
    :param cfpfile: 配置文件名称
    :param cfpsection: 配置文件中所属片段名称
    :param pre: 前缀名,用于区分不同的项目
    :param desc: 项目描述
    :param sendsms: 是否同时发送短信进行提醒的开关
    :return:
    """
    qrfile = os.path.abspath(qrfile)
    if os.path.exists(qrfile):
        # print(qrfile)
        # print(os.path.abspath(qrfile))
        qrfiletimeini = getcfpoptionvalue(cfpfile, cfpsection,
                                          f'{pre}filetime')
        # print(qrfiletimeini)
        qrfilesecsnew = os.stat(qrfile).st_mtime
        qrfiletimenew = str(qrfilesecsnew)
        if (qrfiletimeini :=
                getcfpoptionvalue(cfpfile, cfpsection,
                                  f'{pre}filetime')) is not None:  # or True:
            qrftlst = str(qrfiletimeini).split(
                ',')  # 挂一道是为了确保单一数值时getcfpoptionvalue返回的float转换为str方便split
            print(
                f"{timestamp2str(qrfilesecsnew)}\t{timestamp2str(float(qrftlst[0]))}\t{qrfile}"
            )
            if (qrfiletimenew > qrftlst[0]):  # or True:
                qrtstr = f"{qrfiletimenew},{qrfiletimeini}"
                qrtstrlst = [x for x in qrtstr.split(',') if len(x) != 0]
                qrtstrflst = [timestamp2str(float(x)) for x in qrtstrlst][:30]
                (*full, ext) = getfilepathnameext(qrfile)
                print(full)
                print(ext)
                ext = ext.lower()  # 文件扩展名强制小写,缩小判断目标池
                targetimglst = [qrfile]
                filecontent = str(qrfile)
                if ext in ['.png', '.jpg', 'bmp', 'gif']:
                    targetstr = f'<pre>--------------\n' + '\n'.join(
                        qrtstrflst) + '</pre>'
                elif ext in ['.log']:
                    filecontentinlog = open(
                        qrfile, 'r',
                        encoding='utf-8').read()  # 指定编码,解决Windows系统下的编码问题
                    # print(filecontent)
                    ptn = re.compile(
                        "(\\d{4}-\\d{2}-\\d{2}\\s\\d{2}:\\d{2}:\\d{2},\\d{3})\\s",
                        re.DOTALL)
                    # findptnlst = re.findall(ptn, filecontent)
                    findptnlst = re.split(ptn, filecontentinlog)[::-1]  # 倒置
                    findptnlstcount = int((len(findptnlst) - 1) / 2)
                    loglimit = getinivaluefromnote('everlog', 'loglimit')
                    if loglimit > findptnlstcount:
                        actuallinesnum = findptnlstcount
                    else:
                        actuallinesnum = loglimit
                    findptnlst.insert(
                        0,
                        f"共有{findptnlstcount}行,实际展示最近时间的{actuallinesnum}行\n")
                    filecontent = '\n'.join(findptnlst[:(actuallinesnum * 2 + 1)]).replace('<', '《')\
                        .replace('>', '》').replace('=', '等于').replace('&', '并或')
                    filecontent = re.sub('<', '《', filecontent)
                    if len(filecontent) > 500000:
                        filecontent = filecontent[:500000] + "\n\n\n太长了,切成500k\n\n\n"
                    targetstr = f'<pre>{filecontent}</pre><pre>--------------\n' + '\n'.join(
                        qrtstrflst) + '</pre>'
                else:
                    filecontent = open(qrfile, 'rb').read()
                    targetstr = f'<pre>--------------\n' + '\n'.join(
                        qrtstrflst) + '</pre>'

                if (qrnoteguid := getinivaluefromnote(
                        cfpsection, f"{pre}{getdeviceid()}")) is not None:
                    # print(qrnoteguid)
                    # print(targetstr)
                    imglist2note(
                        note_store, targetimglst, qrnoteguid,
                        f"{getinivaluefromnote('device', getdeviceid())} {desc}",
                        targetstr)
                else:
                    log.critical(f"{pre}{getdeviceid()}在云端笔记配置文件中未设置,退出!")
                    return
                if sendmail:
                    mailfun(qrfile)
                if sendsms:
                    termux_sms_send(f"{desc}\t有新的更新,请尽快处置。")
                setcfpoptionvalue(cfpfile, cfpsection, f'{pre}filetime',
                                  qrtstr)
예제 #24
0
 numlimit = 9  # 显示项目数
 print(itemread[:numlimit])
 itemsrc = [x.split('\t') for x in itemread if not 'False' in x]
 itemnotfine = [x for x in itemsrc if len(x) < 3]
 print(f"有问题的数据共有{len(itemnotfine)}行:{itemnotfine}")
 #     itemfine = [x for x in itemsrc if len(x) >= 3][:10000]
 itemfine = [x for x in itemsrc if len(x) >= 3]
 # print(itemfine)
 if len(itemfine) < 2:
     print('gps数据量不足,暂时无法输出移动距离信息')
     return
 timesr = list()
 dissr = list()
 outlst = list()
 # speedsr = list()
 highspeed = getinivaluefromnote('life', 'highspeed')
 print(f"{highspeed}\t{type(highspeed)}")
 for i in range(len(itemfine) - 1):
     time1, lat1, lng1, alt1, *others, pro1 = itemfine[i]
     time2, lat2, lng2, alt2, *others, pro2 = itemfine[i + 1]
     # print(f'{lng1}\t{lat1}\t\t{lng2}\t{lat2}')
     dis = round(
         geodistance(eval(lng1), eval(lat1), eval(lng2), eval(lat2)) / 1000,
         3)
     #         dis = round(geodistance(eval(lng1), eval(lat1), eval(lng2), eval(lat2)), 3)
     try:
         itemtime = pd.to_datetime(time1)
         itemtimeend = pd.to_datetime(time2)
         timedelta = itemtime - itemtimeend
     except Exception as eep:
         log.critical(
예제 #25
0
def caiwu2note(itemname, itemnameini, rstdf, clnameswithindex):
    print(f"<{itemname}>数据文本有效条目数:{rstdf.shape[0]}")
    shoukuanfixguid = getinivaluefromnote('webchat', f'{itemname}补')
    fixdf = getfix4finance(shoukuanfixguid, clnameswithindex)
    print(f"<{itemname}>修正笔记有效条目数:{fixdf.shape[0]}")
    alldf = rstdf.append(fixdf)
    bcount = alldf.shape[0]
    # 索引去重
    alldf = alldf[~alldf.index.duplicated()]
    acount = alldf.shape[0]
    print(f"{bcount}\t{acount}")
    alldf.sort_index(ascending=False, inplace=True)
    # print(alldf)
    print(f"<{itemname}>综合有效条目数:{alldf.shape[0]}")

    finance2note(alldf.shape[0], alldf, f'{itemname}', f"{itemnameini}",
                 f'{itemname}记录')

    alldf['time'] = alldf.index
    alldf['date'] = alldf['time'].apply(
        lambda x: pd.to_datetime(x).strftime('%F'))
    alldf['amount'] = alldf['amount'].astype(float)
    agg_map = {'daycount': 'count', 'amount': 'sum'}
    alldfgrpagg = alldf.groupby('date', as_index=False).agg(agg_map)
    alldfgrpagg.columns = ['date', 'lcount', 'lsum']
    alldf.drop_duplicates(['date'], keep='first', inplace=True)
    finaldf = pd.merge(alldf, alldfgrpagg, how='outer', on=['date'])
    alldf = finaldf.loc[:, ['date', 'lcount', 'daycount', 'daysum', 'lsum']]
    # 日期,记录项目计数,记录项目最高值,记录项目累计值,记录项目求和
    alldf.columns = ['date', 'lc', 'lh', 'lacc', 'lsum']
    shoukuanrihuizongguid = getinivaluefromnote('webchat', f'{itemname}总手动')
    rhzdengjidf = getfix4finance(shoukuanrihuizongguid,
                                 ['date', 'count', 'sum'])
    duibidf = pd.merge(alldf, rhzdengjidf, how='outer', on=['date'])

    # 判断覆盖天数是否需要更新
    itemslcsum = duibidf['lc'].sum()
    print(f"<{itemname}>记录条目数量:{itemslcsum}")
    itemslcsumini = getcfpoptionvalue('everwebchat', 'finance',
                                      f'{itemname}lcsum')
    print(f"<{itemname}>记录数量(ini)\t{itemslcsumini}")
    if not itemslcsumini:
        itemslcsumini = 0
    if itemslcsumini == itemslcsum:  # and False:
        print(f"<{itemname}>收款记录数量无变化")
        return

    duibidf.set_index('date', inplace=True)
    duibidf.sort_index(ascending=False, inplace=True)
    col_names = list(duibidf.columns)
    col_names.append('check')
    duibidf = duibidf.reindex(columns=col_names)
    # 通过0的填充保证各列数据可以运算
    duibidf.fillna(0, inplace=True)
    duibidf['lacc'] = duibidf['lacc'].astype(float)
    duibidf['sum'] = duibidf['sum'].astype(float)
    duibidf['count'] = duibidf['count'].astype(int, errors='ignore')
    # print(duibidf.dtypes)
    duibidf['check'] = duibidf['lc'] - duibidf['count']
    duibidf['check'] = duibidf['check'].apply(lambda x: '待核正'
                                              if (x != 0) else '')
    duibiguid = getinivaluefromnote('webchat', f'{itemname}核对')
    title = f'{itemname}核对'
    notecontent = tablehtml2evernote(duibidf, title)
    imglist2note(get_notestore(), [], duibiguid, title, notecontent)
    setcfpoptionvalue('everwebchat', 'finance', f'{itemname}lcsum',
                      f"{itemslcsum}")
예제 #26
0
# + {"pycharm": {"is_executing": false}}
def tongjichuqinixingzheng():
    pass


# -

qslst = chuqinjiluzhengli()

print(len(qslst))
for cqyue in qslst:
    title, date, number, yuangongdf, chuqindf = tuple(cqyue)
    print(title, date, number)
    ptsep = re.compile('[,, ]')
    jslst = re.split(ptsep, getinivaluefromnote('xingzheng', '计时工'))
    xzlst = re.split(ptsep, getinivaluefromnote('xingzheng', '行政岗位'))
    for name in chuqindf.columns:
        if name in jslst:
            chugongtianshu, fenzhongleiji, gongshi = tongjichuqinjishigong(chuqindf[name])
            print(f"计时工\t{name}\t{chugongtianshu}\t{fenzhongleiji}\t{gongshi}")
        elif name in xzlst:
            print(f"行政岗位\t{name}")
        else:
            print(f"正常岗位\t{name}")


log.info(f"this a just a show")


예제 #27
0
def showjinzhang(indf):
    # dfgpc = indf.groupby(['name']).count()
    sdzzdf = indf[indf.content.str.contains(
        '^收到转账')].loc[:, ['time', 'send', 'name', 'content']]
    sdzzdfclnames = list(sdzzdf.columns)
    sdzzdfclnames.append('namecontent')
    sdzzdf = sdzzdf.reindex(columns=sdzzdfclnames)
    sdzzdf['namecontent'] = sdzzdf[['name', 'content']].apply(
        lambda x: x['name'] + x['content'], axis=1)
    zzdf = sdzzdf.loc[:, ['time', 'send', 'namecontent']]
    zzdf.set_index('namecontent', inplace=True)
    # print(sdzzdf)
    print(f"{zzdf.dtypes}")
    ixlst = list(set(zzdf.index))
    # print(f"{ixlst}")
    rstlst = []
    for ix in ixlst:
        item = []
        if type(zzdf.loc[ix]) == pd.core.series.Series:
            item.append(ix)
            item.append(zzdf.loc[ix]['time'])
            item.append(zzdf.loc[ix]['send'])
            rstlst.append(item)
            # print(f"{item}")
            continue
        if type(zzdf.loc[ix]) == pd.core.frame.DataFrame:
            mf = zzdf.loc[ix].sort_values(['time']).reset_index(drop=True)
            # print(f"{ix}\t{mf.shape[0]}\t{mf}")
            # 指针滚动,处理项目相同的各条记录
            ii = 0
            while ii < mf.shape[0]:
                item = []
                item.append(ix)
                item.append(mf.loc[ii]['time'])
                item.append(mf.loc[ii]['send'])
                if ii + 1 == mf.shape[0]:
                    rstlst.append(item)
                    # print(f"{item}")
                    # print(f"循环到头了,添加走人")
                    break
                if mf.loc[ii, 'send'] == mf.loc[ii + 1, 'send']:
                    rstlst.append(item)
                    # print(f"{item}")
                    # print(f"没有配对的,添加继续循环")
                    ii += 1
                    break
                else:
                    item.append(mf.loc[ii + 1]['time'])
                    rstlst.append(item)
                    # print(f"{item}")
                    ii += 2

    # print(f"{rstlst}")
    dddf = pd.DataFrame(rstlst,
                        columns=['namecontent', 'stime', 'send', 'etime'])
    dddf['stime'] = pd.to_datetime(dddf['stime'])
    # dddf['etime'] = pd.to_datetime(dddf['etime'])
    dddf.sort_values('stime', ascending=False, inplace=True)
    dddfclnames = list(dddf.columns)
    dddfclnames.append('name')
    dddfclnames.append('amount')
    dddfclnames.append('memo')
    dddf = dddf.reindex(columns=dddfclnames)
    dddf['name'] = dddf.namecontent.apply(lambda x: re.split('收到转账', x)[0])
    dddf['amount'] = dddf.namecontent.apply(
        lambda x: re.findall('([0-9]+\.[0-9]{2})', x)[0])
    dddf['memo'] = dddf.namecontent.apply(
        lambda x: re.findall('\[(.*)\]', x)[0])
    dddf.set_index('stime', inplace=True)
    clnameswithindex = ['stime', 'name', 'amount', 'send', 'memo', 'etime']
    rstdf = dddf.loc[:, clnameswithindex[1:]]
    # print(rstdf.dtypes)
    print(f"数据文本有效条目数:{rstdf.shape[0]}")
    jinzhangfixguid = getinivaluefromnote('webchat', '收到转账补')
    fixdf = getfix4finance(jinzhangfixguid, clnameswithindex)
    fixdf['stime'] = pd.to_datetime(fixdf.index)
    fixdf.set_index('stime', inplace=True)
    # fixdf['etime'] = pd.to_datetime(fixdf['etime'])
    # print(fixdf.dtypes)
    print(f"修正笔记有效条目数:{fixdf.shape[0]}")
    alldf = rstdf.append(fixdf)
    # alldf['etime'] = alldf['etime'].apply(lambda x: x.strftime('%F %T') if x!=pd.NaT else x)
    alldf.sort_index(ascending=False, inplace=True)
    # print(alldf)
    print(f"综合有效条目数:{alldf.shape[0]}")

    finance2note(alldf.shape[0], alldf, '收到转账全部', 'zdzz', '微信个人转账(全部)收款记录')

    secretstrfromini = getinivaluefromnote('webchat', 'secret')
    # print(f"{secretstrfromini}")
    secretlst = re.split('[,,]', secretstrfromini)
    # print(f"{secretlst}")
    rst4workdf = alldf[~alldf.name.isin(secretlst)]
    # print(f"{rst4workdf}")
    rstdf = rst4workdf.loc[:, :]
    # print(f"{rstdf}")
    finance2note(rstdf.shape[0], rstdf, '收到转账工作', 'zdzzwork', '微信个人转账收款记录')

    alldf['amount'] = alldf['amount'].astype(float)
    jzdf = alldf[alldf.send.isin(['False'])]
    jzdf = jzdf[jzdf.etime != None]
    print(jzdf.dtypes)
    agg_map = {'name': 'count', 'amount': 'sum'}
    rsdf = jzdf.resample('D').agg(agg_map).sort_index(ascending=False)
    rsdf.columns = ['count', 'sum']
예제 #28
0
        logguid = notelog.guid
        setcfpoptionvalue(namestr, device_id, 'logguid', logguid)

    if not (logcguid := getcfpoptionvalue(namestr, device_id, 'logcguid')):
        note_store = get_notestore()
        parentnotebook = note_store.getNotebook(
            '4524187f-c131-4d7d-b6cc-a1af20474a7f')
        evernoteapijiayi()
        note = ttypes.Note()
        note.title = f'服务器_{device_id}_严重错误日志信息'
        notelog = makenote(token, note_store, note.title,
                           notebody='', parentnotebook=parentnotebook)
        logcguid = notelog.guid
        setcfpoptionvalue(namestr, device_id, 'logcguid', logcguid)

    if not (loglimitc := getinivaluefromnote(namestr, 'loglimit')):
        loglimitc = 500

    if not (servername := getinivaluefromnote('device', device_id)):
        servername = device_id

    if getinivaluefromnote(namestr, 'critical') == 1:
        levelstrc = 'CRITICAL'
        # noteguidc = cfpeverwork.get('evernote', 'lognotecriticalguid')
        log2note(logcguid, loglimitc, levelstrc,
                 notetitle=f'服务器_{servername}_严重错误日志信息')

    # noteguidn = cfpeverwork.get('evernote', 'lognoteguid')
    log2note(noteguid=logguid, loglimit=loglimitc,
             notetitle=f'服务器_{servername}_日志信息')
예제 #29
0
파일: 0ewknife.py 프로젝트: heart5/everwork
        needdf = rstdf1[rstdf1.guestid == int(nameid)]
        print(nameid, gamedict[nameid], needdf.shape[0])
        rstdf1.loc[list(needdf.index), 'guest'] = gamedict[nameid]
rstdf1

guestidcl = 'guestid'
rstdf1: pd.DataFrame = recorddf.copy(deep=True)
# print(rstdf1)
guestidalllst = rstdf1.groupby(guestidcl).first().index.values
print(guestidalllst)
gidds = rstdf1.groupby(['guestid', 'guest']).count().groupby(level='guestid').count()['roomid']
print(gidds)
guestidlst = [str(guestid) for guestid in gidds.index]
print(guestidlst)
for nameid in guestidlst:
    if namez := getinivaluefromnote('game', nameid):
        needdf = rstdf1[rstdf1.guestid == int(nameid)]
        print(namez, needdf.shape[0])
        rstdf1.loc[list(needdf.index), 'guest'] = namez
rstdf1

rstdf1.groupby(['guestid', 'guest']).count()

clname = 'name'
for name in rstdf.groupby(clname).first().index.values:
    if namez := getinivaluefromnote('game', name):
        print(name, namez)
        namedf = rstdf[rstdf[clname] == name]
        print(name, namedf.shape[0])
        for ix in namedf.index:
            rstdf.loc[ix, [clname]] = namez
예제 #30
0
def show2evernote(imglst):
    deviceid = getdeviceid()
    guid = getinivaluefromnote('freemem', f'free_{deviceid}')
    print(guid)
    if (device_name := getinivaluefromnote('device', deviceid)) is None:
        device_name = deviceid