Esempio n. 1
0
def verify(user_id, code):
    session = SESSION()
    try:
        if not code.isdigit():
            return None
        nmc = session.query(NewMemberCaptcha).filter_by(
            user_id=user_id, is_verify=0, verify_code=int(code)).first()
        if not nmc:
            # sql = '''
            # SELECT id FROM new_member_captcha WHERE verify_code={}
            # '''.format(code)
            # res = session.execute(sql)
            # message = ""
            # for r in res:
            #     message += str(r)
            return None
        # if code != str(nmc.verify_code):
        #     return "验证码错误"
        nmc.is_verify = 1
        session.commit()
        return nmc.group_id
    except Exception as e:
        return None
    finally:
        session.close()
Esempio n. 2
0
def find_lib(lib_name):
    session = SESSION()
    try:
        return session.query(PythonLibs).filter_by(name=lib_name).first()
    except Exception as e:
        return None
    finally:
        session.close()
Esempio n. 3
0
def search_captcha(**kwargs):
    session = SESSION()
    try:
        return session.query(NewMemberCaptcha).filter_by(**kwargs).first()
    except Exception as e:
        return None
    finally:
        session.close()
Esempio n. 4
0
def insert_point(**kwargs):
    session = SESSION()
    try:
        roll = RollHistory(**kwargs)
        session.add(roll)
        session.commit()
    except Exception as e:
        return e
    finally:
        session.close()
Esempio n. 5
0
def get_need_increase():
    session = SESSION()
    try:
        days = session.query(Days).all()
        for d in days:
            yield d
    except Exception as e:
        pass
    finally:
        session.close()
Esempio n. 6
0
def count_my_roll(group_id, user_id):
    session = SESSION()
    try:
        res = session.query(func.sum(RollHistory.point).label('s')).filter_by(
            group_id=group_id, user_id=user_id).first()
        if res:
            return res[0]
        return 0
    except Exception as e:
        return 0
    finally:
        session.close()
Esempio n. 7
0
def find_lang_ref(many=False, **kwargs):
    session = SESSION()
    try:
        res = session.query(PythonLangRef).filter_by(**kwargs)
        if not many:
            return res.first()
        else:
            return res.all()
    except Exception as e:
        return None
    finally:
        session.close()
Esempio n. 8
0
def count_toady_roll(**kwargs):
    session = SESSION()
    try:
        today_start = time.mktime(datetime.today().date().timetuple())
        today_end = today_start + 86400
        res = session.query(RollHistory).filter_by(**kwargs).filter(
            today_start < RollHistory.roll_time,
            today_end > RollHistory.roll_time)
        return res.count()
    except Exception as e:
        return 0
    finally:
        session.close()
Esempio n. 9
0
def increase_one(user_id):
    session = SESSION()
    try:
        d = session.query(Days).filter_by(user_id=user_id).first()
        if not d:
            return
        d.days += 1
        session.commit()
    except Exception as e:
        print(e)
        session.rollback()
    finally:
        session.close()
Esempio n. 10
0
def count_most_times(group_id):
    session = SESSION()
    try:
        res = session.query(
            RollHistory.user_id,
            func.count(RollHistory.user_id).label('t')).filter_by(
                group_id=group_id).group_by(RollHistory.user_id).order_by(
                    desc('t')).first()
        if res:
            return res
        return 0, 0
    except Exception as e:
        return 0, 0
    finally:
        session.close()
Esempio n. 11
0
def insert_lang_ref(**kwargs):
    session = SESSION()
    try:
        lang = session.query(PythonLangRef).filter_by(
            title1=kwargs.get('title1'), title2=kwargs.get('title2')).first()
        if lang:
            lang.update(**kwargs)
        else:
            lang = PythonLangRef(**kwargs)
            session.add(lang)
        session.commit()
    except Exception as e:
        pass
    finally:
        session.close()
Esempio n. 12
0
def insert_new_captcha(**kwargs):
    '''

    :param kwargs: group_id, user_id, verify_code
    :return:
    '''
    nmc = NewMemberCaptcha(**kwargs)
    session = SESSION()
    try:
        session.add(nmc)
        session.commit()
    except Exception as e:
        pass
    finally:
        session.close()
Esempio n. 13
0
def insert_lib(**kwargs):
    session = SESSION()
    try:
        lib = session.query(PythonLibs).filter_by(
            name=kwargs.get('lib_name')).first()
        if lib:
            lib.update(**kwargs)

        else:
            lib = PythonLibs(**kwargs)
            session.add(lib)
        session.commit()
    except Exception as e:
        pass
    finally:
        session.close()
Esempio n. 14
0
def to_zero(user_id):
    session = SESSION()
    try:
        d = session.query(Days).filter_by(user_id=user_id).first()
        if not d:
            d = Days(user_id=user_id, days=0)
            session.add(d)
            session.commit()
            return
        d.days = 0
        session.commit()
        return True
    except Exception as e:
        session.rollback()
    finally:
        session.close()