Guest User

Untitled

a guest
Jun 14th, 2020
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. import RPi_I2C_driver
  2. from time import *
  3. import urllib.request
  4. import json
  5. import math
  6.  
  7. name = ("ChannelName")
  8. channel_id = "your-channel-id"
  9. key = "your-api-key"
  10. mylcd = RPi_I2C_driver.lcd()
  11. lcdLength = 16
  12.  
  13. data = urllib.request.urlopen("https://www.googleapis.com/youtube/v3/channels?part=statistics&id="+channel_id+"&key="+key).read()
  14. subs = json.loads(data)["items"][0]["statistics"]["subscriberCount"]
  15.  
  16.  
  17. lengthName = len(name)
  18. spaces =""
  19. numberofSpaces = math.floor((lcdLength -lengthName)/2)
  20. for x in range(numberofSpaces):
  21.   spaces = spaces + " "
  22.  
  23.  
  24. firstLine = spaces + name + spaces
  25. secondLine ="Subs: "+ "{:,d}".format(int(subs))
  26.  
  27. numberofBetweenSpaces =math.floor((lcdLength - len(secondLine))/2)
  28. betweenSpaces = ""
  29. for x in range(numberofBetweenSpaces):
  30.   betweenSpaces = betweenSpaces + " "
  31.  
  32. secondLine =betweenSpaces +  "Subs: " + "{:,d}".format(int(subs)) + betweenSpaces
  33.  
  34.  
  35. mylcd.lcd_display_string(firstLine,1)
  36. mylcd.lcd_display_string(secondLine,2)
  37.  
  38. print(name + " has " + "{:,d}".format(int(subs)) + " subscribers!")
Add Comment
Please, Sign In to add comment