Skip to content

Commit

Permalink
feature-telegramBot-005
Browse files Browse the repository at this point in the history
Change in bot settings for Heorku deploy and add new requirements.
  • Loading branch information
alvechdel committed Dec 17, 2021
1 parent ce636e0 commit 67b2153
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ coverage.xml
# Django stuff:
*.log
local_settings.py
decide/*/migrations

# Flask stuff:
instance/
Expand Down
5 changes: 1 addition & 4 deletions decide/decide/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions decide/visualizer/telegramBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 2 additions & 10 deletions decide/visualizer/website_scrapping.py
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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)
return urls
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 67b2153

Please sign in to comment.