VPA
Published © GPL3+

Covid19 RGB matrix tableau for multiple countries

Tableau on a 64x32 RGB matrix that displays real-time statistical information on COVID19 in countries with the highest cases of infection.

IntermediateFull instructions provided8 hours1,001
Covid19 RGB matrix tableau for multiple countries

Things used in this project

Hardware components

Raspberry Pi Zero Wireless
Raspberry Pi Zero Wireless
×1
RGB-matrix 64x32
×1
RGB matrix driver for Raspberry Pi
×1
5V 2.5A Switching Power Supply
Digilent 5V 2.5A Switching Power Supply
×1

Software apps and online services

Raspbian
Raspberry Pi Raspbian

Story

Read more

Code

covid19.py

Python
#!/usr/bin/env python

import requests
import time
import lxml.etree
import lxml.html
from rgbmatrix import RGBMatrix, RGBMatrixOptions
from rgbmatrix import graphics
from PIL import Image

# Configuration for the matrix
options = RGBMatrixOptions()

#adafruit-hat
#options.hardware_mapping = 'regular'
options.rows = 32
options.cols = 64
options.chain_length = 1
options.parallel = 1
options.row_address_type = 0
options.multiplexing = 0
options.pwm_bits = 11
options.brightness = 100
options.pwm_lsb_nanoseconds = 130
options.led_rgb_sequence = "RGB"
options.pixel_mapper_config = ""


matrix = RGBMatrix(options = options)

#
url="https://www.worldometers.info/coronavirus/";
stat={'country':'0','totalcases':'0','newcases':'0','newdeaths':'0'}
countries={'Russia':'ru.png',
           'USA':'us.png',
           'UK':'uk.png',
           'Brazil':'br.png',
           'Spain':'es.png',
           'Italy':'it.png',
           'India':'in.png',
           'France':'fr.png',
           'Germany':'de.png',
           'Turkey':'tr.png',
 }

pos=0
offset=0;

matrix.Clear()

canvas=matrix
font1 = graphics.Font()
font1.LoadFont("../../../fonts/7x13.bdf")
font2 = graphics.Font()
font2.LoadFont("../../../fonts/5x7.bdf")
font3 = graphics.Font()
font3.LoadFont("../../../fonts/4x6.bdf")
textColor1 = graphics.Color(0, 255, 0)
textColor2 = graphics.Color(0, 0, 255)
textColor3 = graphics.Color(0, 0, 255)
textColor4 = graphics.Color(0, 255, 0)
textColor5 = graphics.Color(255, 0, 0)

s = graphics.DrawText(canvas, font1, 10, 15, textColor1, "covid19")
#time.sleep(2)   


def prepare(url):
    url = requests.get(url)
    tree = fromstring(url.text)
    tree.make_links_absolute(url.url)
    return tree

while True:
   for pos in range(9,23):  
      r = requests.get("https://www.worldometers.info/coronavirus/")
      root = lxml.html.fromstring(r.content)

      totalcases=root.xpath('//*[@id="main_table_countries_today"]/tbody[1]/tr['+str(pos)+']/td[3]')
      newcases=root.xpath('//*[@id="main_table_countries_today"]/tbody[1]/tr['+str(pos)+']/td[4]')
      newdeaths=root.xpath('//*[@id="main_table_countries_today"]/tbody[1]/tr['+str(pos)+']/td[6]')
      country=root.xpath('//*[@id="main_table_countries_today"]/tbody[1]/tr['+str(pos)+']/td[2]/a/text()')

      # 
      print("pos=",pos)
      print("country=",country[0])
      if countries.get(country[0])!=None:
         print("countries=",countries[country[0]])
      print("totalcases=",totalcases[0].text)
      print("newcases=",newcases[0].text)
      print("newdeaths=",newdeaths[0].text)
      print("----------------")
      #time.sleep(1)

      #
      matrix.Clear()
      #
      if countries.get(country[0])!=None:
         image = Image.open("flags/"+countries[country[0]])
         image.thumbnail((16, 16), Image.ANTIALIAS)
         matrix.SetImage(image.convert('RGB'))
      #
      graphics.DrawText(canvas, font2, 20, 8, textColor1, country[0])
      #
      if(newcases[0].text==None):
         graphics.DrawText(canvas, font3, 2, 20, textColor2, "+0")
      else:
         graphics.DrawText(canvas, font3, 2, 20, textColor2, newcases[0].text)
      #
      if(newdeaths[0].text==None):
         graphics.DrawText(canvas, font3, 35, 20, textColor5, "+0")
      else:
         graphics.DrawText(canvas, font3, 35, 20, textColor5, newdeaths[0].text)
      graphics.DrawText(canvas, font2, 10, 30, textColor2, totalcases[0].text)
      #time.sleep(1)


   

Credits

VPA

VPA

6 projects • 28 followers
Author of more than 10 books on programming (web, Arduino, Raspberry pi, IoT), developer and teacher.

Comments