Ejemplo n.º 1
0
def fileetc_reply(msg):
    innermsg = formatmsg(msg)
    createtimestr = time.strftime("%Y%m%d", time.localtime(msg['CreateTime']))
    filepath = getdirmain() / "img" / "webchat" / createtimestr
    filepath = filepath / f"{innermsg['fmSender']}_{msg['FileName']}"
    touchfilepath2depth(filepath)
    log.info(f"保存{innermsg['fmType']}类型文件:\t{str(filepath)}")
    msg['Text'](str(filepath))
    innermsg['fmText'] = str(filepath)

    writefmmsg2txtandmaybeevernotetoo(innermsg)
Ejemplo n.º 2
0
def readfromtxt(weathertxtfilename):
    if not os.path.exists(weathertxtfilename):
        touchfilepath2depth(weathertxtfilename)
        write2txt(weathertxtfilename, None)
    items = []
    # with open(weathertxtfilename, 'r', encoding='ISO8859-1') as ftxt:
    with open(weathertxtfilename, 'r', encoding='utf-8') as ftxt:
        items = [line.strip() for line in ftxt]  # strip(),去除行首行尾的空格
        # for line in ftxt:
        # try:
        # items.append(line.strip())
        # except UnicodeDecodeError as ude:
        # log.error(f"{line}\n{ude}")
    return items
Ejemplo n.º 3
0
def inserttimeitem2db(timestr: str):
    dbname = touchfilepath2depth(getdirmain() / 'data' / 'db' / 'wcdelay.db')
    conn = lite.connect(dbname)
    cursor = conn.cursor()
    tablename = 'wcdelay'

    def istableindb(tablename: str, dbname: str):
        cursor.execute("select * from sqlite_master where type='table'")
        table = cursor.fetchall()
        print(table)
        chali = [x for item in table for x in item[1:3]]
        print(chali)

        return tablename in chali

    if not istableindb(tablename, dbname):
        cursor.execute(
            f'create table {tablename} (time int primary key, delay int)')
        conn.commit()
        print(f"数据表:\t{tablename} 被创建成功。")

    timetup = time.strptime(timestr, "%Y-%m-%d %H:%M:%S")
    timest = time.mktime(timetup)
    elsmin = (int(time.time()) - time.mktime(ttuple)) // 60
    cursor.execute(f"insert into {tablename} values(?, ?)", (timest, elsmin))
    print(f"数据成功写入{dbname}\t{(timest, elsmin)}")
    conn.commit()
    conn.close()
Ejemplo n.º 4
0
def showbattinfoimg(dbname: str, jingdu: int = 300):
    '''
    show the img for battery info
    '''
    jujinm, battinfodf = getbattinfodb(dbname)
    print(f"充电记录新鲜度:刚过去了{jujinm}分钟")

    register_matplotlib_converters()

    plt.figure(figsize=(36, 12))
    plt.style.use("ggplot")  # 使得作图自带色彩,这样不用费脑筋去考虑配色什么的;

    def drawdelayimg(pos, timedfinner, title):
        # 画出左边界
        tmin = timedfinner.index.min()
        tmax = timedfinner.index.max()
        shicha = tmax - tmin
        bianjie = int(shicha.total_seconds() / 40)
        logstr = f"左边界:{bianjie}秒,也就是大约{int(bianjie / 60)}分钟"
        print(logstr)
        # plt.xlim(xmin=tmin-pd.Timedelta(f'{bianjie}s'))
        plt.subplot(pos)
        plt.xlim(xmin=tmin)
        plt.xlim(xmax=tmax + pd.Timedelta(f"{bianjie}s"))
        # plt.vlines(tmin, 0, int(timedf.max() / 2))
    #     plt.vlines(tmax, 0, int(timedfinner.max() / 2))

        # 绘出主图和标题
        plt.scatter(timedfinner.index, timedfinner, s=timedfinner)
        plt.scatter(timedfinner[timedfinner == 0].index,
                    timedfinner[timedfinner == 0], s=0.5)
        plt.title(title, fontsize=40)
        plt.tick_params(labelsize=20)
        plt.tight_layout()

    timedf = battinfodf['percentage']
    drawdelayimg(321, timedf[timedf.index > timedf.index.max(
    ) + pd.Timedelta('-2d')], "电量(%,最近两天)")
    plt.ylim(0, 110)
    drawdelayimg(312, timedf, "电量(%,全部)")
    plt.ylim(0, 110)
#     imgwcdelaypath = touchfilepath2depth(getdirmain() / "img" / "hard" / "battinfo.png")

    timedf = battinfodf['temperature']
    drawdelayimg(322, timedf[timedf.index > timedf.index.max(
    ) + pd.Timedelta('-2d')], "温度(℃,最近两天)")
    plt.ylim(20, 40)
    drawdelayimg(313, timedf, "温度(℃,全部)")
    plt.ylim(20, 40)
    fig1 = plt.gcf()

    imgwcdelaypath = touchfilepath2depth(
        getdirmain() / "img" / "hard" / "batttempinfo.png")
#     plt.show()
    fig1.savefig(imgwcdelaypath, dpi=jingdu)
    print(os.path.relpath(imgwcdelaypath))

    return imgwcdelaypath
Ejemplo n.º 5
0
def makeexcelfileownpy(ownername):
    """
    init excelpath for dataset store, and ownername in pinyin
    """
    ownpy = Pinyin().get_pinyin(ownername, '')
    excelpath = getdirmain() / 'data' / 'muse' / f'huojiemajiang_{ownpy}.xlsx'
    touchfilepath2depth(excelpath)
    if not excelpath.exists():
        excelwriter = pd.ExcelWriter(excelpath)
        clnames = [
            'roomid', 'time', 'guest', 'guestid', 'client', 'zimo', 'jingding',
            'dianpao', 'laizigang', 'score', 'host'
        ]
        rstdf = pd.DataFrame(list(), columns=clnames)
        rstdf.to_excel(excelwriter, index=False, encoding='utf-8')
        excelwriter.close()

    return excelpath, ownpy
Ejemplo n.º 6
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
Ejemplo n.º 7
0
def df2smsdb(indf: pd.DataFrame, tablename="sms"):
    dbname = touchfilepath2depth(getdirmain() / "data" / "db" /
                                 f"phonecontact_{getdeviceid()}.db")
    checkphoneinfotable(dbname)
    conn = lite.connect(dbname)
    recordctdf = pd.read_sql(f"select * from {tablename}", con=conn)
    indf.to_sql(tablename, con=conn, if_exists="append", index=False)
    afterinsertctdf = pd.read_sql(f"select * from {tablename}", con=conn)
    conn.close()
    logstr = f"记录既有数量:\t{recordctdf.shape[0]}," + f"待添加的记录数量为:\t{indf.shape[0]}," + f"后的记录数量总计为:\t{afterinsertctdf.shape[0]}"
    log.info(logstr)
Ejemplo n.º 8
0
def showinfostream(keyin: str):
    print(keyin)
    dbname = touchfilepath2depth(getdirmain() / "data" / "db" /
                                 "phonecontact.db")
    tablename = "sms"
    checkphoneinfotable(dbname)

    conn = lite.connect(dbname)
    recordctdf = pd.read_sql(
        f"select * from {tablename} where (number like \'%{keyin}%\') or (name like \'%{keyin}%\')",
        con=conn)
    conn.close()
    return recordctdf
Ejemplo n.º 9
0
def showdelayimg(dbname: str, jingdu: int = 300):
    '''
    show the img for wcdelay
    '''
    jujinm, timedf = getdelaydb(dbname)
    #     timedf.iloc[-1]
    print(f"记录新鲜度:出炉了{jujinm}分钟")

    register_matplotlib_converters()

    plt.figure(figsize=(36, 12))
    plt.style.use("ggplot")  # 使得作图自带色彩,这样不用费脑筋去考虑配色什么的;

    def drawdelayimg(pos, timedfinner, title):
        # 画出左边界
        tmin = timedfinner.index.min()
        tmax = timedfinner.index.max()
        shicha = tmax - tmin
        bianjie = int(shicha.total_seconds() / 40)
        print(f"左边界:{bianjie}秒,也就是大约{int(bianjie / 60)}分钟")
        # plt.xlim(xmin=tmin-pd.Timedelta(f'{bianjie}s'))
        plt.subplot(pos)
        plt.xlim(xmin=tmin)
        plt.xlim(xmax=tmax + pd.Timedelta(f"{bianjie}s"))
        # plt.vlines(tmin, 0, int(timedf.max() / 2))
        plt.vlines(tmax, 0, int(timedfinner.max() / 2))

        # 绘出主图和标题
        plt.scatter(timedfinner.index, timedfinner, s=timedfinner)
        plt.scatter(timedfinner[timedfinner == 0].index,
                    timedfinner[timedfinner == 0],
                    s=0.5)
        plt.title(title, fontsize=40)
        plt.tick_params(labelsize=20)
        plt.tight_layout()

    drawdelayimg(
        211, timedf[timedf.index > timedf.index.max() + pd.Timedelta('-2d')],
        "信息频率和延时(分钟,最近两天)")
    drawdelayimg(212, timedf, "信息频率和延时(分钟,全部)")
    fig1 = plt.gcf()

    plt.show()

    imgwcdelaypath = touchfilepath2depth(getdirmain() / "img" / "webchat" /
                                         "wcdelay.png")

    fig1.savefig(imgwcdelaypath, dpi=jingdu)
    print(os.path.relpath(imgwcdelaypath))

    return imgwcdelaypath
Ejemplo n.º 10
0
def getcfp(cfpfilename: str):
    cfpson = ConfigParser()
    inipathson = Path(getdirmain()) / 'data' / (cfpfilename + '.ini')
    touchfilepath2depth(inipathson)
    try:
        cfpson.read(inipathson, encoding='utf-8')
    except (DuplicateSectionError, DuplicateOptionError) as dse:
        log.critical(
            f"ini文件《{inipathson}》中存在重复的section或option名称,备份文件并试图修复文件……{dse}")
        fixinifile(inipathson)
    except Exception as eee:
        log.critical(eee)
        try:
            cfpson.read(inipathson, encoding='utf-8')
            log.critical(f"ini文件《{inipathson}》修复成功!!!")
        except Exception as e:
            log.critical(f"读取配置文件《{inipathson}》时失败!!!{e}")
            log.critical(f"试图强制删除该配置文件《{inipathson}》")
            os.remove(inipathson)
            log.critical(f"配置文件《{inipathson}》被强制删除!!!")
            return

    return cfpson, inipathson
Ejemplo n.º 11
0
def phonecontact2db():
    """
    手机联系人数据入库
    """
    ctstr = termux_contact_list()
    ctlst = eval(ctstr)
    ctdf = pd.DataFrame(ctlst)
    ctdf['number'] = ctdf['number'].apply(lambda x: x.replace(" ", ''))
    ctdf.drop_duplicates('number', inplace=True)
    ctdf['appendtime'] = time.time()
    print(ctdf.shape[0])
    tablename = "phone"
    dbname = touchfilepath2depth(getdirmain() / "data" / "db" /
                                 f"phonecontact_{getdeviceid()}.db")
    checkphoneinfotable(dbname)
    conn = lite.connect(dbname)
    recordctdf = pd.read_sql(f"select * from {tablename}", con=conn)
    ctdf.to_sql(tablename, con=conn, if_exists="append", index=False)
    afterinsertctdf = pd.read_sql(f"select * from {tablename}", con=conn)
    conn.close()
    logstr = f"联系人记录既有数量:\t{recordctdf.shape[0]}," + f"待添加的联系人记录数量为:\t{ctdf.shape[0]}," + f"添加后的联系人记录数量总计为:\t{afterinsertctdf.shape[0]}"
    log.info(logstr)
Ejemplo n.º 12
0
def getphoneinfodb():
    """
    从联系人信息数据表提取数据(DataFrame)
    """
    #     tablename = "wcdelaynew"
    dbname = touchfilepath2depth(getdirmain() / "data" / "db" /
                                 f"phonecontact_{getdeviceid()}.db")
    tablename = "phone"
    checkphoneinfotable(dbname)

    conn = lite.connect(dbname)
    recordctdf = pd.read_sql(f"select * from {tablename}", con=conn)
    conn.close()

    recordctdf["appendtime"] = recordctdf["appendtime"].apply(
        lambda x: pd.to_datetime(
            time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(x))))

    if (tdfsize := recordctdf.shape[0]) != 0:
        print(f"联系人记录共有{tdfsize}条")
        jujinmins = int(
            (pd.to_datetime(time.ctime()) -
             recordctdf['appendtime'].max()).total_seconds() / 3600)
Ejemplo n.º 13
0
    from func.first import getdirmain, touchfilepath2depth
    from life.wcdelay import getdelaydb, showdelayimg
    from func.litetools import ifnotcreate
    from func.wrapfuncs import timethis, logit
    from func.logme import log
    from func.sysfunc import uuid3hexstr, sha2hexstr
    from func.nettools import isitchat

# %% [markdown]
# ## 热启动

# %% [markdown]
# ##### 直接热启动

# %%
pklabpath = os.path.relpath(touchfilepath2depth(getdirmain() / 'itchat.pkl'))
print(pklabpath)

# %%
# isitchat??

# %%
# itchat.auto_login??

# %%
itchat.auto_login(hotReload=True, statusStorageDir=pklabpath)   #热启动你的微信

# %% [markdown]
# ##### 函数方式热启动

# %%
Ejemplo n.º 14
0
# -*- coding: utf-8 -*-
# ---
# jupyter:
#   jupytext:
#     text_representation:
#       jupytext_version: 1.10.3
# ---

import pathmagic
with pathmagic.context():
    from func.logme import log
    from func.first import touchfilepath2depth, getdirmain
    from etc.battery_manage import batteryrecord2db
    from func.sysfunc import not_IPython

if __name__ == "__main__":
    if not_IPython():
        logstrouter = "运行文件\t%s" % __file__
        log.info(logstrouter)
    dbnameouter = touchfilepath2depth(getdirmain() / "data" / "db" /
                                      f"batteryinfo.db")
    batteryrecord2db(dbnameouter)
    if not_IPython():
        logstrouter = "文件%s运行结束" % (__file__)
        log.info(logstrouter)
Ejemplo n.º 15
0
def chuturizhexian(df,
                   riqienddate,
                   xiangmu,
                   cum=False,
                   quyu='',
                   leixing='',
                   pinpai='',
                   imgpath=dirmainpath / 'img'):
    """
    日数据(月份)累积对比图,当月、环比、同期比
    riqienddate形如2017-12-08,代表数据结束点的日期
    :param df:
    :param riqienddate:
    :param xiangmu:
    :param cum:
    :param quyu:
    :param leixing:
    :param pinpai:
    :param imgpath:
    :return:
    """
    riqicurmonthfirst = riqienddate + MonthBegin(-1)  # 日期格式的当月1日
    riqibeforemonthfirst = riqienddate + MonthBegin(-2)  # 日期格式的上月1日
    riqilastmonthfirst = riqienddate + MonthBegin(-13)  # 日期格式的去年当月1日
    tianshu = (riqienddate + MonthEnd(-1)).day  # 当月的天数

    # print(df)
    ds = pd.DataFrame(df)
    datesb = pd.date_range(riqibeforemonthfirst, periods=tianshu,
                           freq='D')  # 上月日期全集,截止到当月最后一天为止
    if ds.index.min() <= datesb.max():  # 存在有效数据则生成按全月每天索引的DataFrame,否则置空
        ds1 = ds.reindex(datesb, fill_value=0)  # 重新索引,补全所有日期,空值用0填充
        ds1.index = (range(1, len(datesb) + 1))  # 索引天日化
        ds1.columns = f'{riqibeforemonthfirst.year:04d}{riqibeforemonthfirst.month:02d}' + ds1.columns  # 列命名,形如201709
    else:
        ds1 = pd.DataFrame()

    datesl = pd.date_range(riqilastmonthfirst, periods=tianshu,
                           freq='D')  # 处理去年当月数据
    if ds.index.min() <= datesl.max():  # 存在有效数据则生成按全月每天索引的DataFrame,否则置空
        ds3 = ds.reindex(datesl, fill_value=0)
        ds3.index = range(1, len(datesl) + 1)
        ds3.columns = (
            '%04d%02d' %
            (riqilastmonthfirst.year, riqilastmonthfirst.month)) + ds3.columns
    else:
        ds3 = pd.DataFrame()

    datesc = pd.date_range(riqicurmonthfirst,
                           periods=riqienddate.day,
                           freq='D')  # 处理当月数据,至截止日期
    if ds.index.min() <= datesc.max(
    ):  # 存在有效数据则生成按按照每天索引的DataFrame,否则置空并退出,避免空转
        ds2 = ds.reindex(datesc, fill_value=0)
        ds2.index = range(1, len(datesc) + 1)
        ds2.columns = (
            '%04d%02d' %
            (riqicurmonthfirst.year, riqicurmonthfirst.month)) + ds2.columns
    else:
        return

    dff = ds2.join(ds1, how='outer').join(ds3, how='outer')

    nianyue = '%04d%02d' % (riqicurmonthfirst.year, riqicurmonthfirst.month)
    biaoti = leixing + quyu + pinpai + nianyue + xiangmu
    # clnames = []
    # for ct in range(0, len(dff.columns), 2):
    #     clnames.append(dff.columns[ct])
    dfc = dff
    if cum:
        dfc = dfc.cumsum()  # 数据累积求和
        biaoti = biaoti + '日累积'
    # print(dfc)
    dfc.plot(title=biaoti)
    # plt.ylim(0) #设定纵轴从0开始

    biaozhukedu(dfc, riqienddate.day)
    imgsavepath = imgpath / (biaoti + '(日累积月).png')
    touchfilepath2depth(imgsavepath)
    plt.savefig(str(imgsavepath))
    plt.close()
    imglistctrz = list()
    imglistctrz.append(str(imgsavepath))

    return imglistctrz
Ejemplo n.º 16
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, '武汉天气图')
Ejemplo n.º 17
0

# %%
def jinchustatdo():
    # items = getcfp('everlife')[0].items('impinfolist')
    noteinfolistinside = []
    if (items := getcfpsectionvalue('everlife', 'impinfolist')):
        for address, infoslicelist in items:
            infoslist = [*args, wifilist] = infoslicelist.split('\n')
            infoslist.insert(1, address)
            infoslist.insert(-1, infoslist[-1].split(','))
            noteinfolistinside.append(infoslist[:-1])
    # print(noteinfolist)

    gfile = dirmainpath / 'data' / 'google'
    touchfilepath2depth(gfile / 'somethingelse')
    dfjinchu = pd.DataFrame(jilugooglefile(gfile))
    itemswifi = jilugmail('Ifttt/Wifi', 'wifi', 'all')
    if itemswifi:
        dfjinchuwifi = wifitodf(itemswifi, noteinfolistinside)
        dfjinchu = dfjinchu.append(dfjinchuwifi)

    try:
        dfjinchu = dfjinchu.append(jilugoogledrive())
    except Exception as eeee:
        log.critical('读取Goolge Drive中表格中数据记录时出现未名错误。%s' % (str(eeee)))

    # print(dfjinchu.shape[0])
    try:
        for noteinfo in noteinfolistinside:
            if len(noteinfo[0]) > 0:  # 有数据源笔记的guid就处理该笔记
Ejemplo n.º 18
0
def getdbname(dbpath: str, ownername: str):
    return touchfilepath2depth(getdirmain() / dbpath /
                               f"wccontact_{ownername}.db")
Ejemplo n.º 19
0
fubiaofinal[:5]

divstr = '<div>November 28, 2014 at 09:34PM,95555,<b>发来短信</b> 您尾号8256的信用卡28日21:34消费人民币437.00元。送你99积分,马上领 t.cn/8s52qAr 。[招商银行]<div><br/></div>December 01, 2014 at 06:47PM,95555,<b>发来短信</b> 【代扣查询】截至12月01日,您的缴费号码0904843679 总计欠费0元,如疑请询95555。[招商银行]<div><br/></div>December 01, 2014 at 08:36PM,95555,<b>发来短信</b> 【代扣查询】截至12月01日,您的缴费号码6626515632 总计欠费0元,如疑请询95555。[招商银行]<div><br/></div>December 04, 2014 at 02:29PM,95555,<b>发来短信</b> 白晔峰先生,您个人信用卡临时额度后天失效,2014年12月05日09点前回#YLEY可重新申请临额至66000元,短信回复为准。巧用额度理财,猛戳 t.cn/8FdmPg8 查询[招商银行]<div><br/></div>December 04, 2014 at 02:35PM,95555,<b>短信发出</b> #yley<div><br/></div>December 04, 2014 at 02:36PM,95555,<b>发来短信</b> 白晔峰先生,您个人信用卡账户临额调整成功,该账户临额66000元,有效期至2015年03月03日,当前可用额度为32281元,超出信用额度使用的款项将计入最低还款额。巧用额度理财,猛戳 t.cn/8FdmPg8 查询[招商银行]</div><br clear="none"/>'

divhtml = BeautifulSoup(divstr, 'lxml')
divhtml.div

[line for line in validlines if not re.findall("(电话(来自|打给)|(错过来电))", line)]

testitem = 'December 26, 2014 at 03:22PM,电话来自 徐志伟 13207166125,时长 61 秒'
testitem.split(",", 3)

# ###### 【删除类型为call的纪录】

tablename = "sms"
dbname = touchfilepath2depth(getdirmain() / "data" / "db" / "phonecontact.db")
conn = lite.connect(dbname)
sqldel = f"delete from {tablename} where type=\'call\'"
print(sqldel)
cursor = conn.cursor()
cursor.execute(sqldel)
conn.close()

# ##### 联系人信息查询


def showinfostream(keyin: str):
    print(keyin)
    dbname = touchfilepath2depth(getdirmain() / "data" / "db" /
                                 "phonecontact.db")
    tablename = "sms"
Ejemplo n.º 20
0
    plt.show()

    imgwcdelaypath = touchfilepath2depth(getdirmain() / "img" / "webchat" /
                                         "wcdelay.png")

    fig1.savefig(imgwcdelaypath, dpi=jingdu)
    print(os.path.relpath(imgwcdelaypath))

    return imgwcdelaypath


# %% [markdown]
# ## 主函数main

# %%
if __name__ == "__main__":
    if not_IPython():
        logstrouter = "运行文件\t%s" % __file__
        log.info(logstrouter)
    # owner = 'heart5'
    owner = '白晔峰'
    dbnameouter = touchfilepath2depth(getdirmain() / "data" / "db" /
                                      f"wcdelay_{owner}.db")
    xinxian, tdf = getdelaydb(dbnameouter)
    print(xinxian)
    print(tdf.sort_index(ascending=False))
    if not_IPython():
        logstrouter = "文件%s运行结束" % (__file__)
        log.info(logstrouter)
Ejemplo n.º 21
0
                        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)
    dsdays.plot()
    imgpathdays = dirmainpath / 'img' / 'gpsdays.png'
    touchfilepath2depth(imgpathdays)
    plt.savefig(str(imgpathdays))
    plt.close()
    imglst.append(str(imgpathdays))
    print(imglst)

    if (device_name := getinivaluefromnote('device', device_id)) is None:
        device_name = device_id
Ejemplo n.º 22
0
    return frddf2append


dfcleanafterupdatecontactuuid = dfsha2udpatecontactuuid(frddfafterdropduplites)
dfcleanafterupdatecontactuuid

# + [markdown] jupyter={"source_hidden": true}
# ##### 【删除该数据表,按结构重构】

# + [markdown] jupyter={"source_hidden": true}
# ##### 回填数据

# + jupyter={"source_hidden": true}
owner = getownername()
dbname = touchfilepath2depth(getdirmain() / "data" / "db" /
                             f"wccontact_{owner}.db")
dftablename = 'wccontact'
conn = lite.connect(dbname)
dfcleanafterupdatecontactuuid.to_sql(dftablename,
                                     con=conn,
                                     if_exists='append',
                                     index=False)
conn.close()
# -

# #### 处理结果并输出简版的结果

# ##### 填充remarkname为空的记录(用nickname填充)

frdfromdb['remarkname'] = frdfromdb[['nickname', 'remarkname']].apply(
    lambda x: x.nickname if x.remarkname == '' else x.remarkname, axis=1)
Ejemplo n.º 23
0
    from func.first import dirmainpath, touchfilepath2depth, getdirmain
    from life.wcdelay import showdelayimg
    from life.phonecontact import getphoneinfodb, checkphoneinfotable
    from func.pdtools import lststr2img
    from func.sysfunc import sha2hexstr, set_timeout, after_timeout
    from etc.getid import getdeviceid
    from func.termuxtools import *
    from func.litetools import droptablefromdb, ifnotcreate
    from func.configpr import getcfpoptionvalue, setcfpoptionvalue
    from life.phonecontact import showphoneinfoimg
# -

# ## 综合输出

# +
dbname = touchfilepath2depth(getdirmain() / "data" / "db" / f"phonecontact_{getdeviceid()}.db")

tablename="phone"
checkphoneinfotable(dbname)

conn = lite.connect(dbname)
recorddf_back = pd.read_sql(f"select * from {tablename}", con=conn)
tablename = 'sms'
recordsms_back = pd.read_sql(f"select type, sent, name, number, time, content from {tablename}", con=conn)
conn.close()
# -

ctdf = recorddf_back.copy(deep=True)
ctdf.dtypes
ctdf
smsdf = recordsms_back.copy(deep=True)
Ejemplo n.º 24
0
    tablefd = cursor.execute(tbnsql).fetchall()
    #     print(tablefd)
    tablesnamelst = [name for x in tablefd for name in x]
    print(tablesnamelst)
    for tname in tablesnamelst:
        structsql = f"SELECT sql FROM sqlite_master WHERE type = 'table' AND tbl_name = '{tname}';"
        tablefd = cursor.execute(structsql).fetchall()
        print(tname + ":\t", [name for x in tablefd for name in x][0])
    conn.commit()
    tcs = conn.total_changes
    print(tcs)
    conn.close()


owner = '白晔峰'
dbname = touchfilepath2depth(getdirmain() / "data" / "db" /
                             f"wccontact_{owner}.db")
print(dbname)
showtablesindb(dbname)
showtablesindb(testdb)

# ## 查询数据表结构,返回列名是否存在,显示数据表的字段结构

# +
import re


def ifclexists(dbin, tb, cl):
    conn = lite.connect(dbin)
    cursor = conn.cursor()
    structsql = f"SELECT sql FROM sqlite_master WHERE type = 'table' AND tbl_name = '{tb}';"
    tablefd = cursor.execute(structsql).fetchall()
Ejemplo n.º 25
0
def zhanjidesc(ownername, recentday: str = '日', simpledesc: bool = True):
    excelpath, ownpy = makeexcelfileownpy(ownername)
    print(excelpath, ownpy)
    #     recorddf = pd.read_excel(excelpath)  # 暂时停用,用huojiemain主数据文件
    huojieds2note()
    recorddf = pd.read_excel(getdirmain() / 'data' / 'muse' /
                             'huojiemain.xlsx')
    rstdf = recorddf.copy(deep=True)
    #     print(rstdf.dtypes)
    # print(rstdf.groupby(['guestid', 'guest']).count())
    rstdf.drop_duplicates(['roomid', 'guestid'], inplace=True)
    rstdf.sort_values(by=['time', 'score'],
                      ascending=[False, False],
                      inplace=True)
    # print(rstdf.head())
    # print(rstdf.dtypes)
    # print(rstdf.groupby(['guestid', 'guest']).count())

    fangdf = fetchmjfang(ownername)
    #     print(fangdf)
    fangdf = fixnamealias(fangdf, 'name')
    #     print(fangdf.dtypes)
    fangclosedf = rstdf.groupby('roomid')['time'].max()
    # print(fangclosedf)
    # 以房号为索引进行数据合并,默认join='outer'
    fangfinaldf: pd.DataFrame = pd.concat([fangdf, fangclosedf],
                                          axis=1).sort_values(by=['mintime'],
                                                              ascending=False)
    fangfinaldf = fangfinaldf.rename(columns={'time': 'closetime'})
    #     print(fangfinaldf.dtypes)
    # print(fangfinaldf) fangfinaldf.loc[:, 'playmin'] = fangfinaldf.apply(lambda df: int((df['closetime'] - df[
    # 'maxtime']).total_seconds() / 60) if df['closetime'] else pd.NaT, axis=1)
    fangfinaldf.loc[:, 'playmin'] = fangfinaldf.apply(
        lambda df: (df['closetime'] - df['maxtime']).total_seconds() // 60
        if df['closetime'] else pd.NaT,
        axis=1)
    # print(fangfinaldf[fangfinaldf['mintime'].isnull()])

    # 根据对局战绩修正房主信息
    rstdfroomhost = rstdf[rstdf.host].groupby('roomid')['guest'].first()
    for ix in list(rstdfroomhost.index.values):
        hostname = rstdfroomhost[ix]
        fangfinaldf.loc[ix, 'name'] = hostname

    # 代开房间房主信息处理
    dkds = rstdf.groupby(['roomid', 'host']).count()['guest']
    for r, h in list(dkds[dkds % 4 == 0].index):
        # 回填战绩df的host栏目
        luckyguy = rstdf.groupby('roomid').first()['guest'].loc[r]
        ixforluckguy = rstdf[(rstdf.roomid == r)
                             & (rstdf.guest == luckyguy)].index
        rstdf.loc[ixforluckguy, 'host'] = True
        print(ixforluckguy)
        # 完善开房信息
        fangfinaldf.loc[r, 'name'] = luckyguy
        print(f"房间信息数据结构:\t{list(fangfinaldf.columns)}")
        print(f"代开房间号:\t{r}, 房间信息:\t{list(fangfinaldf.loc[r])}")

    # 中断牌局,只取最终结果
    zdds = rstdf.groupby('roomid').count()['time']
    for ix in list(zdds[zdds > 4].index):
        time2keep = rstdf.groupby('roomid').max()['time'].loc[ix]
        time2drop = rstdf.groupby('roomid').min()['time'].loc[ix]
        print(
            f"续局房号:\t{ix},记录共有{zdds[ix]}条,需删除时间点\t{time2drop},保留的终局时间点为:\t{time2keep}"
        )
        rstdf = rstdf[rstdf.time != time2drop]

    rstdf = fixnamebyguestid(rstdf)  # 重新修正id和用户名
    print(rstdf.shape[0])
    rstdf.drop_duplicates(['roomid', 'time', 'guestid', 'score', 'host'],
                          inplace=True)
    print(rstdf.shape[0])
    fangfinaldf.to_csv(csvfile := touchfilepath2depth(getdirmain() / 'data' /
                                                      'game' /
                                                      'huojiemajiangfang.csv'))
    fangfdf = fangfinaldf.copy(deep=True)

    # 找到那些没有开局链接的局,按照其他局的平均时间赋值,同时更新count、maxtime、mintime、consumemin、name的列值

    # 平均对局时长(分钟)
    playminmean = int(fangfdf['playmin'].mean())
    # 没有开局链接的局
    fangffix = fangfdf[fangfdf['playmin'].isnull() & fangfdf['count'].isnull()]
    # 用平均用时完善数据集
    for index in fangffix.index:
        fangfdf.loc[index, ['maxtime']] = fangfdf.loc[
            index, ['closetime']][0] - pd.to_timedelta(f'{playminmean}min')
        fangfdf.loc[index, ['mintime']] = fangfdf.loc[index, ['maxtime']][0]
        fangfdf.loc[index, ['count']] = 1
        innername = rstdf[rstdf.host].set_index('roomid').loc[index, ['guest']]
        if type(innername) == pd.DataFrame:
            print(innername)
            innername = innername.iloc[-1, :]
            print(f"内部名称为:\t{innername}")
        fangfdf.loc[index, ['name']] = innername[0]
        fangfdf.loc[index, ['playmin']] = playminmean
        fangfdf.loc[index, ['consumemin']] = 0

    fangfinaldf = fangfdf.sort_values(['mintime'], ascending=False)
    fangfinaldf.drop_duplicates(inplace=True)

    if (zuijindatestart := getstartdate(
            recentday, rstdf['time'].max())) != rstdf['time'].max():
        rstdf = rstdf[rstdf.time >= zuijindatestart]
        fangfilter = fangfdf.apply(lambda x: x['mintime'] >= zuijindatestart or
                                   x['closetime'] >= zuijindatestart,
                                   axis=1)
        # print(fangfilter)
        fangfinaldf = fangfdf[fangfilter]
Ejemplo n.º 26
0
def huojieds2note():
    huojieguid = getinivaluefromnote('game', 'guid')
    notecontent = getnotecontent(huojieguid)

    try:
        neirong = notecontent.find('pre').text
        print(neirong)
        nrlst = neirong.split('\n')
        print(nrlst)
        jushufromnote = int(nrlst[0].split(":")[1])
    except Exception as e:
        print(e)
        jushufromnote = 0
    print(jushufromnote)
    musedatapath = getdirmain() / 'data' / 'muse'
    tlst = [
        musedatapath / pt for pt in os.listdir(musedatapath)
        if (pt.endswith('xlsx') or pt.endswith('xls'))
    ]
    print(tlst)
    df = pd.DataFrame()
    for datafile in tlst:
        countbefore = df.shape[0]
        df = df.append(pd.read_excel(datafile))
        log.info(f"{os.path.basename(datafile)}\t{df.shape[0] - countbefore}")

    df = df.drop_duplicates().sort_values('time', ascending=False)
    jushufromhost = df.shape[0] // 4
    log.info(f"主机本地数据文件有效局数为:\t{jushufromhost}")

    if jushufromnote != jushufromhost:
        datamainpath = musedatapath / 'huojiemain.xlsx'
        touchfilepath2depth(datamainpath)

        reslst = getnoteresource(huojieguid)
        targetbinlst = [
            x[1] for x in reslst if x[0] == os.path.basename(datamainpath)
        ]
        if len(targetbinlst) != 0:
            huojiefromnotepath = musedatapath / 'huojiemainfromnote.xlsx'
            f = open(huojiefromnotepath, 'wb')
            f.write(targetbinlst[0])
            f.close()
            log.info(f"本地数据局数为:{jushufromhost}")
            df = df.append(pd.read_excel(huojiefromnotepath))
            df = df.drop_duplicates().sort_values('time', ascending=False)
            jushufromhost = df.shape[0] // 4
            log.info(f"添加网络数据后的总局数为:{jushufromhost}")
        df.to_excel(datamainpath, index=False)

        timemin = df['time'].min()
        timemax = df['time'].max()
        deviceid = getdeviceid()
        if (device_name := getinivaluefromnote('device', deviceid)) is None:
            device_name = deviceid
        updatereslst2note(
            [datamainpath],
            huojieguid,
            neirong=
            f'局数:{jushufromhost}\n时间跨度:{timemin}至{timemax}\n主机名称:{device_name}',
            filenameonly=True)
Ejemplo n.º 27
0
def getworknewmail():
    """
    获取work标签下的新邮件并保存附件
    """

    global service

    service = getservice()
    # Call the Gmail API
    results = service.users().labels().list(userId='me').execute()
    labels = results.get('labels', [])
    """获取目标label的id"""
    worklabelname = "Work"
    worklabelid = None
    if not labels:
        print('No labels found.')
    else:
        # print('Labels:')
        # pprint.pprint(labels)
        for label in labels:
            # print(label['name'], label['id'], label['messagesTotal'], label['messagesUnread'])
            if label['name'] == worklabelname:
                # pprint.pprint(label)
                worklabelid = label['id']

    # 获取目标label下的未读邮件信息
    label4work = service.users().labels().get(userId='me',
                                              id=worklabelid).execute()
    pprint.pprint(label4work)
    msg4work = service.users().messages().list(userId='me',
                                               labelIds=[worklabelid],
                                               q='is:unread').execute()
    pprint.pprint(msg4work)
    print(f"未读邮件数量为:{msg4work['resultSizeEstimate']}")
    if msg4work['resultSizeEstimate'] == 0:
        log.info(f"目录《{worklabelname}》\t{worklabelid}没有新邮件")
        return

    # 从配置文件读出已处理邮件列表并装配成list待用
    msgidsrecordstr = getcfpoptionvalue('evergmailc', 'mail', '已处理')
    if not msgidsrecordstr:
        msgidsrecordlst = []
    else:
        msgidsrecordlst = msgidsrecordstr.split(',')

    # 遍历待处理邮件并做相应处置
    msgidlst = list()
    for msg in msg4work['messages']:
        # 遍历,通过头部插入实现升序排列
        msgidlst.insert(0, msg['id'])

    msgchulilst = list()
    for msgid in msgidlst:
        # 判断是否在已处理列表中,是则跳过继续循环
        if msgid in msgidsrecordlst:
            print(f"邮件\t{msgid}\t已处理过")
            continue

        # 获取邮件
        mailmsg = service.users().messages().get(userId='me',
                                                 id=msgid).execute()
        print(msgid)
        # pprint.pprint(mailmsg)
        # print(f"{mailmsg['snippet']}")

        # 处理邮件标题
        hnamelst = list()
        hvaluelst = list()
        for headerinner in mailmsg['payload']['headers']:
            hnamelst.append(headerinner['name'])
            hvaluelst.append(headerinner['value'])
        headercontentdict = dict(zip(hnamelst, hvaluelst))
        pprint.pprint(headercontentdict)
        msgheader = headercontentdict['Subject']
        print(msgheader)

        # 处理邮件中的附件
        pprint.pprint(mailmsg['payload']['parts'])
        msgattachmentslst = list()
        for part in mailmsg['payload']['parts']:
            attachname = part['filename']
            if attachname:
                pprint.pprint(part)
                attach = service.users().messages().attachments().get(
                    userId='me',
                    id=part['body']['attachmentId'],
                    messageId=msgid).execute()
                file_data = base64.urlsafe_b64decode(
                    attach['data'].encode('utf-8'))

                # 处理附件文件名,按照主题保存到相应的目录下
                datadirwork = getdirmain() / 'data' / 'work'
                pointat1 = attachname.rfind('.')
                timenowstr = datetime.datetime.now().strftime(
                    '__%Y%m%d%H%M%S_%f')
                datadiri = datadirwork
                if attachname.startswith('销售订单'):
                    # print(fname)
                    datadiri = os.path.join(datadirwork, '销售订单')
                elif attachname.startswith('订单明细'):
                    # print(fname)
                    datadiri = os.path.join(datadirwork, '订单明细')

                attachfile = os.path.join(
                    datadiri,
                    attachname[:pointat1] + timenowstr + attachname[pointat1:])

                print(attachfile, attach['size'])
                touchfilepath2depth(Path(attachfile))
                f = open(attachfile, 'wb')
                f.write(file_data)
                f.close()
                msgattachmentslst.append(attachname)

        print(msgattachmentslst)
        # credentials只有读取的权限,无法做出写入和更改处理,修改操作只能先注释掉
        # modifylabeldict = {'addLabelIds':[], 'removeLabelIds':['Unread']}
        # modifymsg = service.users().messages().modify(userId='me', id=msg['id'], body=modifylabeldict).execute()
        print(f"邮件{msgid}处理完毕,标记为已处理")
        msgidsrecordlst.insert(0, msgid)
        msgchulilst.append(msgid)
        log.info(f"邮件{msgid}\t{msgheader}处理完毕,附件列表为:{msgattachmentslst}")

    setcfpoptionvalue('evergmailc', 'mail', '已处理', ','.join(msgidsrecordlst))
    log.info(f"共有{len(msgchulilst)}封邮件处理完毕,邮件编号列表:{msgchulilst}")
Ejemplo n.º 28
0
def zipdir2one():
    sourcedirpath = dirmainpath / 'data'
    sourcedir = str(sourcedirpath)
    # sourcedir = ""
    env_dlist = os.environ
    # for key in env_dlist:
    #    print(key, env_dlist[key])
    if 'onedrive' in env_dlist:
        onedrivedir = Path(env_dlist['onedrive'])
    else:
        onedrivedir = Path('/storage/emulated/0/Documents')
    # zipfilename = f'datauto_{platform.node()}.zip'
    zipfilename = f"datauto_{platform.uname().system}_{platform.uname().machine}_{platform.uname().node}"
    # print(zipfilename)
    # zipfilenamenew = zipfilename.replace('.zip', '_other.zip')
    # print(zipfilenamenew)
    targetzipdir = Path(
        onedrivedir) / '文档' / 'Program' / 'python' / 'everworkdataonly'
    targetzipfile = targetzipdir / zipfilename
    addextstr = datetime.datetime.now().strftime("_%Y%m%d%H%M%S")
    zipfilename = f"datauto_{platform.uname().system}_{platform.uname().machine}_{platform.uname().node}{addextstr}"
    # targetzipfileadd = targetzipdir / zipfilename
    rt = os.system(f'7z u -r {str(targetzipfile)+".7z"} {str(sourcedirpath)}')
    if rt == 0:
        log.info(f'成功运行7zip更新了压缩文件包:{targetzipfile}')
        return
    zipfilename = zipfilename + '.zip'
    targetzipfile = targetzipdir / zipfilename
    targetzipfileadd = targetzipdir / zipfilename

    # print(targetzipfileadd)
    # targetzipfilenew = targetzipdir / zipfilenamenew
    # print(targetzipfilenew)
    # print(targetzipfile)
    flnamesinzip = dict()
    if not targetzipfile.is_file():
        print(f'{targetzipfile}文件不存在,需要创建。')
        touchfilepath2depth(targetzipfile)
    elif not zipfile.is_zipfile(targetzipfile):
        print(f'{targetzipfile}不是一个合格的zip文件。')
        # targetzipfile = targetzipfilenew
    elif zipfile.is_zipfile(targetzipfile):
        print(f'合格的zip文件{targetzipfile}已经存在。')
        targetzip = zipfile.ZipFile(str(targetzipfile), 'r')
        # print(targetzip)
        filesinzip = targetzip.namelist()
        for filein in filesinzip:
            fileinfo = targetzip.getinfo(filein)
            fileinname = fileinfo.filename
            filestructtime = fileinfo.date_time[0:6]
            fileinmtime = datetime.datetime(*filestructtime).strftime('%F %T')
            flnamesinzip[fileinname] = fileinmtime
            # print(flnamesinzip)
            # print(f'{fileinname}\t{fileinmtime}')
        # print(targetzip.filelist())
        # print(flnamesinzip)
        # print(targetzip.infolist())
        targetzip.close()

    log.info(f'压缩目录《{sourcedir}》到OneDrive文件夹实现自动同步')
    # print(flnamesinzip.keys())
    filelist = list()
    for dirpath, dirnames, filenames in os.walk(sourcedir):
        for filename in filenames:
            filelist.append(os.path.join(dirpath, filename))
    # print(filelist)

    updateoradd = list()
    for tar in filelist:
        flmtime = time.strftime('%F %T', time.localtime(os.path.getmtime(tar)))
        # print(f'{tar[len(sourcedir) + 1:]}')
        if tar[len(sourcedir) + 1:].replace('\\', '/') in flnamesinzip.keys():
            flmtimeinzip = flnamesinzip[tar[len(sourcedir) + 1:].replace(
                '\\', '/')]
            dtzip = datetime.datetime.strptime(flmtimeinzip,
                                               '%Y-%m-%d %H:%M:%S')
            dtnow = datetime.datetime.strptime(flmtime, '%Y-%m-%d %H:%M:%S')
            if dtnow > dtzip:
                timespan = dtnow - dtzip
            else:
                timespan = dtzip - dtnow
            # print(timespan.total_seconds())
            if timespan.total_seconds() > 1:
                print(f'{tar}文件已存在,且有更新。{flmtime}\t{flmtimeinzip}')
                updateoradd.append(tar)
            # else:
            #     print(f'{tar}文件已存在,暂无更新。')
        else:
            print(f'{tar}\t文件需要添加')
            updateoradd.append(tar)
    if len(updateoradd) == 0:
        log.info(f'没有发现需要更新的文件。')
        return
    else:
        newzip = zipfile.ZipFile(str(targetzipfileadd), 'w',
                                 zipfile.ZIP_DEFLATED)
        for tar in updateoradd:
            # print(f'{tar[len(sourcedir):]}\t{time.strftime("%F %T", flmtime)}')
            # newzip.write(tar, tar[len(sourcedir):])  # tar为写入的文件,tar[len(filePath)]为保存的文件名
            try:
                newzip.write(tar, tar[len(sourcedir):])
            except FileNotFoundError as fnfe:
                log.critical(f'文件找不到,可能是临时文件。{tar}\t{fnfe}')
            except OSError as ose:
                log.critical(f'出现系统错误。{ose}')
        newzip.close()
        log.info(f'成功压缩{updateoradd}备份至:{targetzipfileadd}')
Ejemplo n.º 29
0
def getdbname(dbpath: str, ownername: str, title='wccontact'):
    return touchfilepath2depth(getdirmain() / dbpath /
                               f"{title}_{ownername}.db")
Ejemplo n.º 30
0
def getcutpoint(inputdatapath):
    """
    根据时间间隔找到分割点,生成最近一次的图像和全部综合图像并返回
    """
    totalmen = gettotalmem(getdatapath(inputdatapath))
    inputdf = getdatadf(getdatapath(inputdatapath))
    ds = inputdf['time'] - inputdf['time'].shift()
    deltads = ds[ds > getdelta()]

    outlst = list()
    for ix in deltads.index:
        ipos = list(inputdf.index).index(ix)
        # 处理内存占满(但未重启)的特殊情况
        if inputdf.iloc[ipos - 1]['freeper'] == 0:
            continue
        print()
        print(ipos, ix, deltads[ix])
        outlst.append(ipos)
#         bfdf = inputdf[inputdf.index >= (ix - deltads[ix] + pd.Timedelta(minutes=-5))]
#         tmpdf = bfdf[bfdf.index < (ix + pd.Timedelta(minutes=5))]
#         print(tmpdf)

    outlst.insert(0, 0)
    outlst.append(inputdf.shape[0])

    plt.rcParams['font.sans-serif'] = 'SimHei'
    olen = len(outlst)
    if olen == 2:
        picheight = 1
    elif olen == 3:
        picheight = 2
    else:
        picheight = 3
    plt.figure(figsize=(10, 10 * picheight))
    imgpath = getdirmain() / 'img' / 'freemen.png'
    touchfilepath2depth(imgpath)
    #     fig, ax1 = plt.subplots()
    # 针对数据集周期次数进行处理,主要是处理小于三次的情况
    if len(outlst) > 3:
        plt.subplot(311)
    elif len(outlst) == 3:
        plt.subplot(211)

    # 最近数据集图形化输出
    plt.ylabel(f'空闲内存百分比({totalmen}G)')
    cutdf = inputdf.iloc[outlst[-2]:outlst[-1]]
    plt.plot(cutdf.index, cutdf['freeper'])
    plt.ylim(0, 100)
    plt.title('最近一次运行')
    plt.annotate(cutdf.index[0].strftime("%y-%m-%d %H:%M"),
                 xy=[cutdf.index[0], cutdf.iloc[0, 1]])
    plt.annotate(cutdf.index[-1].strftime("%y-%m-%d %H:%M"),
                 xy=[cutdf.index[-1], cutdf.iloc[-1, 1]])

    # 针对单次(一般也是首次运行)数据集进行处理
    if len(outlst) == 2:
        plt.savefig(imgpath)
        return str(imgpath)

    # 针对数据集周期次数进行处理,主要是处理小于三次的情况
    if len(outlst) == 3:
        plt.subplot(212)
    elif len(outlst) > 3:
        plt.subplot(312)
    plt.ylabel(f'空闲内存百分比({totalmen}G)')
    plt.ylim(0, 100)
    plt.title('最近两次运行')
    twolst = outlst[-3:]
    for i in range(len(twolst) - 1):
        cutdf = inputdf.iloc[twolst[i]:twolst[i + 1]]
        plt.plot(cutdf.index, cutdf['freeper'])
        plt.annotate(cutdf.index[0].strftime("%y-%m-%d %H:%M"),
                     xy=[cutdf.index[0], cutdf.iloc[0, 1]])
        plt.annotate(cutdf.index[-1].strftime("%y-%m-%d %H:%M"),
                     xy=[cutdf.index[-1], cutdf.iloc[-1, 1]])

    # 综合(全部)数据集图形输出
    # 针对仅有两次数据集进行处理
    if len(outlst) == 3:
        plt.savefig(imgpath)
        return str(imgpath)
    else:
        plt.subplot(313)
    plt.ylabel(f'空闲内存百分比({totalmen}G)')
    plt.ylim(0, 100)
    plt.title('历次运行')
    for i in range(len(outlst) - 1):
        cutdf = inputdf.iloc[outlst[i]:outlst[i + 1]]
        plt.plot(cutdf.index, cutdf['freeper'])
        plt.annotate(cutdf.index[0].strftime("%y-%m-%d %H:%M"),
                     xy=[cutdf.index[0], cutdf.iloc[0, 1]])
        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)