Esempio n. 1
0
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))
Esempio n. 2
0
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))
Esempio n. 3
0
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))
Esempio n. 4
0
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}')
Esempio n. 5
0
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))
Esempio n. 6
0
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)
Esempio n. 7
0
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))
Esempio n. 8
0
def getnewestdataday(item):
    weatherlastestday = getcfpoptionvalue('everlife', '天气', f"{item}最新日期")
    if not weatherlastestday:
        weatherlastestday = '2016-09-19'
        setcfpoptionvalue('everlife', '天气', f'{item}最新日期',
                          '%s' % weatherlastestday)

    return weatherlastestday
Esempio n. 9
0
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)
Esempio n. 10
0
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)
Esempio n. 11
0
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.")
Esempio n. 12
0
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)
Esempio n. 13
0
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)
Esempio n. 14
0
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
Esempio n. 15
0
def fetchweatherinfo_from_googledrive():
    weatherdatalastestday = getnewestdataday('存储数据')
    today = datetime.datetime.now().strftime('%F')
    hour = int(datetime.datetime.now().strftime('%H'))
    if (today > weatherdatalastestday):  # or True:
        df = getweatherfromgoogledrive()
        if df is not None:
            log.info('通过读Google drive表格,获取天气信息%d条。' % df.shape[0])
            print(df['date'].max())
            weathertxtlastestday = df['date'].max().strftime('%F')
            setcfpoptionvalue('everlife', '天气', '存储数据最新日期',
                              '%s' % weathertxtlastestday)

            return df
Esempio n. 16
0
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)
Esempio n. 17
0
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}")
Esempio n. 18
0
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))
Esempio n. 19
0
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)
Esempio n. 20
0
def fetchweatherinfo_from_gmail(weathertxtfilename):
    weatherdatalastestday = getnewestdataday('存储数据')
    today = datetime.datetime.now().strftime('%F')
    hour = int(datetime.datetime.now().strftime('%H'))
    if (today > weatherdatalastestday) and (hour > 6):
        items = getweatherfromgmail()
        if items:
            log.info('通过邮件轮询,读取天气信息%d条。' % len(items))
            itemfromtxt = readfromtxt(weathertxtfilename)
            for itemg in itemfromtxt:
                items.append(str(itemg))
            write2txt(weathertxtfilename, items)
            weathertxtlastestday = time.strftime(
                '%F',
                time.strptime(items[0].split(' :')[0], '%B %d, %Y at %I:%M%p'))
            setcfpoptionvalue('everlife', '天气', '存储数据最新日期',
                              '%s' % weathertxtlastestday)
Esempio n. 21
0
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))
Esempio n. 22
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)
Esempio n. 23
0
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))
Esempio n. 24
0
def checktableindb(ininame: str,
                   dbpath: str,
                   tablename: str,
                   creattablesql: str,
                   confirm=False):
    """
    检查数据表(ini登记,物理存储)是否存在并根据情况创建
    """
    absdbpath = os.path.abspath(dbpath)  # 取得绝对路径,用于作为section名称
    if not (ifcreated := getcfpoptionvalue(ininame, absdbpath, tablename)):
        print(ifcreated)
        if istableindb(tablename, dbpath) and confirm:
            # 删表操作,危险,谨慎操作
            droptablefromdb(dbpath, tablename, confirm=confirm)
            logstr = f"数据表{tablename}于{dbpath}中被删除"
            log.critical(logstr)
        ifnotcreate(tablename, creattablesql, dbpath)

        setcfpoptionvalue(ininame, absdbpath, tablename, str(True))
Esempio n. 25
0
def finance2note(srccount, rstdf, mingmu, mingmu4ini, title):
    print(f"df索引名称为:{rstdf.index.name}")
    noteguid = getinivaluefromnote('webchat', mingmu)
    count_zdzz = getcfpoptionvalue('everwebchat', 'finance', mingmu4ini)
    if not count_zdzz:
        count_zdzz = 0
    # print(f"{count_zdzz}")

    rstdf.fillna('None', inplace=True)
    colstr = f'{rstdf.index.name}\t' + '\t'.join(list(rstdf.columns)) + '\n'
    itemstr = colstr
    for idx in rstdf.index:
        itemstr += str(idx) + '\t' + '\t'.join(rstdf.loc[idx]) + '\n'
    # print(f"{itemstr}")
    notecontent = "<pre>" + itemstr + "</pre>"
    finance2note4debug = getinivaluefromnote('webchat', 'finance2note4debug')
    # print(f"{type(finance2note4debug)}\t{finance2note4debug}")
    if (srccount != count_zdzz) or finance2note4debug:  # or True:
        imglist2note(get_notestore(), [], noteguid, title, notecontent)
        setcfpoptionvalue('everwebchat', 'finance', mingmu4ini, f"{srccount}")
        log.info(f"成功更新《{title}》,记录共有{rstdf.shape[0]}条")
Esempio n. 26
0
def weatherstatdo():
    weathertxtfilename = str(dirmainpath / 'data' / 'ifttt' / 'weather.txt')
    print(weathertxtfilename)
    dfgoogledrive = None
    try:
        # fetchweatherinfo_from_gmail(weathertxtfilename)
        dfgoogledrive = fetchweatherinfo_from_googledrive()
    except Exception as weathererror:
        log.critical(f'从邮箱或谷歌硬盘获取天气信息时出现错误。{weathererror}')
        raise

    weathernotelastestday = getnewestdataday('笔记')
    today = datetime.datetime.now().strftime('%F')
    weathertxtlastestday = getnewestdataday('存储数据')
    if today == weathernotelastestday:  # and False:
        print('今天的天气信息统计笔记已刷新,本次轮询跳过')
    elif today == weathertxtlastestday:  # or True:
        try:
            items = readfromtxt(weathertxtfilename)
            dftxt = items2df(items)
            # print(dftxt.dtypes)
            dfall = dftxt.append(dfgoogledrive, True)
            # print(dfall)
            # print(dfgoogledrive.dtypes)
            datenew = dfall['date'].max()
            weatherstat(dfall, '296f57a3-c660-4dd5-885a-56492deb2cee')
            log.info(f'天气信息({datenew})成功更新入天气信息统计笔记')
            setcfpoptionvalue('everlife', '天气', '统计天数', f"{len(items)}")
            setcfpoptionvalue('everlife', '天气', '笔记最新日期', today)
        except IndexError as ixe:
            log.critical('读取天气信息并更新天气统计信息笔记时出现索引错误。%s' % (str(ixe)))
        except TypeError as te:
            log.critical('读取天气信息并更新天气统计信息笔记时出现类型错误。%s' % (str(te)))
            raise
        except Exception as eeee:
            log.critical('读取天气信息笔记并更新天气统计信息笔记时出现未名错误。%s' % (str(eeee)))
    else:
        log.info('时间的花儿静悄悄!')
Esempio n. 27
0
def keepliverun():
    # 为了让实验过程更加方便(修改程序不用多次扫码),我们使用热启动
    status4login = itchat.check_login()
    log.critical(f"微信登录状态为:\t{status4login}")
    if status4login == '200':
        log.info(f'已处于成功登录状态')
        return
    itchat.auto_login(hotReload=True, loginCallback=after_login, exitCallback=after_logout)
    # itchat.auto_login(hotReload=True)

    # 设定获取信息时重试的次数,默认是5,设定为50,不知道是否能够起作用
    itchat.originInstance.receivingRetryCount = 50

    init_info = itchat.web_init()
    # showmsgexpanddictetc(init_info)
    if init_info['BaseResponse']['Ret'] == 0:
        logstr = "微信初始化信息成功返回,获取登录用户信息"
        log.info(logstr)
        host_nickname = init_info['User']['NickName']
        host_username = init_info['User']['UserName']
        log.critical(f"函数《{sys._getframe().f_code.co_name}》中用户变量为:\t{(host_nickname, host_username)}")
        if (host_username is not None) and (len(host_username) > 0):
            setcfpoptionvalue('everwebchat', get_host_uuid(), 'host_nickname',
                              host_nickname)
            setcfpoptionvalue('everwebchat', get_host_uuid(), 'host_username',
                              host_username)
        else:
            log.critical("username is None")
    elif (itchat.originInstance.loginInfo):
        log.info("从itchat.originInstance.loginInfo中获取登录用户信息")
        host_nickname = dict(itchat.originInstance.loginInfo['User'])['NickName']
        host_username = dict(itchat.originInstance.loginInfo['User'])['UserName']
        log.critical(f"函数《{sys._getframe().f_code.co_name}》中用户变量为:\t{(host_nickname, host_username)}")
        if (host_username is not None) and (len(host_username) > 0):
            setcfpoptionvalue('everwebchat', get_host_uuid, 'host_nickname',
                              host_username)
            setcfpoptionvalue('everwebchat', get_host_uuid, 'host_username',
                              host_username)
        else:
            log.critical("username is None")
    else:
        log.critical(f"函数《{sys._getframe().f_code.co_name}》中用户变量为:\t{(host_nickname, host_username)}")

    # notechat = newchatnote()
    # listchatrooms()
    # listfriends()
    itchat.run()
Esempio n. 28
0
def merge2note(dfdict, wcpath, notebookguid, newfileonly=False):
    """
    处理从文本文件读取生成的dfdict,分账户读取本地资源文件和笔记进行对照,并做相应更新或跳过
    """
    for name in dfdict.keys():
        fllstfromnote = getnotelist(name, wcpath, notebookguid=notebookguid)
        ptn = f"wcitems_{name}_" + "\d{4}.xlsx"  # wcitems_heart5_2201.xlsx
        xlsxfllstfromlocal = [
            fl for fl in os.listdir(wcpath) if re.search(ptn, fl)
        ]
        if len(fllstfromnote) != len(xlsxfllstfromlocal):
            print(f"{name}的数据文件本地数量\t{len(xlsxfllstfromlocal)},云端笔记列表中为\t{len(fllstfromnote)}," \
                  "两者不等,先把本地缺的从网上拉下来")
            misslstfromnote = [
                fl for fl in fllstfromnote if fl[0] not in xlsxfllstfromlocal
            ]
            for fl, guid in misslstfromnote:
                reslst = getnoteresource(guid)
                if len(reslst) != 0:
                    for res in reslst:
                        flfull = wcpath / fl
                        fh = open(flfull, 'wb')
                        fh.write(res[1])
                        fh.close()
                        dftest = pd.read_excel(flfull)
                        setcfpoptionvalue('everwcitems', fl, 'guid', guid)
                        setcfpoptionvalue('everwcitems', fl, 'itemsnum',
                                          str(dftest.shape[0]))
                        setcfpoptionvalue('everwcitems', fl, 'itemsnum4net',
                                          str(dftest.shape[0]))
                        log.info(
                            f"文件《{fl}》在本地不存在,从云端获取存入并更新ini(section:{fl},guid:{guid})"
                        )

        xlsxfllst = sorted(
            [fl for fl in os.listdir(wcpath) if re.search(ptn, fl)])
        print(f"{name}的数据文件数量\t{len(xlsxfllst)}", end=",")
        if newfileonly:
            xlsxfllst = xlsxfllst[-2:]
        xflen = len(xlsxfllst)
        print(f"本次处理的数量为\t{xflen}")
        for xfl in xlsxfllst:
            print(
                f"{'-' * 15}\t{name}\t【{xlsxfllst.index(xfl) + 1}/{xflen}】\tBegin\t{'-' * 15}"
            )
            dftest = pd.read_excel(wcpath / xfl).drop_duplicates()
            updatewcitemsxlsx2note(name, dftest, wcpath, notebookguid)
            print(
                f"{'-' * 15}\t{name}\t【{xlsxfllst.index(xfl) + 1}/{xflen}】\tDone!\t{'-' * 15}"
            )
Esempio n. 29
0
        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)

    imglst = []
    ds = df4dis['distance']
    today = datetime.datetime.now().strftime('%F')
    dstoday = ds[today].sort_index().cumsum()
    print(dstoday)
    if dstoday.shape[0] > 1:
        dstoday.plot()
        imgpathtoday = dirmainpath / 'img' / 'gpstoday.png'
        touchfilepath2depth(imgpathtoday)
        plt.savefig(str(imgpathtoday))
        plt.close()
        imglst.append(str(imgpathtoday))
    dsdays = ds.resample('D').sum()
    print(dsdays)
Esempio n. 30
0
        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)

    # 短信数据表检查构建
    if not (phonecontactdb := getcfpoptionvalue('everpim', str(getdeviceid()),
                                                'phonesmstable')):
        tablename = "sms"
        print(phonecontactdb, tablename)
        # smsdfdone.columns = ['sent', 'sender', 'number', 'time', 'content', 'smsuuid']
        csql = f"create table if not exists {tablename} (type str,sent bool, name str, number str, time datetime, content str,smsuuid str PRIMARY KEY not null unique on conflict ignore)"
        ifnotcreate(tablename, csql, dbname)
        setcfpoptionvalue('everpim', str(getdeviceid()), 'phonesmstable',
                          str(True))
        logstr = f"数据表{tablename}在数据库{dbname}中构建成功"
        log.info(logstr)

    # 联系人描述数据表检查构建
    if not (phonecontactdb := getcfpoptionvalue('everpim', str(getdeviceid()),
                                                'phonectdesctable')):
        tablename = "ctdesc"
        print(phonecontactdb, tablename)
        # smsdfdone.columns = ['sent', 'sender', 'number', 'time', 'content', 'smsuuid']
        csql = f"create table if not exists {tablename} (name str,desc str)"
        ifnotcreate(tablename, csql, dbname)
        setcfpoptionvalue('everpim', str(getdeviceid()), 'phonectdesctable',
                          str(True))
        logstr = f"数据表{tablename}在数据库{dbname}中构建成功"
        log.info(logstr)