commit inicial con todos los archivos

This commit is contained in:
Xaloc 2020-03-21 18:33:03 +01:00
parent 1850185562
commit f897a2d525
6 changed files with 106 additions and 1 deletions

5
LICENSE Normal file
View File

@ -0,0 +1,5 @@
"THE NON-ALCOHOLIC-BEVERAGE-WARE LICENSE":
<xaloc@tutanota.com> wrote this. As long as you retain this notice you can
do whatever you want with this stuff. If we meet some day, and you think this
stuff is worth it, you can buy me a non-alcoholic beverage in return Xaloc

View File

@ -1,3 +1,9 @@
# coronabot
Pequeño bot de telegram para ver como funciona
Pequeño bot de telegram para ver como funciona usando la libreria python-telegram-bot. Este recoge datos de andorra y del mundo sobre los casos de coronavirus. Hay muchos datos ahora, era fácil encontrar datos.
El bot habla catalan y inglés para dar los datos del mundo, lo podeis seguir [aquí](https://t.me/CoronaAndStatsBot)
Para obtener la api para crear un bot hay que hablar con bot father, [aquí](https://core.telegram.org/bots)
Después hay que poner esta llave en config.py, siguiendo el ejemplo de exampleconfig.py.

28
and.py Executable file
View File

@ -0,0 +1,28 @@
#!/usr/bin/python3
#-*- coding: utf-8 -*-
import requests
urlAnd = 'https://www.govern.ad/covid/taula.php'
headers = {'User-Agent':'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0'}
resp = requests.get(urlAnd, headers=headers)
webAnd = resp.text.split("\n")
conf = webAnd[10]
acti = webAnd[11]
hosp = webAnd[12]
conf = conf.split(">",1)[1]
conf = conf.split("<",1)[0]
acti = acti.split(">",1)[1]
acti = acti.split("<",1)[0]
hosp = hosp.split(">",1)[1]
hosp = hosp.split("<",1)[0]
outfile = open("and.txt", "w")
print("Situació Andorra \nCasos confirmats: %s \nCasos actius: %s \nHospitalitzats: %s" %(conf, acti, hosp), file=outfile)
outfile.close()

39
bot.py Executable file
View File

@ -0,0 +1,39 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
import config
TOKEN = config.apiToken
from telegram.ext import Updater
from telegram.ext import CommandHandler
updater = Updater(token=TOKEN, use_context=True)
dispatcher = updater.dispatcher
def start(update, context):
context.bot.send_message(chat_id=update.effective_chat.id, text="Sóc un bot, prova a dir-me /andorra o /world")
start_handler = CommandHandler('start', start)
dispatcher.add_handler(start_handler)
def andorra(update, context):
os.system("./and.py")
text=open("and.txt", "r")
context.bot.send_message(chat_id=update.effective_chat.id, text=text.read())
and_handler = CommandHandler('andorra', andorra)
dispatcher.add_handler(and_handler)
def world(update, context):
os.system("./world.py")
text=open("world.txt", "r")
context.bot.send_message(chat_id=update.effective_chat.id, text=text.read())
world_handler = CommandHandler('world', world)
dispatcher.add_handler(world_handler)
updater.start_polling()

1
exampleconfig.py Normal file
View File

@ -0,0 +1 @@
apiToken="tu api proporcionada por Bot father"

26
world.py Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import requests
url='https://www.worldometers.info/coronavirus/'
response = requests.get(url)
web=response.text.split("\n")
total = web[360]
deaths = web[370]
recovered = web[378]
total = total.split(">",1)[1]
deaths = deaths.split(">",1)[1]
recovered = recovered.split(">",1)[1]
total = total.split(" ",1)[0]
deaths = deaths.split("<",1)[0]
recovered = recovered.split("<",1)[0]
outfile = open("world.txt","w")
print("World situation\nTotal coronavirus cases: %s\nTotal deaths: %s\nRecovered people: %s" %(total, deaths, recovered), file=outfile)