From 67b215386bc8923aef136487bdcfb545f633628f Mon Sep 17 00:00:00 2001 From: alvechdel Date: Fri, 17 Dec 2021 23:00:18 +0100 Subject: [PATCH] feature-telegramBot-005 Change in bot settings for Heorku deploy and add new requirements. --- .gitignore | 1 + decide/decide/settings.py | 5 +---- decide/visualizer/telegramBot.py | 6 +++--- decide/visualizer/website_scrapping.py | 12 ++---------- requirements.txt | 4 +++- 5 files changed, 10 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 99d20becfe..caad338b9e 100644 --- a/.gitignore +++ b/.gitignore @@ -53,6 +53,7 @@ coverage.xml # Django stuff: *.log local_settings.py +decide/*/migrations # Flask stuff: instance/ diff --git a/decide/decide/settings.py b/decide/decide/settings.py index 7129f8c65a..005681e78d 100644 --- a/decide/decide/settings.py +++ b/decide/decide/settings.py @@ -22,9 +22,6 @@ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = '^##ydkswfu0+=ofw0l#$kv^8n)0$i(qd&d&ol#p9!b$8*5%j1+' -# Token for telegram bot -TELEGRAM_TOKEN = '2111051748:AAH1R736I0_HsZEW6_22Tf0r-OqihtF5x88' - # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True @@ -171,7 +168,7 @@ STATIC_URL = '/static/' #temporary link to visualizer page for bots (until hosted) -VISUALIZER_VIEW="http://127.0.0.1:8000/visualizer/" +VISUALIZER_VIEW="https://decide-full-tortuga-2.herokuapp.com/visualizer/" # number of bits for the key, all auths should use the same number of bits KEYBITS = 256 diff --git a/decide/visualizer/telegramBot.py b/decide/visualizer/telegramBot.py index d31cd6ccce..f9e2fef73f 100644 --- a/decide/visualizer/telegramBot.py +++ b/decide/visualizer/telegramBot.py @@ -12,10 +12,10 @@ #auth and front-end for '@VotitosBot' -UPDATER = Updater(settings.TELEGRAM_TOKEN, +UPDATER = Updater(os.environ.get('TELEGRAM_TOKEN'), use_context=True) -BOT=Bot(token=settings.TELEGRAM_TOKEN) +BOT=Bot(token=os.environ.get('TELEGRAM_TOKEN')) #configures and activate '@VotitosBot' to receive any messages from users def init_bot(): @@ -182,7 +182,7 @@ def results_graph(id, chat_identifier, context): url=settings.VISUALIZER_VIEW+ str(id) images=get_graphs(url) if images: - media_group=[InputMediaPhoto(media=i, caption="PUM en la boquita bb") for i in images] + media_group=[InputMediaPhoto(media=i) for i in images] context.bot.sendMediaGroup(chat_id=chat_identifier, media=media_group) else: context.bot.send_message(chat_id=chat_identifier, diff --git a/decide/visualizer/website_scrapping.py b/decide/visualizer/website_scrapping.py index 496db12702..4fb5f62c7c 100644 --- a/decide/visualizer/website_scrapping.py +++ b/decide/visualizer/website_scrapping.py @@ -1,9 +1,8 @@ from bs4 import BeautifulSoup as bs -import lxml import urllib.request as request from urllib.parse import urlparse -#returns images of a voting (FOR NOW) +#returns images of a voting def get_graphs(link): file=request.urlopen(link) s=bs(file, "lxml") @@ -13,13 +12,6 @@ def get_graphs(link): img_url=img.attrs.get("src") if not img_url: continue - if validate_url(img_url): - urls.append(img_url) if len(urls) == 0: urls=False - return urls - -#checks whether url is valid or not (Might be removed in a near future) -def validate_url(link): - parse=urlparse(link) - return bool(parse.netloc) and bool(parse.scheme) \ No newline at end of file + return urls \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index e6a3e782a5..074faa31fc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,4 +14,6 @@ djongo==1.3.6 pymongo==3.12.1 six==1.16.0 sqlparse==0.2.4 -python-telegram-bot==13.8.2 +python-telegram-bot==13.9.0 +bs4 +