Complete bot.py. Add groups to config. Change /post to POST.

Update gitignore.
This commit is contained in:
Ceda EI 2019-01-22 16:54:57 +05:30
parent 68a4d440e6
commit d7c4f7e14c
4 changed files with 20 additions and 2 deletions

1
.gitignore vendored
View File

@ -114,3 +114,4 @@ dmypy.json
# Pyre type checker
.pyre/
config.py

View File

@ -1,13 +1,27 @@
#!/usr/bin/env python3
import config
import logging
import requests
from telegram.ext import Updater, MessageHandler, Filters
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - \
%(message)s', level=logging.INFO)
def message_handling(bot, update):
pass
print("in here")
if update.message.chat.id in config.groups:
print("in here")
for i in update.message.text.split("\n"):
params = {"message": (f"TG - {update.message.from_user.first_name}"
f": {i}")}
requests.post("http://localhost:" + str(config.port) + "/post",
data=params)
print(params)
updater = Updater(token=config.api_key)
dispatcher = updater.dispatcher
dispatcher.add_handler(MessageHandler(Filters.text, message_handling))
updater.start_polling()

View File

@ -4,3 +4,6 @@ api_key = "123456789:xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# Port to connect to server
port = 9876
# Groups to read from
groups = []

View File

@ -21,4 +21,4 @@ with open('schema.sql') as fp:
cursor.executescript(fp.read())
app.add_url_rule('/get', 'get', lambda: get(db))
app.add_url_rule('/post', 'post', lambda: post(db))
app.add_url_rule('/post', 'post', lambda: post(db), methods=["POST"])