From 79e36a6dae42a84df70bea16176202383057e96b Mon Sep 17 00:00:00 2001 From: Roger Gonzalez Date: Sat, 27 Jun 2020 12:34:25 -0300 Subject: Initial commit --- .env.example | 2 + .gitignore | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ app.py | 40 ++++++++++++++++ requirements.txt | 8 ++++ 4 files changed, 193 insertions(+) create mode 100644 .env.example create mode 100644 .gitignore create mode 100755 app.py create mode 100644 requirements.txt diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..2608a11 --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +TELEGRAM_BOT_ID=your_bot_id +TELEGRAM_CHAT_ID=your_chat_id diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..87d8735 --- /dev/null +++ b/.gitignore @@ -0,0 +1,143 @@ +.DS_Store +.idea +*.log +tmp/ + +# Created by https://www.toptal.com/developers/gitignore/api/python +# Edit at https://www.toptal.com/developers/gitignore?templates=python + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# End of https://www.toptal.com/developers/gitignore/api/python diff --git a/app.py b/app.py new file mode 100755 index 0000000..d0c5305 --- /dev/null +++ b/app.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 + +import os +import requests + +from datetime import datetime + +from selenium import webdriver +from selenium.webdriver.firefox.options import Options + +from dotenv import load_dotenv + +load_dotenv() + +TELEGRAM_BOT_ID = os.environ.get('TELEGRAM_BOT_ID') +TELEGRAM_CHAT_ID = os.environ.get('TELEGRAM_CHAT_ID') +SAE_URL = 'https://sae.mec.gub.uy/sae/agendarReserva/Paso1.xhtml?e=9&a=7&r=13' + +options = Options() +options.headless = True +d = webdriver.Firefox(options=options) +d.get(SAE_URL) +print(f'Headless Firefox Initialized {datetime.now()}') +elem = d.find_element_by_name('form:botonElegirHora') +elem.click() +try: + warning_message = d.find_element_by_id('form:warnSinCupos') + print('No dates yet') + print('------------------------------') +except Exception: + telegram_data = { + "chat_id": TELEGRAM_CHAT_ID, + "parse_mode": "HTML", + "text": ("Hay citas!\nHay citas en el registro civil, para " + f"entrar ve a {SAE_URL}") + } + requests.post('https://api.telegram.org/bot' + f'{TELEGRAM_BOT_ID}/sendmessage', data=telegram_data) + print('Dates found!') +d.close() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e2acddc --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +certifi==2020.6.20 +chardet==3.0.4 +idna==2.9 +python-dotenv==0.13.0 +requests==2.24.0 +selenium==3.141.0 +soupsieve==2.0.1 +urllib3==1.25.9 -- cgit v1.2.3