Example #1
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)
Example #2
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)
Example #3
0
def phonesms2db():
    """
    手机短信数据入库
    """
    if not (phonecontactdb := getcfpoptionvalue('everpim', str(getdeviceid()),
                                                'smsfirstrun')):
        readnum = 50000
Example #4
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)
Example #5
0
def getdelta():
    """
    从网络配置笔记中获取时间间隔(用于判断宕机时间,逻辑上不完全准确,取经验值)
    """
    if (delta := getinivaluefromnote('freemem', getdeviceid())) is not None:
        print(delta)
        delta = [int(x) for x in delta.split(',')]
        deltatime = pd.Timedelta(minutes=delta[0], seconds=delta[1])
Example #6
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)
Example #7
0
def add_friend(msg):
    # 如何不是指定的数据分析中心和主账户,则不打招呼
    thisid = getdeviceid()
    houseid = getinivaluefromnote('webchat', 'datahouse')
    mainaccount = getinivaluefromnote('webchat', 'mainaccount')
    helloword1 = getinivaluefromnote('webchat', 'helloword1')
    helloword2 = getinivaluefromnote('webchat', 'helloword2')
    men_wc = getcfpoptionvalue('everwebchat', get_host_uuid(), 'host_nickname')
    if (thisid != str(houseid) or (men_wc != mainaccount)):
        print(f"不是数据分析中心也不是主账号【{mainaccount}】,不用打招呼哟")
        return
    msg.user.verify()
    msg.user.send(f'Nice to meet you!\n{helloword1}\n{helloword2}')
    writefmmsg2txtandmaybeevernotetoo(msg)
    log.info(msg)
Example #8
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)
Example #9
0
def iprecord():
    """
    获取本机ip
    """
    device_id = getdeviceid()
    ip = wifi = wifiid = tun = None
    ethlst = get_ip4alleth()
    print(ethlst)
    if platform.system() == 'Windows':
        ip = ethlst[0][1]
        cmd = 'netsh wlan show interfaces'
        rrr = os.popen(cmd)
        rrrinfo = rrr.readlines()
        print(rrrinfo)
        for line in rrrinfo:
            if line.find('BSSID') >= 0:
                wifi = line.split(':', 1)[1].strip()
                continue
            if line.find('SSID') >= 0:
                wifiid = line.split(':', 1)[1].strip()
                continue
        return ip, wifi, wifiid, tun, device_id
    for ethinfo in ethlst:
        name, ipinner = ethinfo
        if name.startswith('tun'):
            tun = ipinner
            continue
        if name.startswith('wlan'):
            wifiinfo = termux_wifi_connectioninfo()
            print(wifiinfo)
            wifi = wifiinfo['ssid']
            if wifi.find('unknown ssid') >= 0:
                logstr = f'WIFI处于假连状态:{wifi}\t{ipinner}'
                log.warning(logstr)
                wifi = None
                continue
            wifiid = wifiinfo['bssid']
        ip = ipinner

    return ip, wifi, wifiid, tun, device_id
Example #10
0
    检查联系人和短信数据表是否已经构建,设置相应的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)

    # 短信数据表检查构建
    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"
Example #11
0
    from func.sysfunc import set_timeout, after_timeout, not_IPython


# %%
@set_timeout(240, after_timeout)
@timethis
def foot2record():
    """
    记录位置数据(经纬度等)
    """
    namestr = 'everloc'

    if (device_id := getcfpoptionvalue(namestr, namestr, 'device_id')):
        device_id = str(device_id)
    else:
        device_id = getdeviceid()
        setcfpoptionvalue(namestr, namestr, 'device_id', device_id)

    txtfilename = str(dirmainpath / 'data' / 'ifttt' /
                      f'location_{device_id}.txt')
    print(txtfilename)
    itemread = readfromtxt(txtfilename)
    numlimit = 5  # 显示项目数
    print(itemread[:numlimit])
    tlst = [
        'datetime', 'latitude', 'longitude', 'altitude', 'accuracy', 'bearing',
        'speed', 'elapsedMs', 'provider'
    ]
    locinfo = termux_location()
    print(locinfo)
    nowstr = datetime.datetime.now().strftime('%F %T')
Example #12
0
def show2evernote(imglst):
    deviceid = getdeviceid()
    guid = getinivaluefromnote('freemem', f'free_{deviceid}')
    print(guid)
    if (device_name := getinivaluefromnote('device', deviceid)) is None:
        device_name = deviceid
Example #13
0
# -*- coding: utf-8 -*-
# ---
# jupyter:
#   jupytext:
#     formats: ipynb,py:light
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.3.1
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # 印象笔记

# +
import pathmagic
with pathmagic.context():
    from func.evernttest import findnotebookfromevernote, findnotefromnotebook
    from func.configpr import getcfpoptionvalue
    from etc.getid import getdeviceid

nbdf = findnotebookfromevernote()
ipnbguid = getcfpoptionvalue('everip', getdeviceid(), 'ipnbguid')
ipnbguid
# -
Example #14
0
    if (ulst := splitmjurlfromtext(msgtxt)) and (len(ulst) > 0):
        if getinivaluefromnote("game", "forceupdateexcel"):
            descstr = ''
            for sp in ulst:
                tmpurl, tmpdescstr = geturlcontentwrite2excel(men_wc, sp)
                descstr += tmpdescstr
        else:
            descstr = updateurllst(men_wc, ulst)
        outstr = f"【Text】信息中发现新的火界麻将战绩网页链接并处理:\t{descstr}"
        # log.info(outstr)
        itchat.send_msg(sendernick + outstr)
        makemsg2write(innermsg, outstr)
        makemsg2write(innermsg, msgtxt)

    # 如何不是指定的数据分析中心,则不进行语义分析
    thisid = getdeviceid()
    # print(f"type:{type(thisid)}\t{thisid}")
    houseid = getinivaluefromnote('webchat', 'datahouse')
    mainaccount = getinivaluefromnote('webchat', 'mainaccount')
    # print(f"type:{type(houseid)}\t{houseid}")
    men_wc = getcfpoptionvalue('everwebchat', get_host_uuid(), 'host_nickname')
    if (thisid != str(houseid) or (men_wc != mainaccount)):
        print(f"不是数据分析中心也不是主账号【{mainaccount}】,指令咱不管哦")
        return

    # 根据口令显示火界麻将战绩综合统计结果
    if msg['Text'].startswith('火界麻将战果统计') or msg['Text'].startswith('麻果'):
        log.info(f"根据口令显示火界麻将战绩综合统计结果")
        msgtxt = msg['Text']
        recentday = ""
        if msgtxt.find('日') != -1:
Example #15
0
tablename="phone"
checkphoneinfotable(dbname)

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

ctdonedf = recordctdf_back
ctdonedf

droptablefromdb(dbname, 'phone', confirm=True)

# 联系人数据表检查构建
if not (phonecontactdb := getcfpoptionvalue('everpim', str(getdeviceid()), 'phonecontacttable')) or True:
    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)

dbname

dbname = touchfilepath2depth(getdirmain() / "data" / "db" / f"phonecontact_{getdeviceid()}.db")
tablename="phone"
conn = lite.connect(dbname)
ctdonedf.to_sql(tablename, con=conn, if_exists="append", index=False)
conn.close()
Example #16
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)