コード例 #1
0
ファイル: ads_view.py プロジェクト: flavluc/flask_app
def show():
    if ("ad_id" in request.args):

        ad = Ad.query.filter_by(id=request.args['ad_id']).first()

        if not ad:
            flash("This is not a valid ID.")
            return render_template("show_error.html")

        bot = Bot()
        if (bot.get_ready()):

            bot.send_msg(ad.rate.comment)
            flash("Message sent successfully!")
            session['num_made_ads'] += 1
            session['comp'] = ""
            session['serv'] = ""
            if ("num_ads" in session and "num_made_ads" in session
                    and session['num_made_ads'] >= session['num_ads']):
                flash("You complete today's batch! Congragulations!")
                return redirect(url_for("ads.index"))

            else:
                return redirect(url_for("ads.handler"))

        else:

            flash("Fail send message, start the bot in the Telegram chat...")
            return render_template("show_error.html")

    else:
        flash("No ad ID specified")
        return render_template("show_error.html")