Raspberry Pi : Python code for webscraping share prices

preview_player
Показать описание
Uses Beautiful Soup 4 on Raspberry Pi Zero

#Webscrape #PiZero #RaspberryPi #BeautifulSoup #Python #Code #Examples #SharePrice

Check out the Minimalist online python IDE :

Рекомендации по теме
Комментарии
Автор

#!/usr/bin/env python3
import os, sys
from urllib.request import urlopen
from urllib.error import HTTPError
from urllib.error import URLError
from bs4 import BeautifulSoup
import requests
import time
import scrollphathd as sphd
from scrollphathd.fonts import font3x5
from scrollphathd.fonts import font5x7
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

dT = 30 # Display Duration
wT = 5 # Wait Duration
Bri = 0.4 # Brightness

hur = 'HUR'
sxx = 'SXX'
gnk = 'GNK'

# GET SP
def getSP(ticker):
page = requests.get(url, timeout=30)
soup = BeautifulSoup(page.content, 'html.parser')
tx =
sp = (tx.text[15:21])
return(sp)

# Buzzer setup and sound on startup
PINBuzzer = 22
GPIO.setup(PINBuzzer, GPIO.OUT)
GPIO.output(PINBuzzer, GPIO.LOW)
GPIO.output(PINBuzzer, GPIO.HIGH)
time.sleep(0.3)
GPIO.output(PINBuzzer, GPIO.LOW)
time.sleep(0.2)
GPIO.output(PINBuzzer, GPIO.HIGH)
time.sleep(0.3)
GPIO.output(PINBuzzer, GPIO.LOW)

# Print Welcome Message

sphd.set_brightness(0.4)
x=0, y=0, font=font5x7)
counter = 0
while counter < 94:
sphd.show()
sphd.scroll()
counter += 1
time.sleep(0.05)
sphd.clear()
sphd.show()
time.sleep(1)
# START #
# SHOW SP EVERY 2 mins
while True:

sp = getSP(hur)
print(sp)

GPIO.output(PINBuzzer, GPIO.HIGH)
time.sleep(0.2)
GPIO.output(PINBuzzer, GPIO.LOW)

sphd.write_string(" HUR", font=font3x5, brightness=Bri)
sphd.show()
time.sleep(2)
sphd.clear()
sphd.show()


sphd.write_string("%s" %sp, font=font3x5, brightness=Bri)
sphd.show()
time.sleep(dT)
sphd.clear()
sphd.show()

for x in range(17):
sphd.clear()
for y in range(7):
sphd.set_pixel(x, y, 0.25)
sphd.show()

time.sleep(1/17.0)
sphd.clear()
sphd.show()
time.sleep(wT)
for x in range(17):
sphd.clear()
for y in range(7):
sphd.set_pixel(x, y, 0.3)
sphd.show()

time.sleep(1/17.0)
sphd.clear()
sphd.show()

sp = getSP(sxx)
print(sp)

GPIO.output(PINBuzzer, GPIO.HIGH)
time.sleep(0.2)
GPIO.output(PINBuzzer, GPIO.LOW)

sphd.write_string(" SXX", font=font3x5, brightness=Bri)
sphd.show()
time.sleep(2)
sphd.clear()
sphd.show()

sphd.write_string("%s" %sp, font=font3x5, brightness=Bri)
sphd.show()
time.sleep(dT)
sphd.clear()
sphd.show()

for x in range(17):
sphd.clear()
for y in range(7):
sphd.set_pixel(x, y, 0.25)
sphd.show()

time.sleep(1/17.0)
sphd.clear()
sphd.show()
time.sleep(wT)
for x in range(17):
sphd.clear()
for y in range(7):
sphd.set_pixel(x, y, 0.3)
sphd.show()

time.sleep(1/17.0)
sphd.clear()
sphd.show()

sp = getSP(gnk)
print(sp)
print(" ")
GPIO.output(PINBuzzer, GPIO.HIGH)
time.sleep(0.2)
GPIO.output(PINBuzzer, GPIO.LOW)

sphd.write_string(" GNK", font=font3x5, brightness=Bri)
sphd.show()
time.sleep(2)
sphd.clear()
sphd.show()

sphd.write_string("%s" %sp, font=font3x5, brightness=Bri)
sphd.show()
time.sleep(dT)
sphd.clear()
sphd.show()

for x in range(17):
sphd.clear()
for y in range(7):
sphd.set_pixel(x, y, 0.25)
sphd.show()

time.sleep(1/17.0)
sphd.clear()
sphd.show()
time.sleep(wT)
for x in range(17):
sphd.clear()
for y in range(7):
sphd.set_pixel(x, y, 0.3)
sphd.show()

time.sleep(1/17.0)
sphd.clear()
sphd.show()

python