Advertisement
Guest User

Covid19 stat

a guest
Apr 10th, 2020
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.72 KB | None | 0 0
  1. import json
  2. import wget
  3. import os.path
  4. import tkinter
  5. import matplotlib.pyplot as plt
  6.  
  7. def dothis(orszag):
  8.     global adatok
  9.     URL = 'https://pomber.github.io/covid19/timeseries.json'
  10.     if not os.path.exists('timeseries.json'):
  11.         wget.download(URL, 'C:\\Users\\Svab\\PycharmProjects\\covid\\timeseries.json')
  12.     else:
  13.         os.remove('timeseries.json')
  14.         wget.download(URL, 'C:\\Users\\Svab\\PycharmProjects\\covid\\timeseries.json')
  15.     with open('timeseries.json') as f:
  16.         data = json.load(f)
  17.  
  18.     hun = data[orszag]
  19.     data.keys()
  20.  
  21.     adatok = []
  22.     for i in hun:
  23.         adatok.append([i['date'], i['confirmed'], i['deaths'], i['recovered']])
  24.  
  25.     for j in range(len(adatok)):
  26.         adatok[j].append(adatok[j][1] - adatok[j][2] - adatok[j][3])
  27.  
  28. def readcountries():
  29.     global countries
  30.     countries = []
  31.     with open('counties.txt') as f:
  32.         for c in f:
  33.             countries.append(c.split('\n'))
  34.     for shit in range(len(countries)):
  35.         countries[shit].remove(countries[shit][1])
  36.  
  37. def mutat():
  38.     global adatok
  39.     global lb
  40.     screen = tkinter.Tk()
  41.     screen.geometry('1280x768')
  42.     country = lb.get(tkinter.ACTIVE)
  43.     screen.title('\'{}\' Adatai'.format(country))
  44.  
  45.     dothis(country)
  46.  
  47.     vbar = tkinter.Scrollbar(screen)
  48.     vbar.pack(side=tkinter.RIGHT, fill=tkinter.Y)
  49.     text = tkinter.Text(screen, wrap=tkinter.WORD, yscrollcommand=vbar.set, height=700, width=200)
  50.     text.pack()
  51.     vbar.config(command=text.yview)
  52.  
  53.     #'{}'.format(adatok[i][0])
  54.     text.insert(tkinter.END, 'Dátum{}'.format(15*' '))
  55.     text.insert(tkinter.END, 'Megerősített fertőzött{}'.format(15*' '))
  56.     text.insert(tkinter.END, 'Halálok száma{}'.format(15*' '))
  57.     text.insert(tkinter.END, 'Meggyógyult{}'.format(20*' '))
  58.     text.insert(tkinter.END, 'Aktív eset\n')
  59.  
  60.     for i in range(len(adatok)):
  61.         text.insert(tkinter.END, '{}{}'.format((adatok[i][0]), 25*' '))
  62.         text.insert(tkinter.END, '{}{}'.format((adatok[i][1]), 25*' '))
  63.         text.insert(tkinter.END, '{}{}'.format((adatok[i][2]), 25*' '))
  64.         text.insert(tkinter.END, '{}{}'.format((adatok[i][3]), 28*' '))
  65.         text.insert(tkinter.END, '{}\n'.format(adatok[i][4]))
  66.  
  67.     x_tengely = []
  68.     y_esetek = []
  69.     y_halalok = []
  70.     y_gyogyultak = []
  71.     y_aktiv = []
  72.  
  73.     for xt in range(len(adatok)):
  74.         x_tengely.append(adatok[xt][0][5:])
  75.     for y1 in range(len(adatok)):
  76.         y_esetek.append(adatok[y1][1])
  77.     for y2 in range(len(adatok)):
  78.         y_halalok.append(adatok[y2][2])
  79.     for y3 in range(len(adatok)):
  80.         y_gyogyultak.append(adatok[y3][3])
  81.     for y4 in range(len(adatok)):
  82.         y_aktiv.append(adatok[y4][4])
  83.  
  84.     plt.plot(x_tengely, y_esetek, label='Megerositett esetek')
  85.     plt.plot(x_tengely, y_aktiv, label='Aktív esetek')
  86.     plt.plot(x_tengely, y_gyogyultak, label='Meggyógyultak')
  87.     plt.plot(x_tengely, y_halalok, label='Halálok')
  88.  
  89.     plt.xlabel('Dátum')
  90.     plt.ylabel('Szám')
  91.     plt.title('\'{}\' statisztikai gráfja'.format(country))
  92.     plt.legend()
  93.     plt.show()
  94.  
  95. def window():
  96.     global countries
  97.     global lb
  98.     screen = tkinter.Tk()
  99.     screen.geometry('300x540')
  100.     screen.title('COVID19')
  101.  
  102.     tkinter.Label(screen, text='Orszagok').pack()
  103.  
  104.     scroll = tkinter.Scrollbar(screen)
  105.     scroll.pack(side=tkinter.RIGHT, fill=tkinter.Y)
  106.     lb = tkinter.Listbox(screen, height=30, width=50, bd=3)
  107.     lb.pack(fill=tkinter.Y)
  108.     for item in countries:
  109.         lb.insert(tkinter.END, item[0])
  110.     lb.config(yscrollcommand=scroll.set)
  111.     scroll.config(command=lb.yview)
  112.  
  113.     bt = tkinter.Button(screen, text='Mutat', command=mutat)
  114.     bt.pack()
  115.  
  116.  
  117.     screen.mainloop()
  118.  
  119. readcountries()
  120.  
  121. window()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement