summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Gonzalez <roger@rogs.me>2020-06-27 12:34:25 -0300
committerRoger Gonzalez <roger@rogs.me>2020-06-27 12:34:25 -0300
commit79e36a6dae42a84df70bea16176202383057e96b (patch)
tree949ec003dfb91856f3e819d3b35ec4b185e8d96e
Initial commit
-rw-r--r--.env.example2
-rw-r--r--.gitignore143
-rwxr-xr-xapp.py40
-rw-r--r--requirements.txt8
4 files changed, 193 insertions, 0 deletions
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": ("<b>Hay citas!</b>\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