Skip to content

Instantly share code, notes, and snippets.

@lakomyt
Last active April 25, 2020 11:39
Show Gist options
  • Save lakomyt/75f46a44bd3345fc30f49c25307a8ec9 to your computer and use it in GitHub Desktop.
Save lakomyt/75f46a44bd3345fc30f49c25307a8ec9 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
import requests
from bs4 import BeautifulSoup
def coronavirus():
url = "https://www.worldometers.info/coronavirus/"
soup = BeautifulSoup(requests.get(url).text, "html.parser")
table = soup.find("tbody")
rows = table.findAll("tr", attrs={"style":""})
countries = {}
for row in rows:
cols = row.findAll("td")[1:]
numbers = []
for col in cols:
if len(col.contents) > 0:
number = str(col.contents[0])
if "+" in number:
number = number.replace("+","")
if "," in number:
number = number.replace(",","")
try:
numbers.append(float(number))
except:
numbers.append(0.0)
else:
numbers.append(0.0)
country = row.findAll("td")[0].contents[0]
if len(country) == 1:
try:
country = row.findAll("td")[0].a.contents[0]
except:
country = "Diamond Princess"
countries[country.strip()]=numbers
return countries
def etf():
url = "https://bankier.pl/notowania/indeksy-gpw/ETFSP500"
soup = BeautifulSoup(requests.get(url).text, "html.parser")
num = soup.find_all("div", attrs={"class":"profilLast"})[0].contents[0]
return num
countries = coronavirus()
num = etf()
with open("/home/pi/Documents/coronavirus","w") as f:
content = ""
content += "POLAND, total victims: " + str(countries["Poland"][0]).replace(".0","") + "\n"
content += "POLAND, total recovered: " + str(countries["Poland"][4]).replace(".0","") + "\n"
content += "POLAND, total deaths: " + str(countries["Poland"][2]).replace(".0","") + "\n\n"
content += "ŚWIAT, zarażeni: " + str(countries["World"][0]).replace(".0","") + "\n"
content += "ŚWIAT, wyleczeni: " + str(countries["World"][4]).replace(".0","") + "\n"
content += "ŚWIAT, śmierci: " + str(countries["World"][2]).replace(".0","") + "\n\n"
content += "ETF: " + num + "zł"
f.write(content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment