Beispiel #1
0
import subprocess
import shlex
from flask import Flask, request, jsonify

from config import TELEGRAM_INIT_WEBHOOK_URL as webhook, WEBHOOK_HOSTNAME as hostname
from bot import TelegramBot

app = Flask(__name__)

if not TelegramBot.init_webhook(webhook):
    try:
        raise RuntimeError
    finally:
        print("Webhook not initialized properly")


@app.route("/webhook", methods=["POST"])
def index():
    res = request.get_json()
    robot = TelegramBot()
    robot.parseData(res)
    isSuccessful = robot.conditionalResponse()
    return jsonify(success=isSuccessful)


def webhookProccess(hostname):
    shCommand = "ssh -o ServerAliveInterval=60 -R {}:80:localhost:8888 serveo.net".format(
        hostname)
    args = shlex.split(shCommand)
    subprocess.Popen(args)
Beispiel #2
0
from flask import Flask, jsonify

from bot import TelegramBot
from config import TELEGRAM_INIT_WEBHOOK_URL
from ticket_bot import search_tickets
from apscheduler.schedulers.background import BackgroundScheduler

app = Flask(__name__)
TelegramBot.init_webhook(TELEGRAM_INIT_WEBHOOK_URL)


@app.route('/', methods=['GET'])
def index():
    return jsonify(message="Server is running")


@app.route('/webhook', methods=['POST'])
def telegram_post():
    print("New webhook request")
    return {"message": "Request from telegram is processed"}


cron = BackgroundScheduler(daemon=True)
cron.add_job(search_tickets,
             'interval',
             hours=12,
             kwargs={
                 'min_days': 3,
                 'max_days': 7,
                 'departure_months': [4],
                 'departure_days': [1]