Ejemplo n.º 1
0
async def cookie2user(cookie_str):
    """
    Parse cookie and load user if cookie is valid.
    """
    if not cookie_str:
        return None
    try:
        L = cookie_str.split('-')
        if len(L) != 3:
            return None
        uid, expires, sha1 = L
        if int(expires) < time.time():
            return None
        user = await User.find(uid)
        if user is None:
            return None
        s = '%s-%s-%s-%s' % (uid, user.passwd, expires, _COOKIE_KEY)
        if sha1 != hashlib.sha1(s.encode('utf-8')).hexdigest():
            logger.info('invalid sha1')
            return None
        user.passwd = '******'
        return user
    except Exception as e:
        logger.exception(e)
        return None
Ejemplo n.º 2
0
def insert(conn, fid, month, value):
    # date
    hx_range = '国内航线'
    if fid == 6:
        hx_range = '国际航线'

    param = {"FID": fid, "MONTH": month, "RANGE": hx_range, "VALUE": value}
    try:
        my_database.insert_model(conn=conn, param=param)
    except Exception as e:
        if "PK" not in e:
            logger.exception("入库出错" + param)
            logger.error(e)
Ejemplo n.º 3
0
def insert(conn, fid, month, value):
    # date
    param = {
        "FID": fid,
        "MONTH": month,
        "RANGE":"全部航线",
        "VALUE": value
    }
    try:
        my_database.insert_model(conn=conn, param=param)
    except Exception as e:
        if "PK" not in e:
            logger.exception("入库出错" + param)
            logger.error(e)