Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. import requests
  2. from bs4 import BeautifulSoup as bs
  3. from time import sleep
  4. from Adafruit_CharLCD import Adafruit_CharLCD
  5.  
  6. ##try:
  7. ## res = requests.get('https://bustime.mta.info/m/index;jsessionid=4EA63E7418A423600513FEA992FBEFF4?q=103925')
  8. ##except Exception as exc:
  9. ## print('Error: %s' %(exc))
  10. ##splitFile = res.text.split('BxM9')
  11. ##bx40 = bs(splitFile[0],"html.parser")
  12. ##bxm9 = bs(splitFile[2],"html.parser")
  13. ##bx40List = bx40.select('body div div div li strong ')
  14. ##bxm9List = bxm9.select('ol li strong')
  15. ##
  16. ##bx40List = [tag.getText() for tag in bx40List]
  17. ##bxm9List = [tag.getText() for tag in bxm9List]
  18. ##
  19. ##bx40List = [tag.replace('away','') for tag in bx40List]
  20. ##bxm9List = [tag.replace('away','') for tag in bxm9List]
  21. ##
  22. ##print(bx40List)
  23. ##print(bxm9List)
  24. ##
  25. ##
  26. ##
  27. # instantiate lcd and specify pins
  28. lcd = Adafruit_CharLCD(rs=26, en=19,
  29. d4=13, d5=6, d6=5, d7=11,
  30. cols=16, lines=2)
  31. lcd.clear()
  32. # display text on LCD display \n = new line
  33. flag = True
  34.  
  35. while flag:
  36. try:
  37. res = requests.get('https://bustime.mta.info/m/index;jsessionid=4EA63E7418A423600513FEA992FBEFF4?q=103925')
  38. except Exception as exc:
  39. print('Error: %s' %(exc))
  40. splitFile = res.text.split('BxM9')
  41. bx40 = bs(splitFile[0],"html.parser")
  42. bxm9 = bs(splitFile[2],"html.parser")
  43. bx40List = bx40.select('body div div div li strong ')
  44. bxm9List = bxm9.select('ol li strong')
  45.  
  46. bx40List = [tag.getText() for tag in bx40List]
  47. bxm9List = [tag.getText() for tag in bxm9List]
  48.  
  49. bx40List = [tag.replace('away','') for tag in bx40List]
  50. bxm9List = [tag.replace('away','') for tag in bxm9List]
  51. lcd.clear()
  52. try:
  53. if len(bx40List) == 0:
  54. lcd.message('Bx40: No Buses')
  55. else:
  56. lcd.message('Bx40: %s' %(str(bx40List[0])))
  57. sleep(30)
  58. except KeyboardInterrupt:
  59. flag = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement