Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import RPi_I2C_driver
- from time import *
- import urllib.request
- import json
- import math
- name = ("ChannelName")
- channel_id = "your-channel-id"
- key = "your-api-key"
- mylcd = RPi_I2C_driver.lcd()
- lcdLength = 16
- data = urllib.request.urlopen("https://www.googleapis.com/youtube/v3/channels?part=statistics&id="+channel_id+"&key="+key).read()
- subs = json.loads(data)["items"][0]["statistics"]["subscriberCount"]
- lengthName = len(name)
- spaces =""
- numberofSpaces = math.floor((lcdLength -lengthName)/2)
- for x in range(numberofSpaces):
- spaces = spaces + " "
- firstLine = spaces + name + spaces
- secondLine ="Subs: "+ "{:,d}".format(int(subs))
- numberofBetweenSpaces =math.floor((lcdLength - len(secondLine))/2)
- betweenSpaces = ""
- for x in range(numberofBetweenSpaces):
- betweenSpaces = betweenSpaces + " "
- secondLine =betweenSpaces + "Subs: " + "{:,d}".format(int(subs)) + betweenSpaces
- mylcd.lcd_display_string(firstLine,1)
- mylcd.lcd_display_string(secondLine,2)
- print(name + " has " + "{:,d}".format(int(subs)) + " subscribers!")
Add Comment
Please, Sign In to add comment