From e52f93d84a2500916d530ee626b702087118d75d Mon Sep 17 00:00:00 2001 From: deriv <19568048+deriv@users.noreply.github.com> Date: Tue, 17 Mar 2020 08:18:00 +0200 Subject: [PATCH 1/4] Update fetch.py (#4) Fixed typoes by @deriv --- fetch.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fetch.py b/fetch.py index c89b8ce..3028680 100644 --- a/fetch.py +++ b/fetch.py @@ -31,10 +31,10 @@ print("Cases in " +(last)) 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_w + (" of world citicens are infected!")) +print (percent_c + (" of ")+(last)+ (" citizens are infected!")) +print (percent_w + (" of world citizens are infected!")) print () From 9d4cbadd664e307aee29bf67f401938e20d4a052 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Br=C3=BCgger?= Date: Tue, 17 Mar 2020 07:35:57 +0100 Subject: [PATCH 2/4] Changes --- display.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/display.py b/display.py index d132e89..50af5a1 100644 --- a/display.py +++ b/display.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + from bs4 import BeautifulSoup import Adafruit_CharLCD as LCD import requests @@ -74,6 +76,13 @@ lcd.set_color(0.2, 0.5, 0.4) lcd.clear() lcd.message('% of Swiss Population') + lcd.message('\n' + percent_c + '%') + + time.sleep(20.0) + + lcd.set_color(0.2, 0.5, 0.4) + lcd.clear() + lcd.message('% of World Population') lcd.message('\n' + percent_w + '%') time.sleep(20.0) \ No newline at end of file From 156db1b1343cd6fde35bc9fdc286ebf6a8a6c367 Mon Sep 17 00:00:00 2001 From: Julian Bruegger Date: Thu, 19 Mar 2020 21:27:59 +0100 Subject: [PATCH 3/4] Fixed Datasource --- display.py | 48 ++++++++++++++++++++++++++++++++++-------------- fetch.py | 37 ++++++++++++++++++++++--------------- get_csv.py | 18 ++++++++++++++++++ population.csv | 6 +----- 4 files changed, 75 insertions(+), 34 deletions(-) create mode 100644 get_csv.py diff --git a/display.py b/display.py index d132e89..c4a54ea 100644 --- a/display.py +++ b/display.py @@ -1,8 +1,13 @@ +#!/usr/bin/python + 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 +16,7 @@ cc = "CH" population_w = "7770173166" url_w ="https://corona.help/" +Waiting = '15.0' #Raspberry Pi configuration: @@ -39,15 +45,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 +68,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..fff2809 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 (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 From 089406dd6e76b144898e756130722e820d654a87 Mon Sep 17 00:00:00 2001 From: Julian Bruegger Date: Thu, 19 Mar 2020 21:30:28 +0100 Subject: [PATCH 4/4] Merge-Conflict Solved --- display.py | 11 ----------- fetch.py | 6 ------ 2 files changed, 17 deletions(-) diff --git a/display.py b/display.py index 41b89ef..544e2eb 100644 --- a/display.py +++ b/display.py @@ -90,18 +90,7 @@ lcd.set_color(0.2, 0.5, 0.4) lcd.clear() -<<<<<<< HEAD lcd.message('% of 'first' Population') -======= - lcd.message('% of Swiss Population') - lcd.message('\n' + percent_c + '%') - - time.sleep(20.0) - - lcd.set_color(0.2, 0.5, 0.4) - lcd.clear() - lcd.message('% of World Population') ->>>>>>> b055c788972f0ba38dd50727d9e75908a0579037 lcd.message('\n' + percent_w + '%') time.sleep(Waiting) diff --git a/fetch.py b/fetch.py index 1e8bec4..8dc5d64 100644 --- a/fetch.py +++ b/fetch.py @@ -40,14 +40,8 @@ print("Numbers Worldwide") print(("Infections: ")+infections_w+(", Deaths: ")+ deaths_w +(", Survived: ") +survived_w) -<<<<<<< HEAD print (percent_c + (" of ")+(first)+ (" citicens are infected!")) print (percent_w + (" of world citicens are infected!")) #print () -======= -print (percent_c + (" of ")+(last)+ (" citizens are infected!")) -print (percent_w + (" of world citizens are infected!")) -print () ->>>>>>> b055c788972f0ba38dd50727d9e75908a0579037