def configure_twitter(): # check configuration settings = Status().check_settings() # get the forms for the page form = TwitterForm(request.form) mrof = BotForm(request.form) # blow the flavors into a list flavor_list = [] flavors = Flavors.get_all() for flavor in flavors: flavor_list.append((flavor.id, flavor.description)) mrof.flavor.choices = flavor_list # twitter bot credentials bot = TwitterBot.get() # initialize the bot if it's not if not bot: bot = oauth_initialize() else: if bot.complete == 0: bot = oauth_initialize() if bot.complete == 1 and request.method == "GET": # ensure we don't use stale creds bot = oauth_initialize() elif bot.complete == 1 and request.method == "POST": if form.validate_on_submit(): pin = request.form["pin"] bot = oauth_complete(pin) if bot: flash("Authentication with Twitter complete.", "success") else: flash("Authentication with Twitter failed.", "error") bot = TwitterBot.get() bot.delete(bot) return redirect(url_for(".configure_twitter")) else: # form was not valid, so show errors flash("There were form errors. Please check your entries and try again.", "error") elif request.method == "POST": if mrof.validate_on_submit(): bot.flavor_id = mrof.flavor.data bot.announce = mrof.announce.data bot.max_instances = mrof.max_instances.data bot.updated = int(time.time()) bot.update() if bot.announce > 0: # announce (requires 'settings' in comment to reload stream bot) tweet_status( "Appliance settings updated. Now serving up to (%s) %s instances via '@%s !status'" % (bot.max_instances, bot.flavor.name, bot.screen_name) ) flash("Bot settings updated.", "success") else: # form was not valid, so show errors flash("There were form errors. Please check your entries and try again.", "error") # no bot not hot if not bot: flash("Twitterbot failed to contact Twitter or get credentials.", "error") bot = None else: # set default form values mrof.flavor.data = bot.flavor_id mrof.announce.data = bot.announce return render_template("configure/twitter.html", bot=bot, settings=settings, form=form, mrof=mrof)
def configure_twitter(): # check configuration settings = Status().check_settings() # get the forms for the page form = TwitterForm(request.form) mrof = BotForm(request.form) # blow the flavors into a list flavor_list = [] flavors = Flavors.get_all() for flavor in flavors: flavor_list.append((flavor.id, flavor.description)) mrof.flavor.choices = flavor_list # twitter bot credentials bot = TwitterBot.get() # initialize the bot if it's not if not bot: bot = oauth_initialize() else: if bot.complete == 0: bot = oauth_initialize() if bot.complete == 1 and request.method == 'GET': # ensure we don't use stale creds bot = oauth_initialize() elif bot.complete == 1 and request.method == 'POST': if form.validate_on_submit(): pin = request.form['pin'] bot = oauth_complete(pin) if bot: flash("Authentication with Twitter complete.", "success") else: flash("Authentication with Twitter failed.", "error") bot = TwitterBot.get() bot.delete(bot) return redirect(url_for(".configure_twitter")) else: # form was not valid, so show errors flash( "There were form errors. Please check your entries and try again.", "error") elif request.method == 'POST': if mrof.validate_on_submit(): bot.flavor_id = mrof.flavor.data bot.announce = mrof.announce.data bot.max_instances = mrof.max_instances.data bot.updated = int(time.time()) bot.update() if bot.announce > 0: # announce (requires 'settings' in comment to reload stream bot) tweet_status( "Appliance settings updated. Now serving up to (%s) %s instances via '@%s !status'" % (bot.max_instances, bot.flavor.name, bot.screen_name)) flash("Bot settings updated.", "success") else: # form was not valid, so show errors flash( "There were form errors. Please check your entries and try again.", "error") # no bot not hot if not bot: flash("Twitterbot failed to contact Twitter or get credentials.", "error") bot = None else: # set default form values mrof.flavor.data = bot.flavor_id mrof.announce.data = bot.announce return render_template('configure/twitter.html', bot=bot, settings=settings, form=form, mrof=mrof)