Last active
March 12, 2020 07:49
-
-
Save ssalvatella/cb4cdf03aee5c25b4196f4c170f02c36 to your computer and use it in GitHub Desktop.
Consulta la cifra de infectados en el Ministerio de Sanidad y envía una notificación al SO si ha cambiado
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# | |
# Consulta la cifra de infectados en el Ministerio de Sanidad | |
# y envía una notificación al SO si ha cambiado. | |
# Añadir al cron para que se ejecute cada 5 minutos. | |
# | |
# Dependencia: sudo apt-get install libnotify-bin | |
# | |
import os.path | |
from lxml import html | |
import requests | |
import subprocess | |
page = requests.get('http://www.mscbs.gob.es/profesionales/saludPublica/ccayes/alertasActual/nCov-China/situacionActual.htm', verify=False) | |
tree = html.fromstring(page.content) | |
infectados = tree.xpath('//div[@class="banner-coronavirus banner-verde"]/p')[0].text | |
if os.path.isfile('/tmp/ultimos_infectados.txt'): | |
fr = open('/tmp/ultimos_infectados.txt', 'r') | |
ultimos_infectados = fr.read() | |
else: | |
fw = open('/tmp/ultimos_infectados.txt', 'w') | |
fw.write(infectados) | |
fw.close() | |
ultimos_infectados = infectados | |
# Si la cifra ha cambiado envía una notificación con notify-send | |
if (ultimos_infectados != infectados): | |
subprocess.Popen(['notify-send', "COVID-19: " + infectados +" en España"]) | |
fw = open('/tmp/ultimos_infectados.txt', 'w') | |
fw.write(infectados) | |
fw.close() | |
print(infectados) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment