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
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
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]}条")
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}")
def weatherstat(df, destguid=None): dfduplicates = df.groupby('date').apply( lambda d: tuple(d.index) if len(d.index) > 1 else None).dropna() log.info(dfduplicates) df.drop_duplicates(inplace=True) # 去重,去除可能重复的天气数据记录,原因可能是邮件重复发送等 # print(df.head(30)) df['date'] = df['date'].apply(lambda x: pd.to_datetime(x)) # 日期做索引,去重并重新排序 df.index = df['date'] df = df[~df.index.duplicated()] df.sort_index(inplace=True) # print(df) df.dropna(how='all', inplace=True) # 去掉空行,索引日期,后面索引值相同的行会被置空,需要去除 # print(len(df)) # df['gaowen'] = df['gaowen'].apply(lambda x: np.nan if str(x).isspace() else int(x)) #处理空字符串为空值的另外一骚 df['gaowen'] = df['gaowen'].apply(lambda x: int(x) if x else None) # 数字串转换成整数,如果空字符串则为空值 df['diwen'] = df['diwen'].apply(lambda x: int(x) if x else None) df['fengsu'] = df['fengsu'].apply(lambda x: int(x) if x else None) df['shidu'] = df['shidu'].apply(lambda x: int(x) if x else None) # df['gaowen'] = df['gaowen'].astype(int) # df['diwen'] = df['diwen'].astype(int) # df['fengsu'] = df['fengsu'].astype(int) # df['shidu'] = df['shidu'].astype(int) df.fillna(method='ffill', inplace=True) # 向下填充处理可能出现的空值,bfill是向上填充 df['wendu'] = (df['gaowen'] + df['diwen']) / 2 df['richang'] = df['sunoff'] - df['sunon'] df['richang'] = df['richang'].astype(int) df['wendu'] = df['wendu'].astype(int) # print(df.tail(30)) df_recent_year = df.iloc[-365:] # print(df_recent_year) # print(df[df.gaowen == df.iloc[-364:]['gaowen'].max()]) # df_before_year = df.iloc[:-364] plt.figure(figsize=(16, 20)) ax1 = plt.subplot2grid((4, 2), (0, 0), colspan=2, rowspan=2) ax1.plot(df['gaowen'], lw=0.3, label=u'日高温') ax1.plot(df['diwen'], lw=0.3, label=u'日低温') ax1.plot(df['wendu'], 'g', lw=0.7, label=u'日温度(高温低温平均)') quyangtianshu = 10 ax1.plot(df['wendu'].resample('%dD' % quyangtianshu).mean(), 'b', lw=1.2, label='日温度(每%d天平均)' % quyangtianshu) ax1.plot(df[df.fengsu > 5]['fengsu'], '*', label='风速(大于五级)') plt.legend(loc=2) # 起始统计日 kedu = df.iloc[0] ax1.plot([kedu['date'], kedu['date']], [0, kedu['wendu']], 'c--', lw=0.4) ax1.scatter([ kedu['date'], ], [kedu['wendu']], 50, color='Wheat') fsize = 8 txt = str(kedu['wendu']) ax1.annotate(txt, xy=(kedu['date'], kedu['wendu']), xycoords='data', xytext=(-(len(txt) * fsize), +20), textcoords='offset points', fontsize=fsize, arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=.2", color='Purple')) dates = "%02d-%02d" % (kedu['date'].month, kedu['date'].day) ax1.annotate(dates, xy=(kedu['date'], 0), xycoords='data', xytext=(-10, -20), textcoords='offset points', fontsize=8, arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=0")) # 去年今日,如果数据不足一年,取今日 if len(df) >= 366: locqnjr = -365 else: locqnjr = -1 kedu = df.iloc[locqnjr] # kedu = df.iloc[-364] print(kedu) ax1.plot([kedu['date'], kedu['date']], [0, kedu['wendu']], 'c--') ax1.scatter([ kedu['date'], ], [kedu['wendu']], 50, color='Wheat') ax1.annotate(str(kedu['wendu']), xy=(kedu['date'], kedu['wendu']), xycoords='data', xytext=(-5, +20), textcoords='offset points', arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=.2", color='Purple')) dates = "%02d-%02d" % (kedu['date'].month, kedu['date'].day) ax1.annotate(dates, xy=(kedu['date'], 0), xycoords='data', xytext=(-10, -35), textcoords='offset points', fontsize=8, arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=0")) # 今日 kedu = df.iloc[-1] # print(kedu) ax1.plot([kedu['date'], kedu['date']], [0, kedu['wendu']], 'c--') ax1.scatter([ kedu['date'], ], [kedu['gaowen']], 50, color='BlueViolet') ax1.annotate(str(kedu['gaowen']), xy=(kedu['date'], kedu['gaowen']), xycoords='data', xytext=(-10, +20), textcoords='offset points', arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=.2", color='Purple')) ax1.scatter([ kedu['date'], ], [kedu['wendu']], 50, color='BlueViolet') ax1.annotate(str(kedu['wendu']), xy=(kedu['date'], kedu['wendu']), xycoords='data', xytext=(10, +5), textcoords='offset points', arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=.2", color='Purple')) ax1.scatter([ kedu['date'], ], [kedu['diwen']], 50, color='BlueViolet') ax1.annotate(str(kedu['diwen']), xy=(kedu['date'], kedu['diwen']), xycoords='data', xytext=(-10, -20), textcoords='offset points', arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=.2", color='Purple')) dates = "%02d-%02d" % (kedu['date'].month, kedu['date'].day) ax1.annotate(dates, xy=(kedu['date'], 0), xycoords='data', xytext=(-10, -35), textcoords='offset points', fontsize=8, arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=0")) # 最近一年最高温 kedu = df_recent_year[df_recent_year.gaowen == df_recent_year.iloc[-364:] ['gaowen'].max()].iloc[0] # print(kedu) ax1.plot([kedu['date'], kedu['date']], [0, kedu['gaowen']], 'c--') ax1.scatter([ kedu['date'], ], [kedu['gaowen']], 50, color='Wheat') ax1.annotate(str(kedu['gaowen']), xy=(kedu['date'], kedu['gaowen']), xycoords='data', xytext=(-20, +5), textcoords='offset points', arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=.2", color='Purple')) dates = "%02d-%02d" % (kedu['date'].month, kedu['date'].day) ax1.annotate(dates, xy=(kedu['date'], 0), xycoords='data', xytext=(-10, -20), textcoords='offset points', fontsize=8, arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=0")) # 最近一年最低温 kedu = df_recent_year[df_recent_year.diwen == df_recent_year.iloc[-364:] ['diwen'].min()].iloc[0] ax1.plot([kedu['date'], kedu['date']], [0, kedu['diwen']], 'c--') ax1.scatter([ kedu['date'], ], [kedu['diwen']], 50, color='Wheat') ax1.annotate(str(kedu['diwen']), xy=(kedu['date'], kedu['diwen']), xycoords='data', xytext=(-20, +5), textcoords='offset points', arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=.2", color='Purple')) dates = "%02d-%02d" % (kedu['date'].month, kedu['date'].day) ax1.annotate(dates, xy=(kedu['date'], 0), xycoords='data', xytext=(-10, -20), textcoords='offset points', fontsize=8, arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=0")) # 最高温 kedu = df[df.gaowen == df['gaowen'].max()].iloc[0] ax1.plot([kedu['date'], kedu['date']], [0, kedu['gaowen']], 'c--') ax1.scatter([ kedu['date'], ], [kedu['gaowen']], 50, color='Wheat') ax1.annotate(str(kedu['gaowen']), xy=(kedu['date'], kedu['gaowen']), xycoords='data', xytext=(-20, +5), textcoords='offset points', arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=.2", color='Purple')) dates = "%02d-%02d" % (kedu['date'].month, kedu['date'].day) ax1.annotate(dates, xy=(kedu['date'], 0), xycoords='data', xytext=(-10, -20), textcoords='offset points', fontsize=8, arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=0")) # 最低温 kedu = df[df.diwen == df['diwen'].min()].iloc[0] ax1.plot([kedu['date'], kedu['date']], [0, kedu['diwen']], 'c--') ax1.scatter([ kedu['date'], ], [kedu['diwen']], 50, color='Wheat') ax1.annotate(str(kedu['diwen']), xy=(kedu['date'], kedu['diwen']), xycoords='data', xytext=(-20, +5), textcoords='offset points', arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=.2", color='Purple')) dates = "%02d-%02d" % (kedu['date'].month, kedu['date'].day) ax1.annotate(dates, xy=(kedu['date'], 0), xycoords='data', xytext=(-10, -20), textcoords='offset points', fontsize=8, arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=0")) ax1.set_ylabel(u'(摄氏度℃)') ax1.grid(True) ax1.set_title(u'最高气温、最低气温和均值温度图') ax3 = plt.subplot2grid((4, 2), (2, 0), colspan=2, rowspan=2) # print(type(ax3)) ax3.plot(df_recent_year['shidu'], 'c.', lw=0.3, label=u'湿度') ax3.plot(df_recent_year['shidu'].resample('15D').mean(), 'g', lw=1.5) ax3.set_ylabel(u'(百分比%)') ax3.set_title(u'半月平均湿度图') img_wenshifeng_path = dirmainpath / "img" / 'weather' / 'wenshifeng.png' img_wenshifeng_path_str = str(img_wenshifeng_path) touchfilepath2depth(img_wenshifeng_path) plt.legend(loc='lower left') plt.savefig(img_wenshifeng_path_str) imglist = list() imglist.append(img_wenshifeng_path_str) plt.close() plt.figure(figsize=(16, 10)) fig, ax1 = plt.subplots() plt.plot(df['date'], df['sunon'], lw=0.8, label=u'日出') plt.plot(df['date'], df['sunoff'], lw=0.8, label=u'日落') ax = plt.gca() # ax.yaxis.set_major_formatter(FuncFormatter(min_formatter)) # 主刻度文本用pi_formatter函数计算 ax.yaxis.set_major_formatter( FuncFormatter(lambda x, pos: "%02d:%02d" % (int(x / 60), int(x % 60)))) # 主刻度文本用pi_formatter函数计算 plt.ylim((0, 24 * 60)) plt.yticks(np.linspace(0, 24 * 60, 25)) plt.xlabel(u'日期') plt.ylabel(u'时刻') plt.legend(loc=6) plt.title(u'日出日落时刻和白天时长图') plt.grid(True) ax2 = ax1.twinx() print(ax2) plt.plot(df_recent_year['date'], df_recent_year['richang'], 'r', lw=1.5, label=u'日长') ax = plt.gca() # ax.yaxis.set_major_formatter(FuncFormatter(min_formatter)) # 主刻度文本用pi_formatter函数计算 ax.yaxis.set_major_formatter( FuncFormatter(lambda x, pos: "%02d:%02d" % (int(x / 60), int(x % 60)))) # 主刻度文本用pi_formatter函数计算 # ax.set_xticklabels(rotation=45, horizontalalignment='right') plt.ylim((3 * 60, 12 * 60)) plt.yticks(np.linspace(3 * 60, 15 * 60, 13)) plt.ylabel(u'时分') plt.legend(loc=5) plt.grid(True) # plt.show() img_sunonoff_path = dirmainpath / 'img' / 'weather' / 'sunonoff.png' img_sunonoff_path_str = str(img_sunonoff_path) touchfilepath2depth(img_sunonoff_path) plt.savefig(img_sunonoff_path_str) imglist.append(img_sunonoff_path_str) plt.close() imglist2note(get_notestore(), imglist, destguid, '武汉天气图')
if not (everlogc := getcfpoptionvalue(namestr, namestr, countnameinini)): everlogc = 0 # log.info(everlogc) if len(loglines) == everlogc: # <=调整为==,用来应对log文件崩溃重建的情况 print(f'暂无新的{levelstr4title}记录,不更新everwork的{levelstr}日志笔记。') else: loglinesloglimit = loglines[(-1 * loglimit):] loglinestr = '\n'.join(loglinesloglimit[::-1]) loglinestr = loglinestr.replace('<', '《').replace('>', '》').replace('=', '等于').replace('&', '并或') loglinestr = "<pre>" + loglinestr + "</pre>" log.info(f"日志字符串长度为:\t{len(loglinestr)}") # log.info(loglinestr[:100]) try: nstore = get_notestore() imglist2note(nstore, [], noteguid, notetitle, loglinestr) setcfpoptionvalue(namestr, namestr, countnameinini, f'{len(loglines)}') print(f'新的log{levelstr4title}信息成功更新入笔记') except Exception as eeee: errmsg = f'处理新的log{levelstr4title}信息到笔记时出现未名错误。{eeee}' log.critical(errmsg) ifttt_notify(errmsg, 'log2note') # %% @set_timeout(360, after_timeout) def log2notes(): namestr = 'everlog' device_id = getdeviceid() token = getcfpoptionvalue('everwork', 'evernote', 'token')
def showorderstat(): # xlsfile = 'data\\work\\销售订单\\销售订单20180606__20180607034848_480667.xls' # dforder = chulixls_order(xlsfile) # global workplannotebookguid workplannotebookguid = '2c8e97b5-421f-461c-8e35-0f0b1a33e91c' pathor = dirmainpath / 'data' / 'work' / '销售订单' dforder = chulidataindir_order(pathor) # print(dforder.dtypes) dingdanxiaoshouyuedufenxi(dforder) dforder = dforder.loc[:, ['日期', '订单编号', '区域', '类型', '客户名称', '业务人员', '订单金额']] dforder.sort_values(by=['日期', '订单编号', '业务人员'], ascending=False, inplace=True) zuixinriqi = dforder.groupby(['日期'])['日期'].size().index.max() orderdatestr = zuixinriqi.strftime('%F') print(orderdatestr, end='\t') dforderzuixinriqi = dforder[dforder.日期 == zuixinriqi] print(dforderzuixinriqi.shape[0]) persons = list(dforderzuixinriqi.groupby('业务人员')['业务人员'].count().index) # print(persons) notestr = '每日销售订单核对' if cfpzysm.has_section(notestr) is False: cfpzysm.add_section(notestr) cfpzysm.write(open(inizysmpath, 'w', encoding='utf-8')) for person in persons: if cfpzysm.has_option(notestr + 'guid', person) is False: try: notestore = get_notestore() plannote = ttypes.Note() plannote.title = notestr + person nbody = '<?xml version="1.0" encoding="UTF-8"?>' nbody += '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">' nbody += '<en-note>%s</en-note>' % plannote.title plannote.content = nbody plannote.notebookGuid = workplannotebookguid token = cfp.get('evernote', 'token') note = notestore.createNote(token, plannote) evernoteapijiayi() cfpzysm.set(notestr + 'guid', person, '%s' % note.guid) cfpzysm.write(open(inizysmpath, 'w', encoding='utf-8')) log.info('成功创建%s的%s笔记' % (person, notestr)) except Exception as ee: log.critical('创建%s的%s笔记时出现错误。%s' % (person, notestr, str(ee))) continue if cfpzysm.has_option(notestr + 'guid', person + '最新订单日期'): ordertoday = cfpzysm.get(notestr + 'guid', person + '最新订单日期') if zuixinriqi <= pd.to_datetime(ordertoday): # and False: # 调试开关,强行生成图表 continue dfperson = dforderzuixinriqi[dforderzuixinriqi.业务人员 == person] dfpersonsum = dfperson.groupby('业务人员').sum()['订单金额'] del dfperson['业务人员'] del dfperson['日期'] print(person, end='\t') print(dfpersonsum[0], end='\t') personguid = cfpzysm.get(notestr + 'guid', person) print(personguid) neirong = tablehtml2evernote(dftotal2top(dfperson), f'{orderdatestr}{notestr}——{person}', withindex=False) # print(neirong) try: notestore = get_notestore() imglist2note(notestore, [], personguid, '%s——%s(%s)' % (notestr, person, orderdatestr), neirong) cfpzysm.set(notestr + 'guid', person + '最新订单日期', '%s' % orderdatestr) cfpzysm.write(open(inizysmpath, 'w', encoding='utf-8')) except Exception as eeee: log.critical('更新笔记%s——%s(%s)时出现严重错误。%s' % (notestr, person, orderdatestr, str(eeee))) else: log.info('下列人员的销售订单正常处置完毕:%s' % persons) yuechuriqi = pd.to_datetime(f"{zuixinriqi.strftime('%Y')}-{zuixinriqi.strftime('%m')}-01") dfsales = pd.DataFrame(dforder[dforder.日期 >= yuechuriqi]) dfsales = dfsales.groupby(['区域', '类型', '客户名称', '业务人员'], as_index=False).sum() dfsales.sort_values(['区域', '订单金额'], inplace=True) notestr = '销售订单金额(月)' if cfpzysm.has_section(notestr) is False: cfpzysm.add_section(notestr) cfpzysm.write(open(inizysmpath, 'w', encoding='utf-8')) for person in persons: if cfpzysm.has_option(notestr, person) is False: try: notestore = get_notestore() plannote = ttypes.Note() plannote.title = notestr + person nbody = '<?xml version="1.0" encoding="UTF-8"?>' nbody += '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">' nbody += '<en-note>%s</en-note>' % plannote.title plannote.content = nbody plannote.notebookGuid = workplannotebookguid # cfp, cfppath = getcfp('everwork') token = cfp.get('evernote', 'token') note = notestore.createNote(token, plannote) evernoteapijiayi() cfpzysm.set(notestr, person, '%s' % note.guid) cfpzysm.write(open(inizysmpath, 'w', encoding='utf-8')) log.info('成功创建%s的%s笔记' % (person, notestr)) except Exception as ee: log.critical('创建%s的%s笔记时出现错误。%s' % (person, notestr, str(ee))) continue if cfpzysm.has_option(notestr, person + '最新订单日期'): ordertoday = cfpzysm.get(notestr, person + '最新订单日期') if zuixinriqi <= pd.to_datetime(ordertoday): # and False: continue dfperson = dfsales[dfsales.业务人员 == person] dfpersonsum = dfperson['订单金额'].sum() del dfperson['业务人员'] print(person, end='\t') print(dfpersonsum, end='\t') personguid = cfpzysm.get(notestr, person) print(personguid) neirong = tablehtml2evernote(dftotal2top(dfperson), f'{orderdatestr[:-3]}{notestr}', withindex=False) # print(neirong) try: notestore = get_notestore() imglist2note(notestore, [], personguid, '%s——%s(%s)' % (notestr, person, orderdatestr[:-3]), neirong) cfpzysm.set(notestr, person + '最新订单日期', '%s' % orderdatestr) cfpzysm.write(open(inizysmpath, 'w', encoding='utf-8')) except Exception as eeee: log.critical('更新笔记%s——%s(%s)时出现严重错误。%s' % (notestr, person, orderdatestr, str(eeee))) else: log.info('下列人员的销售订单金额月度分析正常处置完毕:%s' % persons) dfsales = pd.DataFrame(dforder) dfsales = dfsales.groupby(['日期', '业务人员'], as_index=False).sum() # persons = list(dfsales.groupby('业务人员')['业务人员'].count().index) # print(persons) dfsales.sort_values(['日期'], inplace=True) notestr = '销售金额分析图表' if cfpzysm.has_section(notestr) is False: cfpzysm.add_section(notestr) cfpzysm.write(open(inizysmpath, 'w', encoding='utf-8')) for person in persons: if cfpzysm.has_option(notestr, person) is False: try: notestore = get_notestore() plannote = ttypes.Note() plannote.title = notestr + person nbody = '<?xml version="1.0" encoding="UTF-8"?>' nbody += '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">' nbody += '<en-note>%s</en-note>' % plannote.title plannote.content = nbody plannote.notebookGuid = workplannotebookguid # cfp, cfppath = getcfp('everwork') token = cfp.get('evernote', 'token') note = notestore.createNote(token, plannote) evernoteapijiayi() cfpzysm.set(notestr, person, '%s' % note.guid) cfpzysm.write(open(inizysmpath, 'w', encoding='utf-8')) log.info('成功创建%s的%s笔记' % (person, notestr)) except Exception as ee: log.critical('创建%s的%s笔记时出现错误。%s' % (person, notestr, str(ee))) continue dfperson = dfsales[dfsales.业务人员 == person] zuixinriqi = dfperson.groupby(['日期'])['日期'].size().index.max() orderdatestr = zuixinriqi.strftime('%F') if cfpzysm.has_option(notestr, person + '最新订单日期'): ordertoday = cfpzysm.get(notestr, person + '最新订单日期') # print(f'{zuixinriqi}\t{ordertoday}') if zuixinriqi <= pd.to_datetime(ordertoday): # and False: # 调试开关,强行生成图表 continue dfpersonsum = dfperson['订单金额'].sum() dfperson = dfperson.groupby(['日期']).sum() # del dfperson['业务人员'] print(person, end='\t') print(dfpersonsum, end='\t') personguid = cfpzysm.get(notestr, person) print(personguid) # neirong = tablehtml2evernote(dftotal2top(dfperson), f'{orderdatestr[:-3]}{notestr}', withindex=False) neirong = "" # print(neirong) try: notestore = get_notestore() imglist = dfin2imglist(dfperson, cum=True) imglist2note(notestore, imglist, personguid, '%s——%s(%s)' % (notestr, person, orderdatestr[:-3]), neirong) cfpzysm.set(notestr, person + '最新订单日期', '%s' % orderdatestr) cfpzysm.write(open(inizysmpath, 'w', encoding='utf-8')) except Exception as eeee: log.critical('更新笔记%s——%s(%s)时出现严重错误。%s' % (notestr, person, orderdatestr, str(eeee))) else: log.info('下列人员的销售金额分析图表正常处置完毕:%s' % persons)
plt.close() imglst.append(str(imgpathtoday)) dsdays = ds.resample('D').sum() print(dsdays) dsdays.plot() imgpathdays = dirmainpath / 'img' / 'gpsdays.png' touchfilepath2depth(imgpathdays) plt.savefig(str(imgpathdays)) plt.close() imglst.append(str(imgpathdays)) print(imglst) if (device_name := getinivaluefromnote('device', device_id)) is None: device_name = device_id imglist2note( get_notestore(), imglst, guid, f'手机_{device_name}_location更新记录', tablehtml2evernote( df4dis.sort_index(ascending=False).iloc[:100, ], "坐标流水记录单")) # %% [markdown] # ## 主函数main # %% if __name__ == '__main__': if not_IPython(): log.info(f'运行文件\t{__file__}……') dout = chuli_datasource() foot2show(dout) # showdis() if not_IPython(): log.info(f"完成文件{__file__}\t的运行")
plt.annotate(cutdf.index[-1].strftime("%y-%m-%d %H:%M"), xy=[cutdf.index[-1], cutdf.iloc[-1, 1]]) plt.savefig(imgpath) return str(imgpath) # %% def show2evernote(imglst): deviceid = getdeviceid() guid = getinivaluefromnote('freemem', f'free_{deviceid}') print(guid) if (device_name := getinivaluefromnote('device', deviceid)) is None: device_name = deviceid imglist2note(get_notestore(), imglst, guid, f'手机_{device_name}_空闲内存动态', "") # %% [markdown] # ## 主函数 # %% if __name__ == '__main__': if not_IPython(): logstrouter = "运行文件\t%s……" % __file__ log.info(logstrouter) datarelatepath = "sbase/zshscripts" img = getcutpoint(datarelatepath) show2evernote([img]) if not_IPython(): logstrouter = "文件%s运行结束" % (__file__)
noteguid = getinivaluefromnote('webchat', mingmu) if not (count_zdzz := getcfpoptionvalue('everwebchat', 'finance', mingmu4ini)): count_zdzz = 0 # print(f"{count_zdzz}") rstdf.fillna('None', inplace=True) colstr = 'index\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 = itemstr finance2note4debug = getinivaluefromnote('webchat', 'finance2note4debug') print(f"{type(finance2note4debug)}\t{finance2note4debug}") if (srccount != count_zdzz) or finance2note4debug: imglist2note(get_notestore(), [], noteguid, title, notecontent) setcfpoptionvalue('everwebchat', 'finance', mingmu4ini, f"{srccount}") log.info(f"成功更新《{title}》,记录共有{rstdf.shape[0]}条") # %% def tiqucaiwujilufromsingletxt(filename): """ 从单一文件提取聊天记录,生成DataFrame输出 """ ffulltxt = "" decode_set = ['utf-8', 'gb18030', 'ISO-8859-2', 'gb2312', 'gbk', 'Error'] for dk in decode_set: try: with open(filename, "r", encoding=dk) as f: ffulltxt = f.read()
# readinifromnote() # cfpfromnote, cfpfromnotepath = getcfp('everinifromnote') if (men_wc is None) or (len(men_wc) == 0): log.critical(f"登录名{men_wc}为空!!!") return if (chatnoteguid := getinivaluefromnote('webchat', men_wc + f"_{getdeviceid()}").lower()) is None: chatnoteguid = getinivaluefromnote('webchat', men_wc).lower() updatefre = getinivaluefromnote('webchat', 'updatefre') showitemscount = getinivaluefromnote('webchat', 'showitems') # print(f"{type(showitemscount)}\t{showitemscount}") neirong = "\n".join(chatitems[:showitemscount]) neirongplain = neirong.replace('<', '《').replace('>', '》') \ .replace('=', '等于').replace('&', '并或') if (len(chatitems) % updatefre) == 0: neirongplain = "<pre>" + neirongplain + "</pre>" imglist2note(note_store, [], chatnoteguid, f"微信({men_wc})_({getinivaluefromnote('device', getdeviceid())})记录更新笔记", neirongplain) # print(webchats) # %% def getsendernick(msg): """ 获取发送者昵称并返回 """ # sendernick = itchat.search_friends(userName=msg['FromUserName']) if msg['FromUserName'].startswith('@@'): qun = itchat.search_chatrooms(userName=msg['FromUserName']) sendernick = qun['NickName'] + '(群)' + msg['ActualNickName'] else: senderuser = itchat.search_friends(userName=msg['FromUserName']) if senderuser is None:
filename, parentnotebook=nbguid) noteguid = note.guid setcfpoptionvalue('evercode', nbname, f'{filename}_guid', noteguid) ennotetime = 0 setcfpoptionvalue('evercode', nbname, filename, f"{ennotetime}") noteguid = getcfpoptionvalue('evercode', nbname, f'{filename}_guid') ennotetime = getcfpoptionvalue('evercode', nbname, filename) print(nbname, filename, ennotetime, noteguid) filetimenow = os.stat(fn).st_mtime if filetimenow > ennotetime: with open(fn) as f: fcontent = f.read() outlst = list() outlst.extend(re.findall(ptnfiledesc, fcontent)) outlst.extend(["*" * 40]) for item in re.findall(ptnnamedesc, fcontent): outlst.extend([x.strip() for x in item]) outlst.extend(['-' * 20 + "\n"]) cleanoutlst = [x for x in outlst if len(x) > 0] print("\n".join(cleanoutlst)) imglist2note(get_notestore(), [], noteguid, filename, "<pre>" + "\n".join(cleanoutlst) + "</pre>") setcfpoptionvalue('evercode', nbname, filename, f"{filetimenow}") # %% # %% if __name__ == '__main__': checknewthenupdatenote()
def planfenxifunc(): # global dbpathworkplan cnxp = lite.connect(dbpathworkplan) tablename_updated = 'planupdated' errorshowstr = '更新业务日志汇总笔记时出现错误。' try: # fetchattendance_from_evernote() note_store = get_notestore() # 从印象笔记中取得在职业务列表 persons = BeautifulSoup( note_store.getNoteContent('992afcfb-3afb-437b-9eb1-7164d5207564'), 'html.parser') # print(persons) pslist = list() patn = re.compile('\s*[,,]\s*') for ddiv in persons.find_all('div'): psitem = re.split(patn, ddiv.get_text()) if len(psitem) == 3: atom = list() atom.append(psitem[0]) atom.append(pd.to_datetime(psitem[1])) atom.append(pd.to_datetime(psitem[2])) pslist.append(atom) personsdf = pd.DataFrame(pslist, columns=['name', 'shanggang', 'ligang']) personsdfzaigang = personsdf[pd.isnull(personsdf['ligang'])] # print(personsdfzaigang) persons = list(personsdfzaigang['name']) print(persons) evernoteapijiayi() # 更新相应数据表内容 updatedb_workplan(note_store, persons) # 从数据表中查询日志更新记录,只针对在职业务人员 # 组装sql语句使用的set,形如('梅富忠','陈益','周莉') personsetstr = '(' for pr in ['\'' + x + '\'' for x in persons]: personsetstr += pr + ',' personsetstr = personsetstr[:-1] + ')' # print(personsetstr) sqlstr = f'select distinct * from {tablename_updated} where name in {personsetstr} ' \ f'order by date desc, name, updatedtime desc' dfsource = pd.read_sql(sqlstr, cnxp, parse_dates=['date', 'updatedtime']) # 通过ini中记录的有效日志条目(以日期为单位)数量判断是否有有效的日志更新条目 updatablelist = [] for person in persons: planitemscount = dfsource.loc[dfsource.name == person].shape[0] print(f'{person}日志更新记录有{planitemscount}条') if cfpworkplan.has_option('业务计划总结itemscount', person): updatable = planitemscount > cfpworkplan.getint( '业务计划总结itemscount', person) else: updatable = True updatablelist.append(updatable) print(f'{persons},{updatablelist}') updatableall = False for i in range(len(updatablelist)): updatableall |= updatablelist[i] if updatableall: break if updatableall: # or True: dayscount = cfpworkplan.getint('业务计划总结dayscount', 'count') today = pd.to_datetime(datetime.datetime.today().strftime('%F')) workdays = isworkday([today - datetime.timedelta(days=60)], '全体', fromthen=True) # print(workdays) dtqishi = workdays[workdays.work].groupby( 'date').count().sort_index(ascending=False).index[dayscount - 1] print(f'最近{dayscount}个工作日(公司)的起始日期:{dtqishi}') # dtqishi = today - datetime.timedelta(days=dayscount) dtqujian = pd.date_range(dtqishi, today, freq='D').values dfqujian = pd.DataFrame() for person in persons: resultlist = isworkday(dtqujian, person) dftmp = pd.DataFrame( resultlist, columns=['date', 'name', 'work', 'xingzhi', 'tianshu']) shanggangdate = personsdf[personsdf.name == person]['shanggang'].values[0] dftmp = dftmp[dftmp.date >= shanggangdate] if dfqujian.shape[0] == 0: dfqujian = dftmp else: dfqujian = dfqujian.append(dftmp) dfsourcequjian = dfsource[dfsource.date >= dtqishi] # print(dfqujian) # print(dfsourcequjian) dfresult = pd.merge(dfqujian, dfsourcequjian, on=['date', 'name'], how='outer') # dflast = dfresult[dfresult.work == True].sort_values(['date', 'name'], ascending=[False, True]) dflast = dfresult.sort_values(['date', 'name'], ascending=[False, True]) df = dflast.loc[:, [ 'name', 'date', 'contentlength', 'updatedtime', 'xingzhi', 'tianshu' ]] df2show = df.drop_duplicates(['name', 'date'], keep='last') print(f'去重前记录数为:{df.shape[0]},去重后记录是:{df2show.shape[0]}') df2show.columns = ['业务人员', '计划日期', '内容字数', '日志更新时间', '出勤', '天数'] # print(df2show) def hege(a, b, c): freelist = ['请假'] if c in freelist: return f'{c}' if pd.isnull(b): # print(f'{a}\t{b}') return '未交' if pd.to_datetime(a) > pd.to_datetime(b): return '准时' else: return '延迟' col_names = list(df2show.columns) col_names.append('提交') df2show = df2show.reindex(columns=col_names) df2show.loc[:, ['提交']] = df2show.apply( lambda x: hege(x.计划日期, x.日志更新时间, x.出勤), axis=1) print(df2show[pd.isnull(df2show.日志更新时间)]) df2show['计划日期'] = df2show['计划日期'].apply( lambda x: x.strftime('%m-%d')) df2show['日志更新时间'] = df2show['日志更新时间'].apply( lambda x: x.strftime('%m-%d %H:%M') if pd.notnull(x) else '') df2show['内容字数'] = df2show['内容字数'].apply(lambda x: str(int(x)) if pd.notnull(x) else '') df2show = df2show.loc[:, [ '业务人员', '计划日期', '内容字数', '日志更新时间', '提交', '出勤' ]] freeday = ['周日'] df2show = df2show[df2show['出勤'].map(lambda x: x not in freeday)] # print(df2show) for ix in df2show.index: yanchiweitijiao = ['延迟', '未交'] queqin = ['请假'] if df2show.loc[ix]['出勤'] in queqin: for clname in df2show.columns: df2show.loc[ix, clname] = df2show.loc[ix, clname].join( ['<span style=\"color:gray\">', '</span>']) elif df2show.loc[ix]['提交'] in yanchiweitijiao: for clname in df2show.columns: df2show.loc[ix, clname] = df2show.loc[ix, clname] \ .join(['<span style=\"color:red\">', '</span>']) df2show = df2show.loc[:, ['业务人员', '计划日期', '内容字数', '日志更新时间', '提交']] # descdb(df2show) neirong = tablehtml2evernote(df2show, '业务工作日志提交情况汇总(最近%d工作日)' % dayscount, withindex=False) neirong = html.unescape(neirong) # print(neirong) guid = cfpworkplan.get('业务计划总结guid', '汇总') huizongnoteupdatedtime = datetime.datetime.now().strftime('%F %T') imglist2note(note_store, [], guid, '业务工作日志提交情况汇总(%s)' % huizongnoteupdatedtime, neirong) for person in persons: dfperson = dfsource.loc[dfsource.name == person] planitemscount = dfperson.shape[0] if cfpworkplan.has_option('业务计划总结itemscount', person): updatable = planitemscount > cfpworkplan.getint( '业务计划总结itemscount', person) else: updatable = True if updatable: if dfperson.shape[0] == 0: continue log.info('%s的业务日志条目数增加至%d,日志更新表中最新日期为:%s。' % (person, planitemscount, str(dfperson.iloc[0]['nianyueri']))) cfpworkplan.set('业务计划总结itemscount', person, '%d' % planitemscount) cfpworkplan.write(open(iniworkplanpath, 'w', encoding='utf-8')) except OSError as ose: if ose.errno == 10054: log.critical(f'远程主机发脾气了,强行断线。') log.critical(f'{errorshowstr}Windows错误:{ose}') except AttributeError as ae: log.critical(f'{errorshowstr}属性错误:{ae}') except Exception as eee: log.critical(f'{errorshowstr}{eee}') # raise eee finally: cnxp.close()
if numinnotedesc == numatlocal == len(finditems): log.info(f"《{notelisttitle}》中数量无更新,跳过。") return finditems findnotelstwithgtu = findnotefromnotebook(notebookguid, f"wcitems_{name}_", notecount=1000) findnotelst = [[nt[1], nt[0]] for nt in findnotelstwithgtu] findnotelst = sorted(findnotelst, key=lambda x: x[0], reverse=True) nrlst[0] = re.sub("\t(-?\d+)", "\t" + f"{len(findnotelst)}", nrlst[0]) nrlst[1] = "\n".join(["\t".join(sonlst) for sonlst in findnotelst]) nrlst[ 2] = f"更新于{timenowstr},来自于主机:{getdevicename()}{loginstr}" + f"\n{nrlst[2]}" imglist2note(get_notestore(), [], notelistguid, notelisttitle, neirong="<pre>" + "\n---\n".join(nrlst) + "</pre>", parentnotebookguid=notebookguid) numatlocal = len(finditems) setcfpoptionvalue('everwcitems', "common", f"{name}_num_at_local", str(numatlocal)) return findnotelst # %% [markdown] # ### def merge2note(dfdict) # %% @timethis
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)
itemnew = [ f'{ip}\t{wifi}\t{wifiid}\t{tun}\t{nowstr}'] itemnew.extend(itemnewr) # print(itemnew) readinifromnote() device_name = getcfpoptionvalue('everinifromnote', 'device', device_id) if not device_name: device_name = device_id setcfpoptionvalue(namestr, device_id, 'ipr', ip) setcfpoptionvalue(namestr, device_id, 'wifir', str(wifi)) setcfpoptionvalue(namestr, device_id, 'wifiidr', str(wifiid)) setcfpoptionvalue(namestr, device_id, 'tunr', str(tun)) start = datetime.datetime.now().strftime('%F %T') setcfpoptionvalue(namestr, device_id, 'start', start) # 把笔记输出放到最后,避免更新不成功退出影响数据逻辑 imglist2note(get_notestore(), [], guid, f'服务器_{device_name}_ip更新记录', "<pre>" + "\n".join(itemnew) + "</pre>") if __name__ == '__main__': if not_IPython(): log.info( f'开始运行文件\t{__file__}\t……\t{sys._getframe().f_code.co_name}\t{sys._getframe().f_code.co_filename}') if (bsdict := battery_status())['percentage'] >= 20: showiprecords() else: log.warning("手机电量低于20%,跳过ip轮询") # print(f"{self.__class__.__name__}") if not_IPython(): log.info(f'文件\t{__file__}\t执行完毕')
def kuangjiachutu(notefenbudf, noteleixingdf, df, xiangmu, cnxk, pinpai, cum=False): # global log dfquyu = pd.read_sql('select * from quyu', cnxk, index_col='index') dfleixing = pd.read_sql('select * from leixing', cnxk, index_col='index') fenbulist = list(notefenbudf.index) # print(fenbulist) leixinglist = ['终端客户', '连锁客户', '渠道客户', '直销客户', '公关客户', '其他客户', '全渠道'] if df.shape[0] == 0: log.info('%s数据查询为空,返回' % pinpai) return for leixingset in leixinglist: if leixingset == '全渠道': leixing = tuple(dfleixing['编码']) else: leixing = tuple((dfleixing[dfleixing['类型'] == leixingset])['编码']) if len(leixing) == 1: leixing = tuple(list(leixing) + ['U']) if leixingset == '终端客户': for fenbuset in fenbulist: if fenbuset == '所有分部': fenbu = tuple(set(dfquyu['区域'])) else: fenbu = tuple((dfquyu[dfquyu['分部'] == fenbuset])['区域']) log.debug( str(df['日期'].max()) + '\t:\t' + leixingset + '\t,\t' + fenbuset) dfs = df[(df.类型.isin(leixing).values == True) & (df.区域.isin(fenbu).values == True)] if dfs.shape[0] == 0: log.info('在客户类型为“' + str(leixingset) + '”且所在位置为“' + fenbuset + '”时无数据!') continue # 对应fenbuset if cum: dfin = dfs.groupby('日期').sum() else: dfin = getgroupdf(dfs, xiangmu) imglist = dfin2imglist(dfin, cum=cum, leixingset=leixingset, fenbuset=fenbuset, pinpai=pinpai) htable = dfin[dfin.index > ( dfin.index.max() + pd.Timedelta(days=-365))].sort_index( ascending=False).to_html().replace( 'class="dataframe"', '') imglist2note(get_notestore(), imglist, notefenbudf.loc[fenbuset]['guid'], notefenbudf.loc[fenbuset]['title'], neirong=htable) else: log.debug(str(df['日期'].max()) + '\t:\t' + leixingset) dfs = df[df.类型.isin(leixing).values == True] if dfs.shape[0] == 0: log.info('在客户类型“' + str(leixingset) + '”中时无数据!') continue if cum: dfin = dfs.groupby('日期').sum() dfin = pd.DataFrame(dfin, index=pd.to_datetime(dfin.index)) else: dfin = getgroupdf(dfs, xiangmu) imglist = dfin2imglist(dfin, cum=cum, leixingset=leixingset, pinpai=pinpai) targetlist = list(noteleixingdf.index) if leixingset in targetlist: htable = dfin[dfin.index > ( dfin.index.max() + pd.Timedelta(days=-365))].sort_index( ascending=False).to_html().replace( 'class="dataframe"', '') imglist2note(get_notestore(), imglist, noteleixingdf.loc[leixingset]['guid'], noteleixingdf.loc[leixingset]['title'], neirong=htable)
dfnotenameg['count'] = dfnotename.groupby(['address' ]).count()['atime'] dfnotenameg.sort_values(['atime'], ascending=False, inplace=True) wifitongjinametablestr = tablehtml2evernote( dfnotenameg, 'WIFI(特定)统计') wifijilutablestr = tablehtml2evernote(dfnotename.head(50), 'WIFI(特定)连接记录') dfwifiall.reset_index(inplace=True) dfnoteallg = pd.DataFrame( dfwifiall.groupby(['name']).max()['atime']) dfnoteallg['count'] = dfwifiall.groupby(['name']).count()['atime'] dfnoteallg.sort_values(['atime'], ascending=False, inplace=True) wifitongjialltablestr = tablehtml2evernote(dfnoteallg, 'WIFI(全部)统计') imglist2note( notestore, [], '971f14c0-dea9-4f13-9a16-ee6e236e25be', 'WIFI连接统计表', wifitongjinametablestr + wifijilutablestr + wifitongjialltablestr) setcfpoptionvalue('everlife', 'wifi', 'itemnumber', '%d' % dfwificount) except Exception as eee: log.critical('更新WIFI连接统计笔记时出现错误。%s' % str(eee)) return dfout # %% def itemstodf(itemstr, noteinfos): itemstrjoin = '\n'.join(itemstr) # 生成英文的月份列表,组装正则模式,以便准确识别 yuefenlist = [
def jinchustat(jinchujiluall, noteinfos): """ 读取ifttt自动通过gmail转发至evernote生成的地段进出记录,统计作图展示 :rtype: Null """ address = noteinfos[0] destguid = noteinfos[2] notetitle = noteinfos[3] # print(destguid, end='\t') # print(notetitle) dfjc = jinchujiluall[jinchujiluall.address == address][['entered']] # descdb(dfjc) dfjc['atime'] = dfjc.index dfjc['nianyue'] = dfjc['atime'].apply( lambda x: datetime.datetime.strftime(x, '%Y%m')) dfjc['小时'] = dfjc['atime'].apply( lambda x: datetime.datetime.strftime(x, '%H')) # print(dfjc.tail(10)) dfff = dfjc[dfjc.entered == False].groupby( ['nianyue', '小时'])['entered'].count() # 以离开为进出标准 dffu = dfff.unstack(fill_value=0) # print(dffu) # 补满小时数和年月份 for i in range(24): colname = '%02d' % i if colname not in list(dffu.columns): dffu[colname] = 0 lst = sorted(list(dffu.columns)) dffu = dffu[lst] dfrange = pd.date_range(dfjc.index.min(), dfjc.index.max() + MonthBegin(), freq='M') ddrange = pd.Series(dfrange).apply( lambda x: datetime.datetime.strftime(x, "%Y%m")) dffu = dffu.reindex(ddrange, fill_value=0) # 列尾行尾增加汇总 dffu['行合计'] = dffu.apply(lambda x: x.sum(), axis=1) dffu.loc['列合计'] = dffu.apply(lambda x: x.sum()) # print(dffu) lastestitems = tablehtml2evernote(dfjc[['entered']].head(5), notetitle.replace('统计图表', '记录')) stattable = tablehtml2evernote(dffu.sort_index(ascending=False), notetitle) hout = lastestitems + stattable # print(h) # print(hout) # 删掉列尾行尾的合计,并时间序列化index,为plot做准备 del dffu['行合计'] dffu = dffu.iloc[:-1] dffu['nianyue'] = dffu.index dffu['nianyue'] = dffu['nianyue'].apply( lambda x: pd.to_datetime("%s-%s-01" % (x[:4], x[-2:]))) dffu.index = dffu['nianyue'] del dffu['nianyue'] # descdb(dffu) plt.figure() ax1 = plt.subplot2grid((5, 2), (0, 0), colspan=2, rowspan=2) # print(dffu.sum()) ax1.plot(dffu.sum(axis=1).T) ax2 = plt.subplot2grid((5, 2), (3, 0), colspan=2, rowspan=2) # print(dffu.sum(axis=1).T) ax2.plot(dffu.sum()) imglist = [] # plt.show() # global dirmainpath img_jinchu_path = str(dirmainpath / 'img' / 'jichubyfgongsi.png') plt.savefig(img_jinchu_path) imglist.append(img_jinchu_path) # print(imglist) plt.close() imglist2note(get_notestore(), imglist, destguid, notetitle, hout)
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
def dingdanxiaoshouyuedufenxi(dforder): dfall = dforder.loc[:, :] dfall['年月'] = dfall['日期'].apply(lambda x: x.strftime('%Y%m')) # descdb(dfall) zuijinchengjiaori = max(dfall['日期']) print(f'数据集最新日期:{zuijinchengjiaori.strftime("%F")}') if cfpdata.has_option('ordersaleguidquyu', '数据最新日期'): daterec = pd.to_datetime(cfpdata.get('ordersaleguidquyu', '数据最新日期')) if daterec >= zuijinchengjiaori: # and False: log.info(f'订单数据集无更新,返回') return zuiyuanriqi = zuijinchengjiaori + datetime.timedelta(days=-365) zuiyuanyuechu = pd.to_datetime(f"{zuiyuanriqi.strftime('%Y-%m')}-01") print(zuiyuanyuechu.strftime("%F")) dfkehu = dfall.groupby(['单位编号', '客户名称', '区域', '类型'], as_index=False).count() dfkehu.drop_duplicates(['单位编号'], keep='last', inplace=True) dfkehuzhengli = dfkehu[['单位编号', '客户名称', '区域', '类型']] dfkehuzhengli.index = dfkehuzhengli['单位编号'] del dfkehuzhengli['单位编号'] # descdb(dfkehuzhengli) dsquyuzuixinriqi = pd.Series(dfall[dfall.日期 == zuijinchengjiaori].groupby('区域').count().index.values) # print(dsquyuzuixinriqi.values) dfyuetongji = dfall[dfall.日期 >= zuiyuanyuechu].groupby(by=['年月', '单位编号'], as_index=False, sort=True)['订单金额'].sum() dfyuetongji['订单金额'] = dfyuetongji['订单金额'].astype(int) # descdb(dfyuetongji) dfpivot = dfyuetongji.pivot(index='单位编号', values='订单金额', columns='年月') dfpivot = pd.DataFrame(dfpivot) cls = list(dfpivot.columns) # print(cls) # for cl in cls: # dfpivot[cl] = dfpivot[cl].astype(int) dfpivot['单位编号'] = dfpivot.index dfpivot['客户名称'] = dfpivot['单位编号'].apply(lambda x: dfkehuzhengli.loc[x][0]) dfpivot['区域'] = dfpivot['单位编号'].apply(lambda x: dfkehuzhengli.loc[x][1]) dfpivot['类型'] = dfpivot['单位编号'].apply(lambda x: dfkehuzhengli.loc[x][2]) clsnew = ['客户名称', '区域', '类型'] + cls # print(clsnew) dfpivot = dfpivot.loc[:, clsnew] dfpivot['成交月数'] = dfpivot.apply(lambda x: x[-13:].count(), axis=1) def shouciyuefen(xx): for i in range(len(xx)): # print(xx[i]) if xx[i] > 0: return i else: return 12 dfpivot['首次成交月份'] = dfpivot.apply(lambda x: clsnew[shouciyuefen(x[3:16]) + 3], axis=1) dfpivot['首交月数'] = dfpivot.apply(lambda x: 13 - shouciyuefen(x[3:16]), axis=1) def zuijinyuefen(xx): for i in range(len(xx) - 1, -1, -1): # print(f'{xx[i]}\t{i}') if xx[i] > 0: return i else: return 12 dfpivot['最近成交月份'] = dfpivot.apply(lambda x: clsnew[zuijinyuefen(x[3:16]) + 3], axis=1) dfpivot['尾交月数'] = dfpivot.apply(lambda x: 13 - zuijinyuefen(x[3:16]), axis=1) dfpivot['有效月数'] = dfpivot['首交月数'] - dfpivot['尾交月数'] + 1 dfpivot.fillna(0, inplace=True) dfpivot['年总金额'] = dfpivot.apply(lambda x: sum(x[3:16]), axis=1) # print(dfpivot.iloc[0, :]) dfpivot['年总金额'] = dfpivot['年总金额'].astype(int) def youxiaoyuejun(jine, yueshu): if yueshu == 0: return 0 else: return jine / yueshu dfpivot['有效月均'] = dfpivot.apply(lambda x: youxiaoyuejun(x.年总金额, x.有效月数), axis=1) dfpivot['有效月均'] = dfpivot['有效月均'].astype(int) dfpivot.sort_values(['区域', '有效月均'], ascending=[True, False], inplace=True) # descdb(dfpivot) # clsnewnew = clsnew + ['有效月均', '年总金额'] # dfout = dfpivot[(dfpivot.有效月均 > 300) | (dfpivot.首交月数 < 5)] # print(dfout[dfout.首交月数 < 5]) dfout = dfpivot # dfshow = dfout.loc[:, clsnewnew] dfshow = dfout.loc[:, :] dfshow.fillna(0, inplace=True) for cl in cls: dfshow[cl] = dfshow[cl].astype(int) # print(dfshow[dfshow.类型 == 'I']) # descdb(dfshow) cnx = lite.connect(dbpathworkplan) # dfshow.to_sql('tmptable', cnx, index=True, if_exists='replace') cursor = cnx.cursor() cursor.execute(f'attach database \'{dbpathquandan}\' as \'C\'') dfquyu = pd.read_sql('select * from C.quyu', cnx, index_col='index') dfquyu.drop_duplicates(['区域'], keep='first', inplace=True) dfquyu.index = dfquyu['区域'] del dfquyu['区域'] # descdb(dfquyu) dfleixing = pd.read_sql('select * from C.leixing', cnx, index_col='index') dfleixing.index = dfleixing['编码'] del dfleixing['编码'] # descdb(dfleixing) dfshow['区域名称'] = dfshow['区域'].apply(lambda x: dfquyu.loc[x][0]) # print(dfshow[dfshow.类型 == '0']) dfshow['类型小类'] = dfshow['类型'].apply(lambda x: dfleixing.loc[x][0]) dfshow['类型大类'] = dfshow['类型'].apply(lambda x: dfleixing.loc[x][1]) # descdb(dfshow) cnx.close() writer = pd.ExcelWriter(str(dirmainpath / 'data' / '客户销售总表.xlsx')) dfzhongduan = dfshow[dfshow.类型大类 == '终端客户'] # dfzhongduan.to_excel('test4kehuquandan.xlsx') # print(dfzhongduan.dtypes) # print(dfzhongduan.head(5)) pd.DataFrame(dfzhongduan).to_excel(writer, sheet_name='客户销售全单') log.info('成功输出《客户销售全单》') writer.close() # descdb(dfzhongduan) targetlist = list() dfzdall = dfzhongduan.loc[:, :] # descdb(dfzdall) notestore = get_notestore() quyuset = set(dsquyuzuixinriqi.apply(lambda x: dfquyu.loc[x][0]).values) print(quyuset) # quyuset = set(list(dfzdall['区域名称'])) for qy in quyuset: dfslice = dfzdall[dfzdall.区域名称 == qy] dfslicesingle = dfslice.loc[:, :] del dfslicesingle['区域名称'] # descdb(dfslicesingle) print(qy, end='\t') print(dfslicesingle.shape[0], end='\t') # descdb(dfslicesingle) if cfpdata.has_option('guidquyunb', qy): nbguid = cfpdata.get('guidquyunb', qy) else: try: notebook = ttypes.Notebook() notebook.name = qy notebook = notestore.createNotebook(notebook) nbguid = notebook.guid cfpdata.set('guidquyunb', qy, nbguid) cfpdata.write(open(inidatanotefilepath, 'w', encoding='utf-8')) except OSError as eeeee: nbguid = None log.critical(f'创建《{qy}》笔记本时出现错误。{eeeee}') print(nbguid, end='\t') if cfpdata.has_option('ordersaleguidquyu', qy + 'guid'): ntguid = cfpdata.get('ordersaleguidquyu', qy + 'guid') else: try: note = ttypes.Note() note.title = qy + "订单金额年度分析" note.content = '<?xml version="1.0" encoding="UTF-8"?>' \ '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">' note.content += '<en-note>专营休闲美食</en-note>' note.notebookGuid = nbguid note = notestore.createNote(note) evernoteapijiayi() ntguid = note.guid cfpdata.set('ordersaleguidquyu', qy + 'guid', ntguid) cfpdata.write(open(inidatanotefilepath, 'w', encoding='utf-8')) except OSError as ee: ntguid = None log.critical(f'创建《{qy}订单金额年度分析》笔记时出现错误。{ee}') print(ntguid) target = list() target.append(qy) target.append(ntguid) target.append(dfslicesingle) targetlist.append(target) # descdb(dfshow[dfshow.index.str.find('XF') >= 0]) lqzlist = [['连锁客户', '0e8ba322-4874-4627-a6de-13c69fffc88d'], ['渠道客户', '4AC03027-5929-415B-9711-0A8170263189'.lower()], ['直销客户', 'B0731D74-C268-417E-A8B7-7BE3EE590FAE'.lower()] ] for [mingmu, mmguid] in lqzlist: dfls = dfshow.loc[:, :] dfls = dfls[dfls.类型大类 == mingmu] # dfls = dfls[str(dfls.index)[7:9] == 'XF'] del dfls['类型大类'] dfls.sort_values(['有效月均'], ascending=False, inplace=True) target = list() target.append(mingmu) target.append(mmguid) target.append(dfls) targetlist.append(target) lslist = [['学府超市', 'XF', 'ce26a763-81cc-421f-8430-22dab21ba43e'], ['红生超市', 'HS', '1F0995DA-1DEC-4333-8EA6-8C85B54E2B71'.lower()], ['五分钟', 'WF', '41518B63-FF81-4719-BFE0-0E5BBFBC295A'.lower()] ] for [mingcheng, bianma, guid] in lslist: dfls = dfshow.loc[:, :] dfls = dfls[dfls.index.str.find(bianma) >= 0] del dfls['类型大类'] if dfls.shape[0] == 0: log.info(f'连锁超市{mingcheng}没有数据记录,跳过') continue dfls.sort_values(['有效月均'], ascending=False, inplace=True) target = list() target.append(mingcheng) target.append(guid) target.append(dfls) targetlist.append(target) # print(targetlist) for [qy, ntguid, dfslicesingle] in targetlist: try: dfzdclnames = list(dfslicesingle.columns) # print(dfzdclnames) dfzdclnames3 = dfzdclnames[3:16] dfzdclnamesnew = [dfzdclnames[0]] + [dfzdclnames[-2]] + dfzdclnames3 + [dfzdclnames[23]] + [dfzdclnames[22]] # print(dfzdclnamesnew) stattitle = f'总客户:{dfslicesingle.shape[0]},' \ f'在线客户(前三个月有成交记录):{dfslicesingle[dfslicesingle.尾交月数 <= 4].shape[0]},' \ f'本月成交客户:{dfslicesingle[dfslicesingle.尾交月数 == 1].shape[0]}' imglist2note(notestore, [], ntguid, qy + '订单金额年度分析', tablehtml2evernote(dftotal2top(dfslicesingle.loc[:, dfzdclnamesnew]), stattitle, withindex=False, setwidth=False)) cfpdata.set('ordersaleguidquyu', qy + 'count', f'{dfslicesingle.shape[0]}') cfpdata.write(open(inidatanotefilepath, 'w', encoding='utf-8')) log.info(f'{qy}数据项目成功更新') except OSError as eee: log.critical(f'《{qy}订单金额年度分析》笔记更新时出现错误。{eee}') # print(dfslicesingle.shape[0]) else: cfpdata.set('ordersaleguidquyu', '数据最新日期', f'{zuijinchengjiaori}') cfpdata.write(open(inidatanotefilepath, 'w', encoding='utf-8'))