Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from bs4 import BeautifulSoup as bs
- from time import sleep
- from Adafruit_CharLCD import Adafruit_CharLCD
- ##try:
- ## res = requests.get('https://bustime.mta.info/m/index;jsessionid=4EA63E7418A423600513FEA992FBEFF4?q=103925')
- ##except Exception as exc:
- ## print('Error: %s' %(exc))
- ##splitFile = res.text.split('BxM9')
- ##bx40 = bs(splitFile[0],"html.parser")
- ##bxm9 = bs(splitFile[2],"html.parser")
- ##bx40List = bx40.select('body div div div li strong ')
- ##bxm9List = bxm9.select('ol li strong')
- ##
- ##bx40List = [tag.getText() for tag in bx40List]
- ##bxm9List = [tag.getText() for tag in bxm9List]
- ##
- ##bx40List = [tag.replace('away','') for tag in bx40List]
- ##bxm9List = [tag.replace('away','') for tag in bxm9List]
- ##
- ##print(bx40List)
- ##print(bxm9List)
- ##
- ##
- ##
- # instantiate lcd and specify pins
- lcd = Adafruit_CharLCD(rs=26, en=19,
- d4=13, d5=6, d6=5, d7=11,
- cols=16, lines=2)
- lcd.clear()
- # display text on LCD display \n = new line
- flag = True
- while flag:
- try:
- res = requests.get('https://bustime.mta.info/m/index;jsessionid=4EA63E7418A423600513FEA992FBEFF4?q=103925')
- except Exception as exc:
- print('Error: %s' %(exc))
- splitFile = res.text.split('BxM9')
- bx40 = bs(splitFile[0],"html.parser")
- bxm9 = bs(splitFile[2],"html.parser")
- bx40List = bx40.select('body div div div li strong ')
- bxm9List = bxm9.select('ol li strong')
- bx40List = [tag.getText() for tag in bx40List]
- bxm9List = [tag.getText() for tag in bxm9List]
- bx40List = [tag.replace('away','') for tag in bx40List]
- bxm9List = [tag.replace('away','') for tag in bxm9List]
- lcd.clear()
- try:
- if len(bx40List) == 0:
- lcd.message('Bx40: No Buses')
- else:
- lcd.message('Bx40: %s' %(str(bx40List[0])))
- sleep(30)
- except KeyboardInterrupt:
- flag = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement