bcbar.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # py -2 bcbar.py
  2. # Web Scraping Prerequisites
  3. import requests
  4. # LED Matrix Prerequisites
  5. import re
  6. import time
  7. import argparse
  8. from luma.led_matrix.device import max7219
  9. from luma.core.interface.serial import spi, noop
  10. from luma.core.render import canvas
  11. from luma.core.virtual import viewport
  12. from luma.core.legacy import text, show_message
  13. from luma.core.legacy.font import proportional, CP437_FONT, TINY_FONT, SINCLAIR_FONT, LCD_FONT
  14. while(1):
  15. page = requests.get("http://www.bitcoinblockhalf.com/")
  16. from bs4 import BeautifulSoup
  17. soup = BeautifulSoup(page.content, 'html.parser') #Scrapes entire HTML file
  18. data = []
  19. for paragraph in soup.find_all('td'): #Search for all values of td elements
  20. data.append(paragraph.string)
  21. disp = [0]*38 #38 is the length of the list data
  22. for x in range(len(data)):
  23. if x % 2 == 0:
  24. if data[x+1] != None:
  25. disp.append(data[x])
  26. disp.append(data[x+1])
  27. disp = list(filter(lambda a:a != 0, disp)) #For some reason every odd element of the list 'disp' is '0'. This removes all occurences of '0' from the list 'disp'
  28. disp = list(filter(lambda a:a != None, disp)) #If an element is missing, it shows as 'None' and crashes the script. This removes all occurences of 'None' from the list 'disp'
  29. #Remove 'list' in Python2.7
  30. serial = spi(port=0, device=0, gpio=noop())
  31. device = max7219(serial, cascaded=4 , block_orientation=-90, rotate=0)
  32. for i in range(len(disp)):
  33. show_message(device, disp[i], fill="white", font=proportional(LCD_FONT),scroll_delay = 0.04) #Change the value of 'scroll_delay' to change the Scrolling Speed
  34. #show_message(device, disp[4], fill="white", font=proportional(LCD_FONT),scroll_delay = 0.02) # '4' indicates Displays the number of Bitcoins left to mine.
  35. #Change this value according to the table to display various data parameters