forked from jonathanrjpereira/Bitcoin-Bar
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bcbar.py
60 lines (42 loc) · 2.04 KB
/
bcbar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# py -2 bcbar.py
# Web Scraping Prerequisites
import requests
# LED Matrix Prerequisites
import re
import time
import argparse
from luma.led_matrix.device import max7219
from luma.core.interface.serial import spi, noop
from luma.core.render import canvas
from luma.core.virtual import viewport
from luma.core.legacy import text, show_message
from luma.core.legacy.font import proportional, CP437_FONT, TINY_FONT, SINCLAIR_FONT, LCD_FONT
quotes_file = open('quotes.txt', 'r')
blacklist_file = open('data_blacklist.txt', 'r')
blacklist = blacklist_file.readlines()
while(1):
page = requests.get("http://www.bitcoinblockhalf.com/")
from bs4 import BeautifulSoup
soup = BeautifulSoup(page.content, 'html.parser') #Scrapes entire HTML file
data = []
for paragraph in soup.find_all('td'): #Search for all values of td elements
data.append(paragraph.string)
disp = [0]*38 #38 is the length of the list data
for x in range(len(data)):
if x % 2 == 0:
if data[x+1] != None and data[x]+'\n' not in blacklist:
disp.append(data[x])
disp.append(data[x+1])
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'
#Remove 'list' in Python2.7
new_quote = quotes_file.readline()
if new_quote == '':
quotes_file = open('quotes.txt', 'r')
new_quote = quotes_file.readline()
disp.insert(0, new_quote)
serial = spi(port=0, device=0, gpio=noop())
device = max7219(serial, cascaded=8 , block_orientation=-90, rotate=2)
for i in range(len(disp)):
show_message(device, disp[i], fill="white", font=proportional(LCD_FONT),scroll_delay = 0.02) #Change the value of 'scroll_delay' to change the Scrolling Speed
#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.
#Change this value according to the table to display various data parameters