Пример #1
0
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()
Пример #2
0
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
Пример #3
0
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
Пример #4
0
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()
Пример #5
0
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}
Пример #6
0
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()
Пример #7
0
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()