def showiprecords(): """ 综合输出ip记录 """ namestr = 'everip' ip, wifi, wifiid, tun, device_id = iprecord() if ip is None: logstr = '无效ip,可能是没有处于联网状态' log.critical(logstr) sys.exit(1) print(f'{ip}\t{wifi}\t{wifiid}\t{tun}\t{device_id}') if not (guid := getcfpoptionvalue(namestr, device_id, 'guid')): token = getcfpoptionvalue('everwork', 'evernote', 'token') note_store = get_notestore() parentnotebook = note_store.getNotebook( '4524187f-c131-4d7d-b6cc-a1af20474a7f') evernoteapijiayi() note = ttypes.Note() note.title = f'服务器_{device_id}_ip更新记录' # note.title = "hengchu" print(note.title) note = makenote(token, note_store, note.title, notebody='', parentnotebook=parentnotebook) guid = note.guid setcfpoptionvalue(namestr, device_id, 'guid', guid)
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 wifitodf(itemstr, noteinfolistw): itemstrjoin = '\n'.join(itemstr) pattern = re.compile( '(?:Device )((?:dis)?connected) (?:to|from) ([\w|-]+), (\w+ \d+, \d{4} at \d{2}:\d{2}[A|P]M)' ) slices = re.split(pattern, itemstrjoin) items_split = [] for i in range(int(len(slices) / 4)): zhizi = list() zhizi.append( datetime.datetime.strptime(slices[i * 4 + 3], '%B %d, %Y at %I:%M%p')) if slices[i * 4 + 1].startswith('dis'): zhizi.append(False) else: zhizi.append(True) zhizi.append(slices[i * 4 + 2].lower()) items_split.append(zhizi) dfwifiall = pd.DataFrame(items_split, columns=('atime', 'entered', 'name')) dfwifiall.drop_duplicates(inplace=True) dfwifiall.sort_values(['atime'], ascending=False, inplace=True) dfwifiall.index = dfwifiall['atime'] dfwifilist = list() for item in items_split: for [_, address, shuxing, *arg, wifilist] in noteinfolistw: if item[2] in wifilist: item.append(shuxing) address1 = address if item[0] > pd.to_datetime('2017-01-09'): if address.startswith('wenchanglu'): address1 = 'maotanhuamushichang' else: if address.startswith('maotanhuamushichang'): address1 = 'wenchanglu' item.append(address1) dfwifilist.append(item) break dfwifi = pd.DataFrame(dfwifilist, columns=('atime', 'entered', 'name', 'shuxing', 'address')) dfwifi.drop_duplicates(inplace=True) # descdb(dfwifi) dfwifi.sort_values(['atime'], ascending=False, inplace=True) dfwifi.index = dfwifi['atime'] del dfwifiall['atime'] dfout = dfwifi[['entered', 'shuxing', 'address']] # descdb(dfout) try: notestore = get_notestore() dfnotename = dfwifi[['entered', 'shuxing', 'address']] dfwificount = dfwifi.shape[0] # shape[0]获得行数,shape[1]则是列数 print(dfwificount, end='\t') if (dfwificountini := getcfpoptionvalue('everlife', 'wifi', 'itemnumber')): # 新数据集记录数和存档比较 ntupdatenum = dfwificount > dfwificountini else:
def gettitleandcontent(ntguid: str): ns = get_notestore() nttitle = ns.getNote(ntguid, False, False, False, False).title evernoteapijiayi() ntcontent = ns.getNoteContent(ntguid) evernoteapijiayi() return nttitle, ntcontent
def checknewthenupdatenote(): """ 查验程序文件是否有更新(文件时间作为判断标准)并更新至笔记 """ nbdf = findnotebookfromevernote() ttt = list() findfilesincluedef(getdirmain(), ttt, '.py') ptnfiledesc = re.compile(r"(?:^\"\"\"(.*?)\"\"\"$)", re.MULTILINE | re.DOTALL) ptnnamedesc = re.compile( r"""^def\s+((?:\w+)\(.*?\))\s*:\s*\n (?:\s+\"\"\"(.*?)\"\"\")?""", re.MULTILINE | re.DOTALL) protitle = 'p_ew_' netnblst = list(nbdf.名称) for fn in ttt: nbnamelst = fn.rsplit('/', 1) if len(nbnamelst) == 1: nbnamelst.insert(0, 'root') nbnamelst[0] = protitle + nbnamelst[0] # ['p_ew_jpy', 'chuqin.py'] nbname, filename = nbnamelst[0], nbnamelst[1] if (ennotetime := getcfpoptionvalue('evercode', nbname, filename)) is None: # 获取笔记本的guid,笔记本不存在则构建之 if (nbguid := getcfpoptionvalue('evercode', nbname, 'guid')) is None: logstr = f"笔记本《{nbname}》在ini中不存在,可能需要构造之。" log.info(logstr) if nbname in netnblst: nbguid = nbdf[nbdf.名称 == nbname].index.values[0] # print(nbguid) else: notebook = createnotebook(nbname) netnblst.append(nbname) nbguid = notebook.guid setcfpoptionvalue('evercode', nbname, "guid", nbguid) # 获取笔记的guid,笔记不存在则构建之 if (noteguid := getcfpoptionvalue('evercode', nbname, f'{filename}_guid')) is None: logstr = f"笔记《{filename}》在ini中不存在,可能需要构造之。" log.info(logstr) items = findnotefromnotebook(nbguid, filename) if len(items) > 0: # [noteguid, notetitle, note.updateSequenceNum] noteguid = items[-1][0] else: note = makenote(gettoken(), get_notestore(), filename, parentnotebook=nbguid) noteguid = note.guid
def jilunote(noteinfos): """ 读取ifttt自动通过gmail转发至evernote生成的地段进出记录,统计作图展示 :rtype: Null """ # itemstr = BeautifulSoup(get_notestore().getNoteContent(noteinfos[0]), "html.parser"). \ # get_text().replace('\r', '').replace('\n', '') # 文本化后去掉回车、换行符等 itemstr = BeautifulSoup(get_notestore().getNoteContent(noteinfos[0]), "html.parser"). \ get_text().split('\r\n') # 文本化后去掉回车、换行符等,通过split转换为list # print('笔记:"%s" 中提取内容' %noteinfos[5]) # print(itemstr) evernoteapijiayi() return itemstr
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 log2notes(): namestr = 'everlog' device_id = getdeviceid() token = getcfpoptionvalue('everwork', 'evernote', 'token') # log.info(token) if not (logguid := getcfpoptionvalue(namestr, device_id, 'logguid')): 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) logguid = notelog.guid setcfpoptionvalue(namestr, device_id, 'logguid', logguid)
def chuliholidayleave_note(zhuti: list): # global note_store note_store = get_notestore() # print(zhuti) guid = getcfpoptionvalue('everworkplan', '行政管理', f'{zhuti[0]}guid') @trycounttimes2('evernote服务器') def getnote(guidin): notein = note_store.getNote(guidin, True, True, False, False) evernoteapijiayi() return notein note = getnote(guid) # print(timestamp2str(int(note.updated/1000))) # print(note.updateSequenceNum) if not (updatenumold := getcfpoptionvalue('everworkplan', '行政管理', f'{zhuti[0]}updatenum')): updatenumold = 0
def getweatherfromevernote(): noteguid_weather = '277dff5e-7042-47c0-9d7b-aae270f903b8' note_store = get_notestore() soup = BeautifulSoup(note_store.getNoteContent(noteguid_weather), "html.parser") # evernoteapijiayi() # tags = soup.find('en-note') # print tags # print soup.get_text() pattern = u'(\w*\s*\d+,\s*\d{4}\s*at\s*\d{2}:\d{2}[AP]M)\s+' weatherslice = re.split(pattern, soup.get_text()) # print len(slice) split_item = [] for i in range(1, len(weatherslice), 2): split_item.append(weatherslice[i] + " " + weatherslice[i + 1]) print(split_item) return split_item
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
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 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, '武汉天气图')
print(f'日志的{levelstr4title}记录共有{len(loglines)}条,只取时间最近的{loglimit}条') 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()
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()
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执行完毕')
# %% @set_timeout(360, after_timeout) @timethis def foot2show(df4dis): """ 展示足迹 """ namestr = 'everloc' if (device_id := getcfpoptionvalue(namestr, namestr, 'device_id')) is None: device_id = getdeviceid() setcfpoptionvalue(namestr, namestr, 'device_id', device_id) device_id = str(device_id) if (guid := getcfpoptionvalue(namestr, device_id, 'guid')) is None: token = getcfpoptionvalue('everwork', 'evernote', 'token') note_store = get_notestore() parentnotebook = note_store.getNotebook( '4524187f-c131-4d7d-b6cc-a1af20474a7f') evernoteapijiayi() # note = ttypes.Note() title = f'手机_{device_id}_location更新记录' # note.title = "hengchu" print(title) note = makenote(token, note_store, title, notebody='', parentnotebook=parentnotebook) guid = note.guid setcfpoptionvalue(namestr, device_id, 'guid', guid)
def pinpaifenxi(cnxp, daysbefore=90, brandnum=30, fenbu='fenbu'): cursor = cnxp.cursor() cursor.execute(f'attach database \'{dbpathdingdanmingxi}\' as \'C\'') qrypinpai = "select max(日期) as 最近日期, sum(金额) as 销售金额, product.品牌名称 as 品牌 , " \ "product.推广等级 as 等级 from C.orderdetails,product " \ "where (product.商品全名 = C.orderdetails.商品全名) and (等级 > 2) group by 品牌 order by 最近日期" dff = pd.read_sql_query(qrypinpai, cnxp, parse_dates=['最近日期']) cursor.execute('detach database \'C\'') cursor.close() # print(dff) brandlist = list( dff[dff.最近日期 >= (dff.最近日期.max() + pd.Timedelta(days=daysbefore * (-1)))]['品牌']) print(brandlist) # dfbrand = pd.read_sql_query('select 品牌名称, max(推广等级) as 等级 from product group by 品牌名称 order by 等级 desc', cnxp) # # print(dfbrand) # brandlist = list(dfbrand[dfbrand.等级 > 2]['品牌名称'])[::-1] # print(brandlist) if len(brandlist) > brandnum: brandlist = brandlist[brandnum * (-1):] # brandlist = list(dff['品牌']) brandlist.append('') print(brandlist) note_store = get_notestore() token = getcfpoptionvalue('everwork', 'evernote', 'token') for br in brandlist: log.info('第%d个品牌:%s,共有%d个品牌' % (brandlist.index(br) + 1, br, len(brandlist))) updatesection(cfpdata, 'guid%snb' % fenbu, br + 'kehuguid%s' % fenbu, inidatanotefilepath, token, note_store, br + '客户开发图表') updatesection(cfpdata, 'guid%snb' % fenbu, br + 'saleguid%s' % fenbu, inidatanotefilepath, token, note_store, br + '销售业绩图表') updatesection(cfpdata, 'guidleixingnb', br + 'kehuguidleixing', inidatanotefilepath, token, note_store, br + '客户开发图表') updatesection(cfpdata, 'guidleixingnb', br + 'saleguidleixing', inidatanotefilepath, token, note_store, br + '销售业绩图表') # notelxxsdf = [''] notelxxsdf = readinisection2df(cfpdata, br + 'saleguidleixing', br + '销售图表') notefbxsdf = readinisection2df(cfpdata, br + 'saleguid%s' % fenbu, br + '销售图表') # print(notefbxsdf) qrystr = "select 日期,strftime('%%Y%%m',日期) as 年月,customer.往来单位编号 as 客户编码," + \ 'sum(金额) as %s, substr(customer.往来单位编号,1,2) as 区域 ,substr(customer.往来单位编号,12,1) as 类型, ' \ 'product.品牌名称 as 品牌 from xiaoshoumingxi, customer, product ' \ 'where (customer.往来单位 = xiaoshoumingxi.单位全名) and (product.商品全名 = xiaoshoumingxi.商品全名) ' \ '%s %s group by 日期,客户编码 order by 日期' # % (xmclause,jineclause, brclause) xiangmu = ['销售金额', '退货金额'] fenxiyueduibi(qrystr, xiangmu, notefbxsdf, notelxxsdf, cnxp, pinpai=br, cum=True) # fenximonthduibi(token, note_store, cnxp, notefbxsdf, notelxxsdf, '金额', pinpai=br, cum=True) # notelxkhdf = [''] notelxkhdf = readinisection2df(cfpdata, br + 'kehuguidleixing', br + '客户图表') notefbkhdf = readinisection2df(cfpdata, br + 'kehuguid%s' % fenbu, br + '客户图表') # print(notefbkhdf) qrystr = "select 日期,strftime('%%Y%%m',日期) as 年月,customer.往来单位编号 as 客户编码," + \ 'count(*) as %s, substr(customer.往来单位编号,1,2) as 区域 ,' \ 'substr(customer.往来单位编号,12,1) as 类型, ' \ 'product.品牌名称 as 品牌 from xiaoshoumingxi, customer, product ' \ 'where (customer.往来单位 = xiaoshoumingxi.单位全名) and (product.商品全名 = xiaoshoumingxi.商品全名) ' \ '%s %s group by 日期,客户编码 order by 日期' # % (xmclause,jineclause, brclause) xiangmu = ['销售客户数', '退货客户数'] fenxiyueduibi(qrystr, xiangmu, notefbkhdf, notelxkhdf, cnxp, pinpai=br)
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)
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()
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()
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 updatedb_workplan(note_store, persons): # global dbpathworkplan, token, cfp, cfpworkplan cnxp = lite.connect(dbpathworkplan) tablename_plan = 'personplan' tablename_updated = 'planupdated' try: liuxin = 5 for person in persons: # print(person) # if person != '梅富忠': # continue guid = cfpworkplan.get('业务计划总结guid', person).lower() # print(guid) if note_store is None: note = get_notestore().getNote(guid, True, True, False, False) log.debug(f'处理{person}日志时notestore失效,重构一个再来。') else: note = note_store.getNote(guid, True, True, False, False) evernoteapijiayi() # print(timestamp2str(int(note.updated/1000))) # print(note.updateSequenceNum) if cfpworkplan.has_option('业务计划总结updatenum', person): usnini = cfpworkplan.getint('业务计划总结updatenum', person) updatable = note.updateSequenceNum > usnini else: usnini = 0 updatable = True if updatable is False: log.info(f'{person}的工作日志本轮查询中无更新,跳过。') continue verlist = note_store.listNoteVersions(token, guid) # 历史版本,不含当前最新版本 evernoteapijiayi() # 当前版本和历史版本组成轮训池 usnlist = [note.updateSequenceNum] + [ x.updateSequenceNum for x in verlist if x.updateSequenceNum > usnini ] # print(f'{note.updateSequenceNum}\t{usnini}\t{usnlist}') log.info(f'业务主管{person}的日志有更新,版本号列表为:{usnlist}') for verusn in usnlist[::-1]: # 倒过来,从最早的笔记版本开始处理 if verusn == note.updateSequenceNum: vernote = note else: vernote = note_store.getNoteVersion( token, guid, verusn, True, True, True) evernoteapijiayi() soup = BeautifulSoup(vernote.content, "html.parser").get_text().strip() planitems = chulinote_workplan(soup) # print(planitems[:3]) if len(planitems) == 0: log.info('%s业务日志中无有效日志记录,跳过。' % person) continue # 通过已存储项目的日期(如果没有就默认是当前项目列表最早日期的前一天)截取需要处理的项目并追加到相应数据表中 sqlstr = 'select max(date) from %s where name=\'%s\'' % ( tablename_plan, person) dftmp = pd.read_sql(sqlstr, cnxp) datemaxdb = pd.to_datetime(dftmp.iloc[0, 0]) print(f'{person}的日志数据表中最新条目日期为{datemaxdb}') if datemaxdb is None: datemaxdb = planitems[-1][0] + datetime.timedelta(days=-1) planitemsxinxiancount = 0 for i in range(len(planitems)): planitemsxinxiancount += 1 if planitems[i][0] <= datemaxdb: break baddate = False for i in range(1, planitemsxinxiancount): # 逐项检查,看是否有时间倒序问题存在 baddate |= planitems[i - 1][0] < planitems[i][0] if baddate: log.critical( f'{person}业务日志(版本号:{verusn})中存在日期倒置:{planitems[i - 1][0]},位于第{i}条。跳过。' ) break if baddate: continue if len(planitems) > liuxin: # 固化内容存储,预留5天可修改,随着记录更新追加到数据表中 dfrizhi = pd.DataFrame(planitems, columns=['date', 'content']) dfrizhi['name'] = person dfrizhi = dfrizhi[['name', 'date', 'content']] dfrizhi.sort_values(['date'], inplace=True) # 升序排列 dfrizhichuli = dfrizhi[dfrizhi.date > datemaxdb] # 取尾部记录 # print(dfrizhichuli) if dfrizhichuli.shape[0] > liuxin: dfrizhiappend = dfrizhichuli[:dfrizhichuli.shape[0] - liuxin] # 取头部 dfrizhiappend.to_sql(tablename_plan, cnxp, index=False, if_exists='append') log.info( f'{person}的业务日志有{dfrizhiappend.shape[0]}条追加到日志内容表中,最新日期为:{datemaxdb}' ) sqlstr = 'select max(date) from %s where name=\'%s\'' % ( tablename_updated, person) dftmp = pd.read_sql(sqlstr, cnxp) datemaxdb = pd.to_datetime(dftmp.iloc[0, 0]) if datemaxdb is None: datemaxdb = planitems[-1][0] + datetime.timedelta(days=-1) print(f'{person}的日志更新数据表中最近有效日期为{datemaxdb}') dfitems = pd.DataFrame(planitems, columns=['date', 'content']) dfadd = dfitems[dfitems.date > datemaxdb] if dfadd.shape[0] > 0: print(dfadd) else: log.info( f'{person}业务日志(版本号:{verusn})暂无有效新内容,最新有效日期为{planitems[0][0]}' ) continue itemss = list() for ix in dfadd.index: item = list() item.append(person) datestr = datetime.date.strftime(dfadd.loc[ix, 'date'], '%Y-%m-%d') item.append(datestr) item.append(dfadd.loc[ix, 'date']) item.append(dfadd.loc[ix, 'content']) item.append(len(dfadd.loc[ix, 'content'])) item.append(timestamp2str(int(vernote.updated / 1000))) itemss.append(item) dfupdate = pd.DataFrame(itemss, columns=[ 'name', 'nianyueri', 'date', 'content', 'contentlength', 'updatedtime' ]) print(dfupdate) dfupdate.to_sql(tablename_updated, cnxp, index=False, if_exists='append') log.info(f'{person}的业务日志有{dfupdate.shape[0]}条追加到日志内容表中') cfpworkplan.set('业务计划总结updatenum', person, '%d' % verusn) cfpworkplan.write(open(iniworkplanpath, 'w', encoding='utf-8')) else: log.info('下列人员的日志笔记正常处置完毕:%s' % persons) except Exception as eee: log.critical('读取工作日志笔记更新入日志内容表和日志更新表时发生错误。%s' % str(eee)) finally: cnxp.close()
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 chulioldversion(): note_store = get_notestore() notes = findnotefromnotebook(token, '2c8e97b5-421f-461c-8e35-0f0b1a33e91c', '业务推广') for ii in range(len(notes)): note = notes[ii] guid = note[0] titles = note[1].split('—') if len(titles) >= 2: person = titles[-1] print('%s\t%s' % (person, guid)) # if person != '黄壮': #开关,某人记录未读完是专项处理 # continue else: continue verlist = note_store.listNoteVersions(token, guid) evernoteapijiayi() print(len(verlist)) print(verlist[0]) # NoteVersionId(updateSequenceNum=472609, updated=1527677247000, saved=1527682577000, # title='业务推广日工作总结和计划——徐志伟') items = [] note_store = get_notestore() for ver in verlist: print( f'{ver.updateSequenceNum}\t{timestamp2str(int(ver.updated / 1000))}' f'\t{timestamp2str(int(ver.saved / 1000))}') try: # if ver.updateSequenceNum >= 349273: #开关,断点续传 # continue notever = note_store.getNoteVersion(token, guid, ver.updateSequenceNum, True, True, True) evernoteapijiayi() except Exception as eeee: log.critical('%s业务日志读取版本%d中时出现错误,终止操作进入下一轮。%s' % (person, ver.updateSequenceNum, str(eeee))) break soup = BeautifulSoup(notever.content, "html.parser").get_text().strip() planitems = chulinote_workplan(soup) if len(planitems) == 0: log.info('%s业务日志版本%d中无有效日志记录,跳过此版本。' % (person, ver.updateSequenceNum)) continue item = list() item.append(person) datestr = datetime.date.strftime(planitems[0][0], '%Y-%m-%d') item.append(datestr) item.append(planitems[0][0]) item.append(planitems[0][1]) item.append(len(planitems[0][1])) item.append(timestamp2str(int(notever.updated / 1000))) items.append(item) print(items) cnxp = lite.connect(dbpathworkplan) tablename_updated = 'planupdated' dfupdate = pd.DataFrame(items, columns=[ 'name', 'nianyueri', 'date', 'content', 'contentlength', 'updatedtime' ]) dfupdate.to_sql(tablename_updated, cnxp, index=False, if_exists='append') cnxp.close()
log.info(logstr) itemnewr = [f'{ipr}\t{wifir}\t{wifiidr}\t{tunr}\t{startr}\t{nowstr}'] itemnewr.extend(itemclean) # print(itemnewr) write2txt(txtfilename, itemnewr) 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__': logstr2 = f'开始运行文件\t{__file__}\t{sys._getframe().f_code.co_name}\t{sys._getframe().f_code.co_filename}' log.info(logstr2) showiprecords() # print(f"{self.__class__.__name__}") logstr1 = f'文件\t{__file__}\t执行完毕' log.info(logstr1)
from func.logme import log from func.nettools import trycounttimes2 # ###### 提取ini数据,用于对比 guidchuli = getcfpoptionvalue('everpim', "noteguid", 'noteguid') len(guidchuli.split(',')) # ###### 获取笔记列表 notelst = findnotefromnotebook("39625f3f-8ee7-486b-ab73-e6ca4f325be6", titlefind="", notecount=300) len(notelst) ns = get_notestore() ntguid = notelst[5][0] # ###### `splitcontentfromnotemysms` def splitcontentfromnotemysms(noteguid: str): @trycounttimes2('evernote服务器') def gettitleandcontent(ntguid: str): ns = get_notestore() nttitle = ns.getNote(ntguid, False, False, False, False).title evernoteapijiayi() ntcontent = ns.getNoteContent(ntguid) evernoteapijiayi() return nttitle, ntcontent
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 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)