diff --git a/display.py b/display.py index d132e89..544e2eb 100644 --- a/display.py +++ b/display.py @@ -1,8 +1,17 @@ +<<<<<<< HEAD +#!/usr/bin/python +======= +#!/usr/bin/env python3 +>>>>>>> b055c788972f0ba38dd50727d9e75908a0579037 + from bs4 import BeautifulSoup import Adafruit_CharLCD as LCD import requests import time import math +import csv +import sys + # Insert your URL here url_c = "https://corona.help/country/switzerland" @@ -11,6 +20,7 @@ cc = "CH" population_w = "7770173166" url_w ="https://corona.help/" +Waiting = '15.0' #Raspberry Pi configuration: @@ -39,15 +49,22 @@ soup_w = BeautifulSoup(page_w.text, 'html.parser') # print (soup) - infections_c = soup_c.select('h1')[1].text.strip() - deaths_c = soup_c.select('h1')[2].text.strip() - survived_c = soup_c.select('h1')[3].text.strip() - - infections_w = soup_w.select('h1')[1].text.strip() - deaths_w = soup_w.select('h1')[2].text.strip() - survived_w = soup_w.select('h1')[3].text.strip() - percent_c = '{:.7f}'.format(int(infections_c) / int(population_c)) - percent_w = '{:.7f}'.format(int(infections_w) / int(population_w)) + country = soup_c.select('h2')[0].text.strip() + infections_c = soup_c.select('h2')[1].text.strip() + deaths_c = soup_c.select('h2')[2].text.strip() + survived_c = soup_c.select('h2')[3].text.strip() + today_c = soup_c.select('h2')[4].text.strip() + + first, last = country.split() + + infections_w = soup_w.select('h2')[1].text.strip() + deaths_w = soup_w.select('h2')[2].text.strip() + survived_w = soup_w.select('h2')[3].text.strip() + today_w = soup_w.select('h2')[4].text.strip() + + percent_c = str('{:.7f}'.format(int(infections_c.replace(',','')) / int(population_c))+(" %")) + percent_w = str('{:.7f}'.format(int(infections_w.replace(',','')) / int(populatio + lcd.set_color(1.0, 0.54, 0.0) @@ -55,25 +72,32 @@ lcd.message(cc + ' Cases ' + infections_c) lcd.message('\nWW Cases ' + infections_w) - time.sleep(20.0) + time.sleep(Waiting) lcd.set_color(0.0, 1.0, 0.0) lcd.clear() lcd.message(cc + ' Recoverd ' + survived_c) lcd.message('\nWW ' + survived_w) - time.sleep(20.0) + time.sleep(Waiting) lcd.set_color(1.0, 0.0, 0.0) lcd.clear() lcd.message(cc +' Dead ' + deaths_c) lcd.message('\nWW Dead ' + deaths_w) - time.sleep(20.0) + time.sleep(Waiting) lcd.set_color(0.2, 0.5, 0.4) lcd.clear() - lcd.message('% of Swiss Population') + lcd.message('% of 'first' Population') lcd.message('\n' + percent_w + '%') - time.sleep(20.0) \ No newline at end of file + time.sleep(Waiting) + + lcd.set_color(0.2, 0.5, 0.4) + lcd.clear() + lcd.message('Infected Today in' +cc) + lcd.message('\n' + today_c) + + time.sleep(Waiting) \ No newline at end of file diff --git a/fetch.py b/fetch.py index c89b8ce..8dc5d64 100644 --- a/fetch.py +++ b/fetch.py @@ -1,10 +1,13 @@ from bs4 import BeautifulSoup import requests +import csv +import sys +import time # Insert your URL here url_c = "https://corona.help/country/switzerland" # Insert your Population here -population_c = "8570000" +population_c = "8173166" population_w = "7770173166" url_w ="https://corona.help/" @@ -13,28 +16,32 @@ page_w = requests.get(url_w) soup_w = BeautifulSoup(page_w.text, 'html.parser') -# print (soup) -country = soup_c.select('h1')[0].text.strip() -infections_c = soup_c.select('h1')[1].text.strip() -deaths_c = soup_c.select('h1')[2].text.strip() -survived_c = soup_c.select('h1')[3].text.strip() +#print (soup_c) -first, *middle, last = country.split() +country = soup_c.select('h2')[0].text.strip() +infections_c = soup_c.select('h2')[1].text.strip() +deaths_c = soup_c.select('h2')[2].text.strip() +survived_c = soup_c.select('h2')[3].text.strip() +today_c = soup_c.select('h2')[4].text.strip() -infections_w = soup_w.select('h1')[1].text.strip() -deaths_w = soup_w.select('h1')[2].text.strip() -survived_w = soup_w.select('h1')[3].text.strip() -percent_c = str('{:.7f}'.format(int(infections_c) / int(population_c))+(" %")) -percent_w = str('{:.7f}'.format(int(infections_w) / int(population_w))+(" %")) +first, last = country.split() + +infections_w = soup_w.select('h2')[1].text.strip() +deaths_w = soup_w.select('h2')[2].text.strip() +survived_w = soup_w.select('h2')[3].text.strip() +today_w = soup_w.select('h2')[4].text.strip() + +percent_c = str('{:.7f}'.format(int(infections_c.replace(',','')) / int(population_c))+(" %")) +percent_w = str('{:.7f}'.format(int(infections_w.replace(',','')) / int(population_w))+(" %")) -print("Cases in " +(last)) +print("Cases in " +(first)) print(("Infections: ") + infections_c + (", Deaths: ") + deaths_c+(", Survived: ")+survived_c) print("Numbers Worldwide") -print(("Infections: ")+infections_w+(", Deaths: ")+ deaths_w +(", Survivied: ") +survived_w) +print(("Infections: ")+infections_w+(", Deaths: ")+ deaths_w +(", Survived: ") +survived_w) -print (percent_c + (" of ")+(last)+ (" citicens are infected!")) +print (percent_c + (" of ")+(first)+ (" citicens are infected!")) print (percent_w + (" of world citicens are infected!")) -print () +#print () diff --git a/get_csv.py b/get_csv.py new file mode 100644 index 0000000..78c60b2 --- /dev/null +++ b/get_csv.py @@ -0,0 +1,18 @@ +#!/usr/bin/python + +import csv +import sys + +#input number you want to search +number = input('Enter number to find\n') + +#read csv, and split on "," the line +csv_file = csv.reader(open('population.csv', "rt"), delimiter=";") + + +#loop through csv list +for row in csv_file: + #if current rows 2nd value is equal to input, print that row + if number == row[0]: + print (row[2]) + print ("succes") \ No newline at end of file diff --git a/population.csv b/population.csv index 4ebc9f0..bfc5d15 100644 --- a/population.csv +++ b/population.csv @@ -1,8 +1,4 @@ -Data Source;World Development Indicators; -;; -Last Updated Date;27.02.2020; -;; -Country Name;Country Code;2018 +Country;Country Code;2018 Aruba;ABW;105845 Afghanistan;AFG;37172386 Angola;AGO;30809762