def replace_imported_bots(json_text): Game.query.delete() Bot.query.delete() Team.query.delete() data = json.loads(json_text) for team in data['teams']: new_team = Team(team['name']) db.session.add(new_team) for bot in team['bots']: new_bot = Bot(new_team, bot['name'], bot['s3_key']) db.session.add(new_bot) db.session.commit()
def register_user(user_name, user_id, weibo_token, is_bot=None): if is_bot: user = Bot() user.name, user.weibo_id, user.access_token = (user_name, user_id, weibo_token) user.type = 2 db.session.add(user) db.session.commit() else: user = User.query.filter_by(weibo_id=user_id).first() if user: user.access_token, user.name = weibo_token, user_name db.session.commit() else: user = User() user.name, user.weibo_id, user.access_token = (user_name, user_id, weibo_token) db.session.add(user) db.session.commit() return user.generate_token()
#coding: utf-8 from server.base import db from server.config import weibot from server.models import Bot print '=> creating tables' db.create_all() print '=> creating bots' for i in weibot.keys(): b = Bot() b.type = i b.assign(weibot[i]) db.session.add(b) db.session.commit()