コード例 #1
0
ファイル: filedatafunc.py プロジェクト: heart5/everwork
def fenliu2note(dfall):
    cfpzysm, inizysmpath = getcfp('everzysm')
    zhfromini = [[x, cfpzysm.get('支付宝账户', x).split()]
                 for x in cfpzysm.options('支付宝账户')]
    # print(zhfromini)
    zhonlyone = [x for x in zhfromini if len(x[1][0].split(',')) == 1]
    print(zhonlyone)
    zhmulti = [x for x in zhfromini if len(x[1][0].split(',')) > 1]
    print(zhmulti)
    zhmultichaifen = [[[x[0], [y, x[1][1]]] for y in x[1][0].split(',')]
                      for x in zhmulti]
    print(zhmultichaifen)
    zhmultichaifenchild = [x for y in zhmultichaifen for x in y]
    print(zhmultichaifenchild)
    zhresult = zhonlyone + zhmultichaifenchild
    print(zhresult)
    # zhfine = [x for y in zhresult for x in y]
    zhfine = [[x[0], ','.join([y for y in x[1]])] for x in zhresult]
    print(zhfine)
    zhdf = pd.DataFrame(zhfine, columns=['name', 'codename'])
    zhdf.index = zhdf['name']
    zhds = zhdf['codename']
    dfall['账户名称'] = dfall['对方账户'] + ',' + dfall['对方名称']
    dfall['名称'] = dfall['账户名称'].map(lambda x: zhds[zhds == x].index.values[
        0] if len(zhds[zhds == x].index.values) > 0 else np.NaN)
    dfall.sort_values('日期', ascending=False, inplace=True)
    cls = list(dfall.columns)
    # clsnew = cls[:-2] + [cls[-1]]
    clsnew = cls
    print(clsnew)

    dfout = dfall.loc[:, clsnew]
    # dfout['date'] = dfout['日期'].map(lambda x : pd.to_datetime(x.strftime('%F')))
    dfout['date'] = dfout['日期']
    dfout['ru'] = dfout['收入(+元)'].map(lambda x: False if x == ' ' else True)
    dfout['jine'] = dfout['收入(+元)'] + dfout['支出(-元)']

    def showmingmu(ru, shangpinmingcheng, beizhu, zhanghumingcheng, mingcheng):
        if not ru:
            return
        if pd.isnull(mingcheng) & (zhanghumingcheng != ' , '):
            return '货款,' + '|'.join(
                [shangpinmingcheng, beizhu, zhanghumingcheng])
        elif (mingcheng != '白晔峰') & (not pd.isnull(mingcheng)):
            return '货款,' + '|'.join([
                shangpinmingcheng, beizhu, zhanghumingcheng
            ]) + ',经手人' + mingcheng
        else:
            return

    dfout['mingmu'] = dfout.apply(
        lambda x: showmingmu(x.ru, x.商品名称, x.备注, x.账户名称, x.名称), axis=1)
    dfout['card'] = '支付宝白晔峰流水条目'
    dfout['guid'] = 'f5bad0ca-d7e4-4148-99ac-d3472f1c8d80'

    dffine = dfout[dfout.mingmu.isnull() ==
                   False].loc[:,
                              ['date', 'ru', 'jine', 'mingmu', 'card', 'guid']]

    return dffine
コード例 #2
0
ファイル: filedatafunc.py プロジェクト: heart5/everwork
def alipay2note():
    cnxp = lite.connect(dbpathdingdanmingxi)
    pathalipay = dirmainpath / 'data' / 'finance' / 'alipay'
    dfall = chulidataindir(cnxp, 'alipay', '支付宝流水', '2088802968197536', '支付宝',
                           pathalipay, chulixls_zhifubao)
    zhds = fenliu2note(dfall)
    cnxp.close()

    financesection = '财务流水账'
    item = '支付宝白晔峰流水条目'
    cfpzysm, inizysmpath = getcfp('everzysm')
    if not cfpzysm.has_option(financesection, item):
        count = 0
    else:
        count = cfpzysm.getint(financesection, item)
    if count == zhds.shape[0]:
        log.info(f'{item}\t{zhds.shape[0]}\t无内容更新。')
        return zhds
    else:
        log.info(f'{item}\t{zhds.shape[0]}\t内容有更新。')
    nowstr = datetime.datetime.now().strftime('%F %T')
    imglist2note(
        get_notestore(), [], 'f5bad0ca-d7e4-4148-99ac-d3472f1c8d80',
        f'支付宝白晔峰流水({nowstr})',
        tablehtml2evernote(zhds, tabeltitle='支付宝白晔峰流水', withindex=False))
    cfpzysm.set(financesection, item, f'{zhds.shape[0]}')
    cfpzysm.write(open(inizysmpath, 'w', encoding='utf-8'))

    return zhds
コード例 #3
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()
コード例 #4
0
ファイル: majjianghuojie.py プロジェクト: heart5/everwork
def fixnamebyguestid(inputdf: pd.DataFrame, guestidcl: str = 'guestid'):
    """
    根据guestid更新用户名
    """
    rstdf1: pd.DataFrame = inputdf.copy(deep=True)
    # print(rstdf1.dtypes)
    guestidalllst = rstdf1.groupby(guestidcl).first().index.values
    #     print(guestidalllst)
    gidds = rstdf1.groupby(
        ['guestid',
         'guest']).count().groupby(level='guestid').count()['roomid']
    guestidduplst = [str(guestid) for guestid in gidds[gidds > 1].index]
    if len(guestidduplst) > 0:
        print(guestidduplst)

    # 存在一人多号情况,所以需要无差别更新所有id的对应用户名
    cfpini, cfpinipath = getcfp('everinifromnote')
    gamedict = dict(cfpini.items('game'))
    #     print(gamedict)
    print(f"name correctted by id from evernote ini...", end='\t')
    for nameid in guestidalllst:
        if str(nameid) in gamedict.keys():
            namez = gamedict[str(nameid)]
            needdf = rstdf1[rstdf1.guestid == nameid]
            #             print(nameid, namez, needdf.shape[0])
            rstdf1.loc[list(needdf.index), 'guest'] = namez
    print('Done!')

    return rstdf1
コード例 #5
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()
コード例 #6
0
ファイル: zymessage.py プロジェクト: heart5/everwork
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()
コード例 #7
0
ファイル: peoplelog2note.py プロジェクト: heart5/everwork
def notification2df(items):
    split_items = list()
    for itemstr in items:
        split_items.append(itemstr.strip().split('||| '))

    dfnoti = pd.DataFrame(split_items,
                          columns=('atime', 'shuxing', 'topic', 'content'))
    dfnoti['received'] = True
    # global log
    log.info('系统提醒记录有%d条。' % dfnoti.shape[0])
    # descdb(dfnoti)
    dfnoti.drop_duplicates(inplace=True)
    log.info('系统提醒记录去重后有%d条。' % dfnoti.shape[0])
    dfnoti.index = dfnoti['atime'].apply(lambda x: pd.to_datetime(
        datetime.datetime.strptime(x.strip(), '%B %d, %Y at %I:%M%p')) if len(
            x.split('at')) > 1 else pd.to_datetime(
                datetime.datetime.strptime(x.strip(), '%B %d, %Y')))
    # dfnoti.index = dfnoti['atime']
    del dfnoti['atime']
    dfnoti.sort_index(ascending=False, inplace=True)
    # descdb(dfnoti)
    dfout = dfnoti
    # b3a3e458-f05b-424d-8ec1-604a3e916724

    try:
        notestore = get_notestore()
        xiangmu = ['微信', '支付宝', 'QQ', '日历']
        cfplife, inilifepath = getcfp('everlife')
        for xm in xiangmu:
            biaoti = '系统提醒(%s)记录' % xm
            dfxm = dfnoti[dfnoti.shuxing == xm]
            if cfplife.has_option('lifenotecount', xm):
                ready2update = dfxm.shape[0] > cfplife.getint(
                    'lifenotecount', xm)
            else:
                ready2update = True
            print('%d\t%s\t%s' % (dfxm.shape[0], ready2update, biaoti))
            if ready2update:
                imglist2note(notestore, [], cfplife.get('notesguid', xm),
                             biaoti, tablehtml2evernote(dfxm[:1000], biaoti))
                cfplife.set('lifenotecount', xm, '%d' % dfxm.shape[0])
                cfplife.write(open(inilifepath, 'w', encoding='utf-8'))

    except Exception as ee:
        log.critical('更新系统提醒笔记时出现错误。%s' % str(ee))
    return dfout
コード例 #8
0
ファイル: evernt.py プロジェクト: heart5/everwork
def readinifromnote():
    cfpeverwork, cfpeverworkpath = getcfp('everwork')
    noteguid_inifromnote = cfpeverwork.get('evernote', 'ininoteguid')
    # noteguid_inifromnote = 'e0565861-db9e-4efd-be00-cbce06d0cf98'
    global note_store
    note_store = get_notestore()
    soup = BeautifulSoup(note_store.getNoteContent(noteguid_inifromnote),
                         "html.parser")
    # print(soup)
    ptn = u'<div>(.*?)</div>'
    # ptn = u'<div>'
    itemsource = re.findall(ptn, str(soup))
    print(itemsource)
    items = [x for x in itemsource if not re.search('<.*?>', x)]
    print(items)
    fileobj = open(str(dirmainpath / 'data' / 'everinifromnote.ini'),
                   'w',
                   encoding='utf-8')
    for item in items:
        fileobj.write(item + '\n')
    fileobj.close()
コード例 #9
0
def log2notetimer(jiangemiao):
    print(getdirmain())
    pathlog = getdirmain() / 'log'
    files = os.listdir(str(pathlog))
    loglines = []
    for fname in files[::-1]:
        with open(pathlog / fname, 'r', encoding='utf-8') as flog:
            loglines = loglines + [
                line.strip() for line in flog if line.find('CRITICAL') >= 0
            ]

    print(f'日志共有{len(loglines)}条记录')
    # global cfp, inifilepath
    cfp, cfppath = getcfp('everwork')
    everlogc = cfp.getint('evernote', 'everlogc')
    if len(loglines) == everlogc:  # <=调整为==,用来应对log文件崩溃重建的情况
        log.info('暂无新记录,不更新everworklog笔记。')
    else:
        loglinestr = '\n'.join(loglines[::-1])
        loglinestr = loglinestr.replace('<', '《')
        loglinestr = loglinestr.replace('>', '》')
        loglinestr = loglinestr.replace('&', '并符')
        loglinestr = loglinestr.replace('=', '等于')
        loglinestr = '<pre>' + loglinestr + '</pre>'
        # print(loglinestr)
        noteguid_lognote = '4a940ff2-74a8-4584-be46-aa6d68a4fa53'
        try:
            nstore = get_notestore()
            imglist2note(nstore, [], noteguid_lognote, 'everwork日志严重错误信息',
                         loglinestr)
            cfp.set('evernote', 'everlogc', '%d' % len(loglines))
            cfp.write(open(cfppath, 'w', encoding='utf-8'))
            log.info('新的log错误信息成功更新入笔记,将于%d秒后再次自动检查并更新' % jiangemiao)
        except Exception as eeee:
            log.critical('处理新log错误信息到笔记时出现未名错误。%s' % (str(eeee)))

    global timer_log2note
    timer_log2note = Timer(jiangemiao, log2notetimer, [jiangemiao])
    timer_log2note.start()
コード例 #10
0
ファイル: majjianghuojie.py プロジェクト: heart5/everwork
def fixnamealias(inputdf: pd.DataFrame, clname: str):
    '''
    更新df中的别名为规范名称
    :param inputdf:
    :param clname:
    :return:
    '''
    rstdf1: pd.DataFrame = inputdf.copy(deep=True)
    # print(rstdf1.dtypes)
    namelst = rstdf1.groupby(clname).first().index.values
    # print(namelst)
    cfpini, cfpinipath = getcfp('everinifromnote')
    gamedict = dict(cfpini.items('game'))
    print(f"id to name correctring...")
    for name in namelst:
        if name in gamedict.keys():
            namez = gamedict[name]
            namedf = rstdf1[rstdf1[clname] == name].copy(deep=True)
            print(name, namez, namedf.shape[0])
            # print(namedf)
            for ix in namedf.index:
                rstdf1.loc[ix, [clname]] = namez

    return rstdf1
コード例 #11
0
ファイル: peoplelog2note.py プロジェクト: heart5/everwork
def callsms2df(itemstr):
    # 读取老记录
    # global dirmainpath
    with open(str(dirmainpath / 'data' / 'ifttt' / 'smslog_gmail_all.txt'),
              'r',
              encoding='utf-8') as fsms:
        items = [line.strip() for line in fsms if len(line.strip()) > 0]
    itemstr = itemstr + items
    log.info('电话短信记录有%d条。' % len(itemstr))
    itemstrjoin = '\n'.join(itemstr)
    pattern = re.compile(
        r'^(.*?)(?:(\w+ \d+, \d{4} at \d{2}:\d{2}[A|P]M)|(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\+08:00))(.*?)$',
        re.U | re.M)
    slices = re.split(pattern, itemstrjoin)
    slices = slices[1:]
    # print(len(slices))
    # for i in range(15):
    #     print("%d\t%s" %(i,slices[i]))

    # pattern = re.compile(r'^(?:\w*?)(?:\s*?)@SMS \+(?:\s+)(\w+ \d+, \d{4} at \d{2}:\d{2}[A|P]M)(?:\s*?),'
    #                      r'(.*?)(?:\s+)(.*?)(?:\s+)([\d|-]+)(?:.*?)(?:\s+)(\d+)(?:\s+)(?:.*?)$', re.U|re.M)
    # slices = re.split(pattern, itemstr)
    # print(len(slices))
    # for i in range(30):
    #     print(slices[i].strip())
    #
    split_items = list()
    for i in range(int(len(slices) / 5)):
        item = list()
        # print(slices[i*5:i*5+5])
        itemtimestr = slices[i * 5 + 1]
        if itemtimestr is None:
            itemtimestr = slices[i * 5 + 2].strip()
            itemtime = datetime.datetime.strptime(itemtimestr,
                                                  '%Y-%m-%d %H:%M:%S+08:00')
            # itemtime = pd.to_datetime(itemtimestr)
        else:
            itemtime = datetime.datetime.strptime(slices[i * 5 + 1].strip(),
                                                  '%B %d, %Y at %I:%M%p')

        itemname = ''
        itemnumber = ''
        itemshuxing = '电话'
        itemreceived = True
        itemcontentstr = slices[i * 5 + 3].strip()
        itemcontent = itemcontentstr

        patternsms = re.compile(r':(.*),(\w*)\|\|\| (\d+)', re.U)
        splititem = re.split(patternsms, itemcontentstr)
        if len(splititem) == 5:
            # :抱歉 明天见,||| 13554015554
            # ['', '抱歉 明天见', '', '13554015554', '']
            itemcontent = splititem[1]
            itemname = splititem[2]
            itemnumber = splititem[3]
            itemshuxing = '短信'

        if len(itemname) == 0:
            itemnamestr = slices[i * 5 + 0].strip()
            if itemnamestr.endswith('@SMS +'):
                [itemname, *__] = itemnamestr.split('@SMS +')
                patterncall7 = re.compile(
                    '^,?(?:(电话打给)|(电话来自))\s+(?:(.+?)\s+)?(\d+),时长\s+(\d+)\s+秒$',
                    re.U)
                splititem = re.split(patterncall7, itemcontentstr)
                # print(len(splititem))
                # splititem = itemcontentstr.split()
                if len(splititem) == 7:
                    # ,电话打给 陈益 15623759390,时长 42 秒
                    # ['', '电话打给', None, '陈益', '15623759390', '42', '']
                    # ,电话来自 18671454792,时长 29 秒
                    # ['', None, '电话来自', None, '18671454792', '29', '']
                    # ,电话打给 黄兆钢 15337282888,时长 42 秒
                    # ['', '电话打给', None, '黄兆钢', '15337282888', '42', '']
                    # ,电话来自 白天军 13949452849,时长 35 秒
                    # ['', None, '电话来自', '白天军', '13949452849', '35', '']

                    itemshuxing = '电话'
                    itemname = splititem[3]
                    itemnumber = splititem[4]
                    itemcontent = splititem[5]
                    if splititem[1]:
                        itemreceived = False
                # else:

                patterncall5 = re.compile('(错过来电)\s+(?:(.+?)\s+)?(\d+)', re.U)
                splititem = re.split(patterncall5, itemcontentstr)
                if len(splititem) == 5:
                    # 错过来电 曹树强 13971167977
                    # ['', '错过来电', '曹树强', '13971167977', '']
                    # 错过来电 18903752832
                    # ['', '错过来电', None, '18903752832', '']
                    itemshuxing = '电话'
                    itemname = splititem[2]
                    itemnumber = splititem[3]
                    itemreceived = True
                    itemcontent = None

            elif itemnamestr.endswith('的通话记录'):
                [_, itemname, *__] = itemnamestr.split()
                patterncall6 = re.compile(
                    r',(?:(\+?\d+)s\s\(\d{2}:\d{2}:\d{2}\))?(\+?\d+)\s\((?:(已接来电)|(已拨电话)|(未接来电))\)'
                )
                splititem = re.split(patterncall6, itemcontent)
                if len(splititem) == 7:
                    itemshuxing = '电话'
                    itemnumber = splititem[2]
                    itemcontent = splititem[1]
                    if splititem[4] is not None:
                        itemreceived = False
                else:
                    pass
            elif itemnamestr.startswith('SMS with'):
                itemshuxing = '短信'
                [*__, itemname] = itemnamestr.split()
                if itemcontent.startswith('收到'):
                    itemreceived = True
                    weiyi = 4
                elif itemcontent.startswith('发出'):
                    itemreceived = False
                    weiyi = 4
                else:
                    weiyi = 1
                itemcontent = itemcontentstr[weiyi:]
                # print(itemname + '\t' + str(itemtime) + '\t' + itemcontent)
                # print(splititem)

        item.append(itemtime)
        if itemname is None:
            itemname = itemnumber
        item.append(itemname)
        item.append(itemnumber)
        item.append(itemshuxing)
        item.append(itemreceived)
        item.append(itemcontent)
        # print(slices[i*5].strip()+'\t'+slices[i*5+1].strip()+'\t'+slices[i*5+2].strip()+'\t'+slices[i*5+4].strip())
        split_items.append(item)

    dfnoti = pd.DataFrame(split_items,
                          columns=('atime', 'name', 'number', 'shuxing',
                                   'received', 'content'))
    log.info('电话短信记录整理后有%d条。' % dfnoti.shape[0])
    dfnoti.drop_duplicates(inplace=True)
    log.info('电话短信记录去重后有%d条。' % dfnoti.shape[0])
    dfnoti.sort_values(['atime'], ascending=False, inplace=True)
    # dfnoti.index = dfnoti['time']
    # del dfnoti['time']
    dfout = dfnoti
    # b3a3e458-f05b-424d-8ec1-604a3e916724

    try:
        notestore = get_notestore()
        cfplife, inilifepath = getcfp('everlilfe')
        if cfplife.has_option('allsets', 'callsms'):
            ready2update = dfout.shape[0] > cfplife.getint(
                'allsets', 'callsms')
        else:
            ready2update = True
        if ready2update:
            xiangmu = '电话短信'
            imglist2note(notestore, [], cfplife.get('notesguid', xiangmu),
                         xiangmu, tablehtml2evernote(dfout[:1000], xiangmu))
            cfplife.set('allsets', 'callsms', '%d' % dfout.shape[0])
            cfplife.write(open(inilifepath, 'w', encoding='utf-8'))
    except Exception as eee:
        log.critical('更新人脉记录笔记时出现错误。%s' % str(eee))
    return dfout
コード例 #12
0
ファイル: filedatafunc.py プロジェクト: heart5/everwork
def chulidataindir(cnxp, tablename, mingmu, fnstart, notestr, pathorder: Path,
                   chulixls):
    """

    :param cnxp: 数据库连接
    :param tablename: 表名
    :param mingmu: 名目
    :param fnstart: 文件名起字符串
    :param notestr: section名称
    :param pathorder: 待处理文件目录
    :param chulixls: 处理原始数据的函数
    :return:
    """
    sqlstr = "select count(*)  from sqlite_master where type='table' and name = '%s'" % tablename
    tablexists = pd.read_sql_query(sqlstr, cnxp).iloc[0, 0] > 0
    if tablexists:
        # dfresult = pd.DataFrame()
        dfresult = pd.read_sql('select * from \'%s\'' % tablename,
                               cnxp,
                               parse_dates=['日期'])
        log.info(f'{mingmu}数据表{tablename}已存在, 从中读取{dfresult.shape[0]}条数据记录。')
    else:
        log.info(f'{mingmu}数据表{tablename}不存在,将创建之。')
        dfresult = pd.DataFrame()

    # print(dfresult)
    cfpzysm, inizysmpath = getcfp('everzysm')
    if cfpzysm.has_section(notestr) is False:
        cfpzysm.add_section(notestr)
        cfpzysm.write(open(inizysmpath, 'w', encoding='utf-8'))
    files = os.listdir(str(pathorder))
    for fname in files:
        if fname.startswith(fnstart) and (fname.endswith('xls')
                                          or fname.endswith('xlsx')):
            yichulifilelist = list()
            if cfpzysm.has_option(notestr, '已处理文件清单'):
                yichulifilelist = cfpzysm.get(notestr, '已处理文件清单').split()
            if fname in yichulifilelist:
                continue
            print(fname, end='\t')
            dffname = chulixls(str(pathorder / fname))
            if dffname is None:
                continue
            dfresult = dfresult.append(dffname)
            print(dffname.shape[0], end='\t')
            print(dfresult.shape[0])
            yichulifilelist.append(fname)
            cfpzysm.set(notestr, '已处理文件清单', '%s' % '\n'.join(yichulifilelist))
            cfpzysm.write(open(inizysmpath, 'w', encoding='utf-8'))

    # dfresult.drop_duplicates(['单据编号', '日期', '订单编号', '客户名称', '业务人员', '订单金额', '部门'], inplace=True)
    print(f'除重前有{dfresult.shape[0]}条记录,', end='\t')
    dfresult.drop_duplicates(inplace=True)
    # descdb(dfresult)
    dateqiyu = min(dfresult['日期'])
    datezhiyu = max(dfresult['日期'])
    print(f'除重后有{dfresult.shape[0]}条记录;数据起于{dateqiyu},止于{datezhiyu}')
    dfttt = dfresult.drop_duplicates()
    if cfpzysm.has_option(notestr, '记录数'):
        jilucount = cfpzysm.getint(notestr, '记录数')
    else:
        jilucount = 0
    if dfttt.shape[0] > jilucount:
        dfttt.to_sql(tablename, cnxp, index=False, if_exists='replace')
        cfpzysm.set(notestr, '记录数', '%d' % dfttt.shape[0])
        cfpzysm.write(open(inizysmpath, 'w', encoding='utf-8'))
        log.info(f'增加有效{mingmu}明细数据{dfttt.shape[0] - jilucount}条。')

    cnxp.close()

    return dfttt
コード例 #13
0
ファイル: 0ewknife.py プロジェクト: heart5/everwork
rstdf.to_excel(excelwriter, index=False, encoding='utf-8')
excelwriter.close()

# ##### 调试名号错位问题

from func.evernttest import trycounttimes2, getinivaluefromnote
from muse.majjianghuojie import fetchmjurl, getsinglepage, updateurllst, fixnamebyguestid

ownername = "heart5"
zjurllst = fetchmjurl(ownername)
recentquandf = getsinglepage(zjurllst[0])
recentquandf

# 一次读取所有game下的items用于名称替换,避免一次次读取文件读取网络的效率损耗,也即为减少IO
from func.configpr import getcfp
cfpme, cfpmepath = getcfp('everinifromnote')
gamedict = dict(cfpme.items('game'))
gamedict
'1088457' in gamedict.keys()

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 nameid in gamedict.keys():