Run flask and telebot at the same time
This commit is contained in:
parent
3f2b2379fe
commit
e043fcda7f
17
app.py
17
app.py
@ -1,12 +1,25 @@
|
|||||||
|
import multiprocessing as mp
|
||||||
|
import time
|
||||||
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
|
|
||||||
|
from bot import bot
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def hello_world(): # put application's code here
|
def hello_world():
|
||||||
return 'Hello World!'
|
return 'Hello World!'
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run()
|
proc1 = mp.Process(target=app.run, args=())
|
||||||
|
proc1.start()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
bot.polling(none_stop=True)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[EXCEPTION] {e}")
|
||||||
|
time.sleep(15)
|
||||||
|
15
bot.py
15
bot.py
@ -3,25 +3,31 @@
|
|||||||
# text bot at t.me/projektaktienbot
|
# text bot at t.me/projektaktienbot
|
||||||
# API Documentation https://core.telegram.org/bots/api
|
# API Documentation https://core.telegram.org/bots/api
|
||||||
# Code examples https://github.com/eternnoir/pyTelegramBotAPI#getting-started
|
# Code examples https://github.com/eternnoir/pyTelegramBotAPI#getting-started
|
||||||
|
import os
|
||||||
|
|
||||||
import telebot
|
import telebot
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
from telebot import types
|
from telebot import types
|
||||||
|
|
||||||
bot = telebot.TeleBot("5228016873:AAGFrh0P6brag7oD3gxXjCh5gnLLE8JMvMs")
|
bot = telebot.TeleBot(os.getenv('BOT_API_KEY'))
|
||||||
|
|
||||||
|
|
||||||
@bot.message_handler(commands=['start', 'help'])
|
@bot.message_handler(commands=['start', 'help'])
|
||||||
def send_welcome(message):
|
def send_welcome(message):
|
||||||
bot.reply_to(message, "Thank you for using this bot")
|
bot.reply_to(message, "Thank you for using this bot")
|
||||||
|
|
||||||
|
|
||||||
@bot.message_handler(func=lambda message: True)
|
@bot.message_handler(func=lambda message: True)
|
||||||
def echo_all(message):
|
def echo_all(message):
|
||||||
answer = message.text + ' ID: ' + str(message.from_user.id)
|
answer = message.text + ' ID: ' + str(message.from_user.id)
|
||||||
bot.reply_to(message, answer)
|
bot.reply_to(message, answer)
|
||||||
|
|
||||||
|
|
||||||
telebot.logger.setLevel(logging.DEBUG)
|
telebot.logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
|
||||||
@bot.inline_handler(lambda query: query.query == 'text')
|
@bot.inline_handler(lambda query: query.query == 'text')
|
||||||
def query_text(inline_query):
|
def query_text(inline_query):
|
||||||
try:
|
try:
|
||||||
@ -31,6 +37,7 @@ def query_text(inline_query):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
def main_loop():
|
def main_loop():
|
||||||
bot.infinity_polling()
|
bot.infinity_polling()
|
||||||
while 1:
|
while 1:
|
||||||
|
Loading…
Reference in New Issue
Block a user