GadhaGod
Published © MIT

Live Coronavirus Stats Display

An oled displays how many cases, deaths, and recoveries for the coronavirus globally.

BeginnerFull instructions provided2 hours617
Live Coronavirus Stats Display

Things used in this project

Story

Read more

Schematics

corona_schematic_MBUhBrEIcp.fzz

corona schematic

Code

backend.py

Python
# gets the data from the website
import requests


def connect():
    html_code = requests.get("https://www.worldometers.info/coronavirus/").text[:100001]
    html_code_line = html_code.split('\n')
    return html_code_line


class global_data:
    def __init__(self, code):
        self.code = code

    def cases(self):
        cases = self.code[self.code.index('<h1>Coronavirus Cases:</h1>') + 2]
        cases = cases.replace('<span style="color:#aaa">', '')
        cases = cases.replace('</span>', '')
        return cases

    def deaths(self):
        deaths = self.code[self.code.index('<h1>Deaths:</h1>') + 2]
        deaths = deaths.replace('<span>', '')
        deaths = deaths.replace('</span>', '')
        return deaths

    def recoveries(self):
        deaths = self.code[self.code.index('<h1>Recovered:</h1>') + 2]
        recoveries = recoveries.replace('<span>', '')
        recoveries = recoveries.replace('</span>', '')
        return recoveries


def data_return():
    connected = global_data(connect())
    return connected.cases(), connected.deaths(), connected.recoveries()

main.py

Python
import backend
import host
import time
import requests

import Adafruit_GPIO.SPI as SPI
import Adafruit_SSD1306

from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont

import subprocess

RST = None
DC = 23
SPI_PORT = 0
SPI_DEVICE = 0

disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)
disp.begin()
disp.clear()
disp.display()

width = disp.width
height = disp.height
image = Image.new('1', (width, height))
draw = ImageDraw.Draw(image)
draw.rectangle((0,0,width,height), outline=0, fill=0)

padding = -2
top = padding
bottom = height-padding
x = 0

font = ImageFont.load_default()

while True:
    draw.rectangle((0,0,width,height), outline=0, fill=0)

    cases1, deaths1, recoveries1 = backend.global_data.data_return()
    
    cases1 = "Deaths: " + str(cases1)
    deaths1 = "Cases: " + str(deaths1)
    recoveries1 = "Recovered: " + str(recoveries1)

    draw.text((x, top), deaths1,  font=font, fill=255)
    draw.text((x, top+10), cases1, font=font, fill=255)
    draw.text((x, top+20), recoveries1,  font=font, fill=255)

    disp.image(image)
    disp.display()
    time.sleep(.1)
    time.sleep(500)

Credits

GadhaGod

GadhaGod

17 projects • 20 followers
Thanks to shaunikm.

Comments