def create_eventnames(): session = Session() names = session.query(Eventnames).all() for func in functions: if func not in names: session.add(Eventnames(event_name=func)) session.commit() session.close()
def new_token(user_id): session = Session() token = secrets.token_hex() session.add(TokenTable( token=token, user_id=user_id )) session.commit() session.close() return token
def add_music(name, singer): session = Session() song_id = session.query(Musics).count() + 1 session.add( Musics( song_title=name, singer=singer, created_at=datetime.now().isoformat(' ', 'seconds'), )) session.commit() session.close() return song_id
def init_db(): session = Session() session.add( Users( user_name='master', user_password='******', created_at=datetime.now().isoformat(' ', 'seconds'), )) session.add( Musics( song_title='wonder stella', singer='fhana', created_at=datetime.now().isoformat(' ', 'seconds'), )) session.commit() session.close()
def signup(data): name = data['user_name'] user_id = -1 session = Session() user = session.query(Users).filter_by(user_name=name).all() if len(user) == 0: user_id = session.query(Users).count() + 1 session.add( Users(user_name=name, user_password=hashlib.sha256( data['user_password'].encode()).hexdigest(), created_at=datetime.now().isoformat(' ', 'seconds'))) session.commit() msg = 'succeeded to create an user account' else: msg = 'already exists' session.close() return {'user_id': user_id, 'msg': msg}
def init_db(): session = Session() create_eventnames() session.add(Users( user_name='master', user_password='******', created_at=datetime.now().isoformat(' ', 'seconds'), )) session.add(Musics( song_title='wonder stella', singer='fhana', created_at=datetime.now().isoformat(' ', 'seconds'), )) logger.info('{0}@_@{1} {2} {3} {4}'.format( 0, 9, 0, 1, 0 )) session.commit() session.close()
def upload_hash(song_id, h, t, n): # TODO: format table? session = Session() session.add(Hsh(song_id=song_id, hsh_data=h, ptime=t, noise=n)) session.commit() session.close()