|
| 1 | +# https://www.facebook.com/permalink.php?story_fbid=1289077461428963&id=100009801635737 |
| 2 | +# subscribed by jay patel |
| 3 | +# python program to check live corona |
| 4 | + |
| 5 | +import pandas as pd |
| 6 | +import seaborn as sns |
| 7 | +import matplotlib.pyplot as plt |
| 8 | +import mysql.connector as mysql |
| 9 | +import requests |
| 10 | +import math |
| 11 | +from bs4 import BeautifulSoup |
| 12 | +from prettytable import PrettyTable |
| 13 | + |
| 14 | + |
| 15 | +from pandas import DataFrame |
| 16 | +import matplotlib.pyplot as plt |
| 17 | +import numpy as np |
| 18 | +from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg |
| 19 | +import tkinter as tk |
| 20 | +from tkinter import ttk |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +url='https://www.worldometers.info/coronavirus/' |
| 25 | +r = requests.get(url) |
| 26 | + |
| 27 | +data =r.text |
| 28 | +soup=BeautifulSoup(data,'html.parser') |
| 29 | + |
| 30 | + |
| 31 | +#Basic data |
| 32 | +print(soup.title.text) |
| 33 | +print() |
| 34 | +live_data = soup.find_all('div',id="maincounter-wrap") |
| 35 | +for i in live_data: |
| 36 | + |
| 37 | + print(i.text) |
| 38 | +print() |
| 39 | +all_rows = soup.find_all('tr') |
| 40 | + |
| 41 | +print('Analyisis based on indivdual countries') |
| 42 | +print() |
| 43 | +#Extrs=acting table data |
| 44 | +table_body = soup.find('tbody') |
| 45 | +table_rows = table_body.find_all('tr') |
| 46 | + |
| 47 | +no = [] |
| 48 | +countries = [] |
| 49 | +cases = [] |
| 50 | +todays =[] |
| 51 | +deaths = [] |
| 52 | + |
| 53 | +for tr in table_rows: |
| 54 | + td=tr.find_all('td') |
| 55 | + countries.append(td[1].text.strip()) |
| 56 | + cases.append(td[2].text.strip()) |
| 57 | + todays.append(td[3].text.strip()) |
| 58 | + deaths.append(td[4].text.strip()) |
| 59 | +#print(countries) |
| 60 | + |
| 61 | +headers = ['Countries','Total cases','Todays cases','death'] |
| 62 | +df = pd.DataFrame(list(zip(countries[8:],cases[8:],todays[8:],deaths[8:])),columns=headers) |
| 63 | +df.to_csv('corona_analyse.csv') |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | +df["Total cases"] = df["Total cases"].str.replace('[\,\.]', '').astype(int) |
| 68 | + |
| 69 | +tc = list(df["Todays cases"]) |
| 70 | +for i in range(len(tc)): |
| 71 | + if(str(tc[i]) == ''): |
| 72 | + tc[i] = "0" |
| 73 | + |
| 74 | +df["Todays cases"] = tc |
| 75 | +df["Todays cases"] = df["Todays cases"].str.replace('[\+\,]','').astype(int) |
| 76 | + |
| 77 | +tc = list(df["death"]) |
| 78 | +for i in range(len(tc)): |
| 79 | + if(str(tc[i]) == ''): |
| 80 | + tc[i] = "0" |
| 81 | +df["death"] = tc |
| 82 | +df["death"] = df["death"].str.replace('[\$\,\.]', '').astype(int) |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | +#df.to_Mysql('coronaData.db') |
| 88 | +print(df) |
| 89 | + |
| 90 | +# y_pos =[i for i in range(1,len(countries)+1)] |
| 91 | + |
| 92 | +# plt.bar(y_pos,cases[::-1],align='center',alpha=0.5) |
| 93 | +# plt.xticks(y_pos,countries[::-1],rotation=5000) |
| 94 | +# plt.ylabel('Total Cases') |
| 95 | + |
| 96 | +# plt.title('Petsonals affect by corona') |
| 97 | +# plt.savefig('corona-analyse.png',dpi=600) |
| 98 | +# plt.show() |
| 99 | + |
| 100 | +country = input("Enter the name of the country : ") |
| 101 | + |
| 102 | + |
| 103 | +selectedCountry=country |
| 104 | + |
| 105 | + |
| 106 | +if (country in list(df['Countries'])): |
| 107 | + #print("Hello1") |
| 108 | + country_details = df[df['Countries'].isin([country])] |
| 109 | + print(country_details) |
| 110 | + case_count = list(country_details["Total cases"])[0] |
| 111 | + todays_count = list(country_details["Todays cases"])[0] |
| 112 | + death_count = list(country_details["death"])[0] |
| 113 | + print("country: " + str(country)) |
| 114 | + print("case_count : " + str(case_count)) |
| 115 | + print("todays_count :" +str(todays_count)) |
| 116 | + print("death_count : " + str(death_count)) |
| 117 | + |
| 118 | +#--------------------------------------------------------- |
| 119 | +r=requests.get('https://pomber.github.io/covid19/timeseries.json') |
| 120 | +data = r.json() |
| 121 | + |
| 122 | +def getChart(): |
| 123 | + |
| 124 | + #country=name.get() |
| 125 | + country=selectedCountry |
| 126 | + print(country) |
| 127 | + |
| 128 | + |
| 129 | + if country=='': |
| 130 | + return |
| 131 | + df=DataFrame(data[country]) |
| 132 | + |
| 133 | + |
| 134 | + figure = plt.figure() |
| 135 | + subplot=figure.add_subplot(111) |
| 136 | + subplot.plot(df['date'],df['confirmed'],label='confirmed',color='blue') |
| 137 | + subplot.plot(df['date'],df['deaths'],label='deaths',color='red') |
| 138 | + subplot.plot(df['date'],df['recovered'],label='recovered',color='green') |
| 139 | + |
| 140 | + subplot.legend(loc='upper left') |
| 141 | + |
| 142 | + start,end=subplot.get_xlim() |
| 143 | + subplot.xaxis.set_ticks(np.arange(start,end,5)) |
| 144 | + |
| 145 | + |
| 146 | + for tick in subplot.get_xticklabels(): |
| 147 | + tick.set_rotation(60) |
| 148 | + |
| 149 | + #canvas = FigureCanvasTkAgg(figure) |
| 150 | + #canvas.get_tk_widget().grid(row=1,column=4,columnspan=3,rowspan=20) |
| 151 | + plt.show() |
| 152 | + |
| 153 | +'''window =tk.Tk() |
| 154 | +
|
| 155 | +name=tk.StringVar() |
| 156 | +nameEntered=ttk.Entry(window,width=30,textvariable=name) |
| 157 | +nameEntered.grid(column=0,row=1) |
| 158 | +
|
| 159 | +button=ttk.Button(window,text="Search trend for country",command=getChart) |
| 160 | +button.grid(column=0,row=2) |
| 161 | +window.mainloop()''' |
| 162 | + |
| 163 | +getChart() |
| 164 | + |
0 commit comments