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()
def insert_point(**kwargs): session = SESSION() try: roll = RollHistory(**kwargs) session.add(roll) session.commit() except Exception as e: return e finally: session.close()
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()
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()
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()
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()
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()
def delete(self): SESSION.delete(self) SESSION.commit()
def update(self): SESSION.commit()
def add(self): SESSION.add(self) SESSION.commit()