bitbar.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # py -2 bcbar.py
  2. import requests
  3. # import re
  4. # import time
  5. # import argparse
  6. # from luma.led_matrix.device import max7219
  7. # from luma.core.interface.serial import spi, noop
  8. # from luma.core.render import canvas
  9. # from luma.core.virtual import viewport
  10. # from luma.core.legacy import text, show_message
  11. # from luma.core.legacy.font import proportional, CP437_FONT, TINY_FONT, SINCLAIR_FONT, LCD_FONT
  12. page = requests.get("http://www.bitcoinblockhalf.com/")
  13. #print (page.status_code)
  14. #print (page.content)
  15. from bs4 import BeautifulSoup
  16. soup = BeautifulSoup(page.content, 'html.parser')
  17. #print(soup.prettify())
  18. #list(soup.children)
  19. #print([type(item) for item in list(soup.children)])
  20. #print(soup.find_all('td'))
  21. #for paragraph in soup.find_all('td'):
  22. # print (paragraph.string)
  23. data = []
  24. for paragraph in soup.find_all('td'):
  25. data.append(paragraph.string)
  26. # print (data)
  27. disp = [0]*38
  28. for x in range(len(data)):
  29. if x % 2 == 0:
  30. disp.append(data[x])
  31. if data[x+1] == None:
  32. disp.append(data[x+1])
  33. else:
  34. disp.append((data[x+1]).replace(',',''))
  35. # print (disp)
  36. disp = list(filter(lambda a:a != 0, disp))
  37. # print (disp)
  38. #coins_2b_mined = (data[7].replace(',','')) #data[1] is the Coins remaining to be Mined. replace() removes the ',' from the string. int() coverts the string into an into
  39. #coins_2b_mined = data[7] #Valuw with commas does not look neat on Dot Matrix display.
  40. # serial = spi(port=0, device=0, gpio=noop())
  41. # device = max7219(serial, cascaded=4 , block_orientation=-90, rotate=2)
  42. #
  43. # show_message(device, data[6] + coins_2b_mined, fill="white", font=proportional(LCD_FONT),scroll_delay = 0.04)
  44. ##with canvas(device) as draw:
  45. ## text(draw, (0, 0), msg, fill="white", font=proportional(LCD_FONT))