def checktable(dbpath: str, ownername: str): """ 检查数据表是否存在并根据情况创建 """ if not (ifcreated := getcfpoptionvalue('everwebchat', 'wcdb', ownername)): print(ifcreated) dbnameinner = getdbname(dbpath, ownername) tablename = "wcheadimg" if istableindb(tablename, dbnameinner): # 删表操作,危险,谨慎操作 droptablefromdb(dbnameinner, tablename, confirm=True) csql = f"create table if not exists {tablename} (himgid INTEGER PRIMARY KEY AUTOINCREMENT,username TEXT not null, himguuid TEXT NOT NULL UNIQUE ON CONFLICT IGNORE, headimg BLOB NOT NULL)" ifnotcreate(tablename, csql, dbnameinner) logstr = f"数据表{tablename}于{dbnameinner}中被删除并完成重构" log.critical(logstr) tablename_cc = "wccontact" if istableindb(tablename_cc, dbnameinner): # 删表操作,危险,谨慎操作 droptablefromdb(dbnameinner, tablename_cc, confirm=True) csql = f"create table if not exists {tablename_cc} (id INTEGER PRIMARY KEY AUTOINCREMENT, contactuuid TEXT NOT NULL UNIQUE ON CONFLICT IGNORE, nickname TEXT, contactflag int, remarkname TEXT, sex int, signature TEXT, starfriend int, attrstatus int, province TEXT, city TEXT, snsflag int, keyword TEXT, imguuid text, appendtime datatime)" ifnotcreate(tablename_cc, csql, dbnameinner) logstr = f"数据表{tablename_cc}于{dbnameinner}中被删除并完成重构" log.critical(logstr) setcfpoptionvalue('everwebchat', 'wcdb', ownername, str(True))
def getnotelist(name, wcpath, notebookguid): """ 根据传入的微信账号名称获得云端记录笔记列表 """ notelisttitle = f"微信账号({name})记录笔记列表" loginstr = "" if (whoami := execcmd("whoami")) and ( len(whoami) == 0) else f",登录用户:{whoami}" timenowstr = pd.to_datetime(datetime.now()).strftime("%F %T") if (notelistguid := getcfpoptionvalue('everwcitems', "common", f"{name}_notelist_guid")) is None: findnotelst = findnotefromnotebook(notebookguid, notelisttitle, notecount=100) if len(findnotelst) == 1: notelistguid = findnotelst[0][0] log.info(f"文件列表《{notelisttitle}》的笔记已经存在,取用") else: nrlst = list() nrlst.append(f"账号\t{name}\n笔记数量\t-1") # 初始化内容头部,和正常内容头部格式保持一致 nrlst.append("") nrlst.append( f"\n本笔记创建于{timenowstr},来自于主机:{getdevicename()}{loginstr}") note_body_str = '\n---\n'.join(nrlst) note_body = f"<pre>{note_body_str}</pre>" notelistguid = makenote2(notelisttitle, notebody=note_body, parentnotebookguid=notebookguid).guid log.info(f"文件列表《{notelisttitle}》被首次创建!") setcfpoptionvalue('everwcitems', "common", f'{name}_notelist_guid', str(notelistguid))
def chuliweixinzhifuzhangdan(dmpath): """ 处理“微信支付账单”文件,生成DataFrame输出 """ file_list = os.listdir(dmpath) # print(file_list) fnlst = [ x for x in file_list if (x.startswith('微信支付账单') and ( x.endswith('csv') or x.endswith('xlsx'))) ] fnlst.sort(key=lambda fn: os.path.getmtime(dmpath / fn)) rstdf = pd.DataFrame() for fn in fnlst: if not (filerecorded := getcfpoptionvalue('everwebchat', 'wczhifufile', str(fn))): if fn.endswith('.csv'): singledf = pd.read_csv(dmpath / fn, header=16, parse_dates=True) elif fn.endswith('.xlsx'): content = xlrd.open_workbook(filename=dmpath / fn) singledf = pd.read_excel(content, header=16, parse_dates=True, engine='xlrd') else: logstr = f"读取《微信支付账单》文件时失败:\t{fn}" log.critical(logstr) continue rstdf = rstdf.append(singledf, ignore_index=True) print(rstdf.shape[0], end='\t') setcfpoptionvalue('everwebchat', 'wczhifufile', str(fn), str(True))
def phonesms2db(): """ 手机短信数据入库 """ if not (phonecontactdb := getcfpoptionvalue('everpim', str(getdeviceid()), 'smsfirstrun')): readnum = 50000
def updatewcitemsxlsx2note(name, dftest, wcpath, notebookguid): """ 处理从本地资源文件读取生成的df,如果和ini登记数量相同,则返回;如果不同,则从笔记端读取相应登记 数量再次对比,相同,则跳过,如果不同,则拉取笔记资源文件和本地资源文件融合,更新笔记端资源文件并 更新ini登记数量(用融合后的记录数量) """ ny = dftest['time'].iloc[0].strftime("%y%m") dftfilename = f"wcitems_{name}_{ny}.xlsx" dftallpath = wcpath / dftfilename dftallpathabs = os.path.abspath(dftallpath) print(dftallpathabs) loginstr = "" if (whoami := execcmd("whoami")) and ( len(whoami) == 0) else f",登录用户:{whoami}" timenowstr = pd.to_datetime(datetime.now()).strftime("%F %T") if (dftfileguid := getcfpoptionvalue('everwcitems', dftfilename, 'guid')) is None: findnotelst = findnotefromnotebook(notebookguid, dftfilename, notecount=1) if len(findnotelst) == 1: dftfileguid = findnotelst[0][0] log.info(f"数据文件《{dftfilename}》的笔记已经存在,取用") else: first_note_desc = f"账号\t{None}\n记录数量\t-1" # 初始化内容头部,和正常内容头部格式保持一致 first_note_body = f"<pre>{first_note_desc}\n---\n\n本笔记创建于{timenowstr}," \ f"来自于主机:{getdevicename()}{loginstr}</pre>" dftfileguid = makenote2(dftfilename, notebody=first_note_body, parentnotebookguid=notebookguid).guid setcfpoptionvalue('everwcitems', dftfilename, 'guid', str(dftfileguid))
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 chulidataindir_orderdetails(pathorder: Path): notestr = '订单明细' cnxp = lite.connect(dbpathdingdanmingxi) tablename_order = 'orderdetails' sqlstr = "select count(*) from sqlite_master where type='table' and name = '%s'" % tablename_order tablexists = pd.read_sql_query(sqlstr, cnxp).iloc[0, 0] > 0 if tablexists: # dfresult = pd.DataFrame() dfresult = pd.read_sql('select * from \'%s\'' % tablename_order, cnxp, parse_dates=['日期']) log.info('%s数据表%s已存在, 从中读取%d条数据记录。' % (notestr, tablename_order, dfresult.shape[0])) else: log.info('%s数据表%s不存在,将创建之。' % (notestr, tablename_order)) dfresult = pd.DataFrame() files = os.listdir(str(pathorder)) for fname in files: if fname.startswith(notestr) and (fname.endswith('xls') or fname.endswith('xlsx')): yichulifilelist = list() if (yichulifile := getcfpoptionvalue('everzysm', notestr, '已处理文件清单')): yichulifilelist = yichulifile.split() if fname in yichulifilelist: continue print(fname, end='\t') dffname = chulixls_orderdetails(pathorder / fname) if dffname is None: continue dfresult = dfresult.append(dffname) print(dffname.shape[0], end='\t') print(dfresult.shape[0]) yichulifilelist.append(fname) setcfpoptionvalue('everzysm', notestr, '已处理文件清单', '%s' % '\n'.join(yichulifilelist))
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 foot2record(): """ 记录位置数据(经纬度等) """ namestr = 'everloc' if (device_id := getcfpoptionvalue(namestr, namestr, 'device_id')): device_id = str(device_id)
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)
def df2db(dftest, name, wcpath): """ 把指定微信账号的记录df写入db相应表中 """ ny = dftest['time'].iloc[0].strftime("%y%m") dftfilename = f"wcitems_{name}_{ny}.xlsx" if (itemsnum_db := getcfpoptionvalue('everwcitems', dftfilename, 'itemsnum_db')) is None: itemsnum_db = 0
def formatmsg(msg): """ 格式化并重构msg,获取合适用于直观显示的用户名,对公众号和群消息特别处置 """ timetuple = time.localtime(msg['CreateTime']) timestr = time.strftime("%Y-%m-%d %H:%M:%S", timetuple) # print(msg['CreateTime'], timetuple, timestr) men_wc = getcfpoptionvalue('everwebchat', get_host_uuid(), 'host_nickname') # 信息延时登记入专门数据库文件 dbname = touchfilepath2depth(getdirmain() / "data" / "db" / f"wcdelay_{men_wc}.db") inserttimeitem2db(dbname, msg['CreateTime']) # owner = itchat.web_init() meu_wc = getcfpoptionvalue('everwebchat', get_host_uuid(), 'host_username') send = (msg['FromUserName'] == meu_wc) if 'NickName' in msg["User"].keys(): showname = msg['User']['NickName'] if len(msg['User']['RemarkName']) > 0: showname = msg['User']['RemarkName'] elif 'UserName' in msg['User'].keys(): showname = msg['User']['UserName'] elif 'userName' in msg['User'].keys(): showname = msg['User']['userName'] else: showname = "" log.warning(f"NickName或者UserName或者userName键值不存在哦") showmsgexpanddictetc(msg) # 过滤掉已经研究过属性公众号信息,对于尚未研究过的显示详细信息 ignoredmplist = getinivaluefromnote('webchat', 'ignoredmplist') imlst = re.split('[,,]', ignoredmplist) ismp = type(msg['User']) == itchat.storage.MassivePlatform if ismp and (showname not in imlst): showmsgexpanddictetc(msg) # print(f"{showname}\t{imlst}") # 处理群消息 if type(msg['User']) == itchat.storage.templates.Chatroom: isfrom = msg['FromUserName'].startswith('@@') isto = msg['ToUserName'].startswith('@@') # qunmp = isfrom or isto # showmsgexpanddictetc(msg) if isfrom: # print(f"(群)\t{msg['ActualNickName']}", end='') showname += f"(群){msg['ActualNickName']}" elif isto: # print(f"(群)\t{msg['User']['Self']['NickName']}", end='') showname += f"(群){msg['User']['Self']['NickName']}" # print(f"\t{msg['Type']}\t{msg['MsgType']}\t{msg['Text']}") # print(f"\t{send}\t{msg['Type']}\t{msg['Text']}") fmtext = msg['Text'] finnalmsg = {'fmId': msg['MsgId'], 'fmTime': timestr, 'fmSend': send, 'fmSender': showname, 'fmType': msg['Type'], 'fmText': fmtext} return finnalmsg
def fetchmjurlfromfile(ownername): """ fetch all zhanji urls from chatitems files """ ownpy = Pinyin().get_pinyin(ownername, '') datapath = getdirmain() / 'data' / 'webchat' datafilelist = os.listdir(datapath) print(datapath) resultlst = list() for filenameinner in datafilelist: if not filenameinner.startswith('chatitems'): continue filename = datapath / filenameinner rstlst = [] # 应对文本文件编码不同的情况 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: filelines = f.readlines() rstlstraw = [ inurl for line in filelines for inurl in splitmjurlfromtext(line) ] # drops the duplicates url rstlst = list(set(rstlstraw)) print(len(rstlst), len(rstlstraw), filename, dk) break except UnicodeDecodeError as eef: print(eef) continue except LookupError as eel: print(eel) if dk == 'Error': print(f"{filename}没办法用预设的字符集正确打开") break resultlst.extend(rstlst) resultlst = list(tuple(resultlst)) # print(resultlst[:10]) if (urlsnum := getcfpoptionvalue(f'evermuse_{ownpy}', ownername, 'urlsnum')): if urlsnum == len(resultlst): changed = False log.info(f"战绩链接数量暂无变化, till then is {len(resultlst)}.") else: changed = True urlsnumnew = len(resultlst) setcfpoptionvalue(f'evermuse_{ownpy}', ownername, 'urlsnum', f"{urlsnumnew}") log.info(f"战绩链接数 is set to {urlsnumnew} now.")
def extract_traceback4exception(tbtuple, func_name, sleeptime=None): """ 格式化指定异常的详细信息(tuple)并返回(字符串),默认只返回堆栈的首位各两个元素,除非显性指定显示全部 """ # by pass the recyle import, nit recommendded from func.configpr import getcfpoptionvalue # 通sys函数获取eee的相关信息 eee_type, eee_value, tblst = tbtuple if not (brief := getcfpoptionvalue("everinifromnote", "nettools", "brief")): brief = False
def checkbatteryinfotable(dbname: str, tablename: str): """ 检查设备的电池信息数据表是否已经构建,设置相应的ini值避免重复打开关闭数据库文件进行检查 """ if not (batteryinfocreated := getcfpoptionvalue('everhard', str(getdeviceid()), 'batteryinfodb')): print(batteryinfocreated) csql = f"create table if not exists {tablename} (appendtime int PRIMARY KEY, percentage int, temperature float)" ifnotcreate(tablename, csql, dbname) setcfpoptionvalue('everhard', str(getdeviceid()), 'batteryinfodb', str(True)) logstr = f"数据表{tablename}在数据库{dbname}中构建成功" log.info(logstr)
def splitjs(jsstr: str): """ 处理《计时工》原始打卡记录,规范成合规的时间间隔 :param jsstr: str :return: str """ zhongwuxiaban = getcfpoptionvalue('everinifromnote', 'xingzheng', 'zhongwuxiaban') xiawushangban = getcfpoptionvalue('everinifromnote', 'xingzheng', 'xiawushangban') xiawuxiaban = getcfpoptionvalue('everinifromnote', 'xingzheng', 'xiawuxiaban') # print(zhongwuxiaban, xiawushangban, xiawuxiaban) ptn = re.compile('\\d{2}:\\d{2}') findlst = re.findall(ptn, jsstr) if len(findlst) == 2: if (findlst[0] <= zhongwuxiaban) & (findlst[1] >= xiawushangban): findlst.insert(1, xiawushangban) findlst.insert(1, zhongwuxiaban) log.info(f"计时工打卡记录条目({len(findlst)})增补中午休息间隔\t{findlst}") elif (findlst[0] >= zhongwuxiaban) & (findlst[1] >= xiawushangban): log.info(f"计时工打卡记录条目({len(findlst)})属于正常下午班") elif (findlst[0] <= zhongwuxiaban) & (findlst[1] <= xiawushangban): log.info(f"计时工打卡记录条目({len(findlst)})属于正常上午班") else: log.critical(f"出现不合规范的计时工打卡记录({len(findlst)})\t{findlst}") findlst = None elif len(findlst) == 3: if findlst[0] <= zhongwuxiaban: findlst.insert(1, zhongwuxiaban) log.info(f"计时工打卡记录条目({len(findlst)})增补中午休息间隔\t{findlst}") else: log.critical(f"出现不合规范的计时工打卡记录({len(findlst)})\t{findlst}") findlst = None elif len(findlst) == 1: if findlst[0] <= zhongwuxiaban: findlst.append(zhongwuxiaban) log.info(f"计时工打卡记录条目({len(findlst)})增补中午休止\t{findlst}") elif findlst[0] >= zhongwuxiaban: findlst.append(xiawuxiaban) log.info(f"计时工打卡记录条目({len(findlst)})增补下午休止\t{findlst}") else: log.critical(f"出现不合规范的计时工打卡记录({len(findlst)})\t{findlst}") findlst = None elif len(findlst) == 4: pass elif len(findlst) != 0: log.critical(f"出现不合规范的计时工打卡记录({len(findlst)})\t{findlst}") findlst = None resultlst = findlst return resultlst
def checkwcdelaytable(dbname: str, tablename: str): """ 检查和dbname(绝对路径)相对应的延时数据表是否已经构建,设置相应的ini值避免重复打开关闭数据库文件进行检查 """ if (wcdelaycreated := getcfpoptionvalue( 'everwebchat', os.path.abspath(dbname), tablename)) is None: print(wcdelaycreated) csql = f"create table if not exists {tablename} (id INTEGER PRIMARY KEY AUTOINCREMENT, msgtime int, delay int)" ifnotcreate(tablename, csql, dbname) setcfpoptionvalue('everwebchat', os.path.abspath(dbname), tablename, str(True)) logstr = f"数据表{tablename}在数据库{dbname}中构建成功" log.info(logstr)
def checkphoneinfotable(dbname: str): """ 检查联系人和短信数据表是否已经构建,设置相应的ini值避免重复打开关闭数据库文件进行检查 """ # 联系人数据表检查构建 if not (phonecontactdb := getcfpoptionvalue('everpim', str(getdeviceid()), 'phonecontacttable')): tablename = "phone" print(phonecontactdb, tablename) csql = f"create table if not exists {tablename} (number str PRIMARY KEY not null unique on conflict ignore, name str, appendtime datetime)" ifnotcreate(tablename, csql, dbname) setcfpoptionvalue('everpim', str(getdeviceid()), 'phonecontacttable', str(True)) logstr = f"数据表{tablename}在数据库{dbname}中构建成功" log.info(logstr)
def txtdfsplit2xlsx(name, df, dpath, newfileonly=False): """ 按月份拆分指定账号的数据记录df,如果尚不存在本地相应资源文件,直接写入并更新ini中登记 数量;如果存在相应本地资源文件,则读取并融合df中的记录,存入对应格式化名称的excel表格 中,相应更新ini中登记数量 """ dftimestart = df['time'].min() dftimeend = df['time'].max() dr = getdaterange(dftimestart, dftimeend) if newfileonly: dr = dr[-2:] log.info(f"时间范围横跨{len(dr) - 1}个月") outlst = list() for i in range(len(dr) - 1): print( f"{'-' * 15}\t{name}\t【{i + 1}/{len(dr) - 1}】\tBegin\t{'-' * 15}") dfp = df[(df.time > dr[i]) & (df.time <= dr[i + 1])] if dfp.shape[0] != 0: ny = dfp['time'].iloc[0].strftime("%y%m") fn = f"wcitems_{name}_{ny}.xlsx" # 纯文件名称 fna = os.path.abspath(dpath / fn) # 全路径文件名(绝对路径) if not os.path.exists(fna): logstr = f"创建文件{fn},记录共有{dfp.shape[0]}条。" log.info(logstr) dfp.to_excel(fna, engine='xlsxwriter', index=False) setcfpoptionvalue('everwcitems', fn, 'itemsnumfromtxt', f"{dfp.shape[0]}") else: if (oldnum := getcfpoptionvalue('everwcitems', fn, 'itemsnumfromtxt')) is None: oldnum = 0 if oldnum != dfp.shape[0]: dftmp = pd.read_excel(fna) dfpall = dfp.append(dftmp).drop_duplicates().sort_values( ['time'], ascending=False) logstr = f"{fn}\t本地(文本文件)登记的记录数量为({oldnum}),但新文本文件中" \ f"记录数量({dfp.shape[0]})条记录," \ f"融合本地excel文件后记录数量为({dfpall.shape[0]})。覆盖写入所有新数据!" log.info(logstr) dfpall.to_excel(fna, engine='xlsxwriter', index=False) setcfpoptionvalue('everwcitems', fn, 'itemsnumfromtxt', f"{dfp.shape[0]}") else: print(f"{fn}已经存在,且文本文件中记录数量没有变化。") print(i, ny, dr[i], dr[i + 1], dfp.shape[0]) print( f"{'-' * 15}\t{name}\t【{i + 1}/{len(dr) - 1}】\tDone!\t{'-' * 15}")
def sharing_reply(msg): sendernick = getsendernick(msg) innermsg = formatmsg(msg) # showmsgexpanddictetc(msg) # 处理火界麻将战绩网页 # http://zj.lgmob.com/h5_whmj_qp/fks0_eb81c193dea882941fe13dfa5be24a11.html # ptn = re.compile("h5_whmj_qp/fks0_") # http://s0.lgmob.com/h5_whmj_qp/zhanji/index.php?id=fks0_eb81c193dea882941fe13dfa5be24a11 # ptn = re.compile("h5_whmj_qp/zhanji/index.php\\?id=") men_wc = getcfpoptionvalue('everwebchat', get_host_uuid(), 'host_nickname') msgurl = msg['Url'] print(msgurl) if (ulst := splitmjurlfromtext(msgurl)) and (len(ulst) > 0): if getinivaluefromnote("game", "forceupdateexcel"): descstr = '' for sp in ulst: tmpurl, tmpdescstr = geturlcontentwrite2excel(men_wc, sp) descstr += tmpdescstr else: descstr = updateurllst(men_wc, ulst) outstr = f"【Text】信息中发现新的火界麻将战绩网页链接并处理:\t{descstr}" itchat.send_msg(f'({sendernick})' + outstr) makemsg2write(innermsg, outstr) makemsg2write(innermsg, msgurl)
def fetch_dutyondata2lite(): zhutis = [['放假', 'holiday'], ['请假', 'leave'], ['打卡', 'checkin'], ['入职', 'dutyon'], ['高温', 'hot'], ['下雨', 'rain']] try: for zhuti in zhutis: dfresult = chuliholidayleave_note(zhuti) if zhuti[0] in ['高温', '下雨']: if zhuti[0] == '高温': dffromgd, dfallfromgd = getgaowenfromgoogledrive() dfresult = dfresult.append(dffromgd) dfresult.drop_duplicates(['hottime'], inplace=True) else: dffromgd, dfallfromgd = getrainfromgoogledrive() dfresult = dfresult.append(dffromgd) dfresult.drop_duplicates(['raintime'], inplace=True) countfromini = getcfpoptionvalue('everworkplan', '行政管理', f'{zhuti[0]}count') if not countfromini: countfromini = 0 if countfromini == dfresult.shape[0]: log.info(f"本轮查询没有发现新的《{zhuti[0]}》相关数据,跳过!") continue cnxp = lite.connect(dbpathworkplan) # index, ['mingmu', 'xingzhi', 'tianshu', 'date'] dfresult.to_sql(zhuti[1], cnxp, if_exists='replace', index=None) cnxp.close() log.info(f'{zhuti[0]}数据表更新了{dfresult.shape[0]}条记录。') setcfpoptionvalue('everworkplan', '行政管理', f'{zhuti[0]}count', f"{dfresult.shape[0]}") except OSError as exp: topic = [x for [x, *y] in zhutis] log.critical(f'从evernote获取{topic}笔记信息时出现未名错误。{exp}')
def showiprecords(): namestr = 'everip' ip, wifi, wifiid, tun, device_id = iprecord() if ip is None: log.critical('无效ip,可能是没有处于联网状态') exit(1) print(f'{ip}\t{wifi}\t{wifiid}\t{tun}\t{device_id}') if not (guid := getcfpoptionvalue(namestr, device_id, 'guid')): parentnotebookguid = '4524187f-c131-4d7d-b6cc-a1af20474a7f' note_title = f'服务器_{device_id}_ip更新记录' # note.title = "hengchu" print(note_title) note = makenote2(note_title, notebody='', parentnotebook=parentnotebookguid) guid = note.guid setcfpoptionvalue(namestr, device_id, 'guid', guid)
def after_logout(): men_wc = getcfpoptionvalue('everwebchat', get_host_uuid(), 'host_nickname') try: termux_sms_send(f"微信({men_wc})登录已退出,如有必要请重新启动") except Exception as e: log.critical(f"尝试发送退出提醒短信失败。{e}") log.critical(f'退出微信({men_wc})登录')
def mysmsfromnotes2smsdb(notebookguid: str): notelst = findnotefromnotebook(notebookguid) for item in notelst: if not (guidchuli := getcfpoptionvalue('everpim', "notemysmsguid", 'noteguid')): guidchulilst = [] else: guidchulilst = guidchuli.split(',') if item[0] not in guidchulilst: log.info(item[0]) desclst, smsnotedf = splitcontentfromnotemysms(item[0]) log.info(desclst) df2smsdb(smsnotedf) guidchulilst.append(item[0]) setcfpoptionvalue('everpim', "notemysmsguid", 'noteguid', ','.join(guidchulilst))
def getnotebookguid(notebookname): """ 根据输入的笔记本名称返回相应的guid """ ntfind = findnotebookfromevernote(notebookname) if ntfind.shape[0] == 0: notebookguid = createnotebook(notebookname) # print(notebookguid) setcfpoptionvalue('everwcitems', 'common', 'notebookguid', str(notebookguid)) else: if (notebookguid := getcfpoptionvalue('everwcitems', 'common', 'notebookguid')) is None: notebookguid = ntfind.index[0] # print(notebookguid) setcfpoptionvalue('everwcitems', 'common', 'notebookguid', str(notebookguid))
def getnewestdataday(item): weatherlastestday = getcfpoptionvalue('everlife', '天气', f"{item}最新日期") if not weatherlastestday: weatherlastestday = '2016-09-19' setcfpoptionvalue('everlife', '天气', f'{item}最新日期', '%s' % weatherlastestday) return weatherlastestday
def chuli_datasource(): """ 展示足迹 """ namestr = 'everloc' if (device_id := str(getcfpoptionvalue(namestr, namestr, 'device_id'))) is None: device_id = getdeviceid() setcfpoptionvalue(namestr, namestr, 'device_id', device_id)
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 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 smsfromnotes2smsdb(notebookguid: str): notelst = findnotefromnotebook(notebookguid) for item in notelst: if not (guidchuli := getcfpoptionvalue('everpim', "noteguid", 'noteguid')): guidchulilst = [] else: guidchulilst = guidchuli.split(',') if item[0] not in guidchulilst: log.info(item[0]) desclst, smsnotedf = splitcontentfromnote(item[0]) log.info(desclst) df2smsdb(pd.DataFrame([desclst], columns=['name', 'desc']), tablename='ctdesc') df2smsdb(smsnotedf) guidchulilst.append(item[0]) setcfpoptionvalue('everpim', "noteguid", 'noteguid', ','.join(guidchulilst))