Skip to content

Instantly share code, notes, and snippets.

@ArthurGuy
Last active August 10, 2017 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArthurGuy/72d3620aac0fad341249d393034f72a0 to your computer and use it in GitHub Desktop.
Save ArthurGuy/72d3620aac0fad341249d393034f72a0 to your computer and use it in GitHub Desktop.
YouTube sign counter
[program:display]
command=python /home/pi/youtube.py
autostart=true
autorestart=true
stderr_logfile=/var/log/youtube.err.log
stdout_logfile=/var/log/youtube.out.log
user=root
#!/usr/bin/env python
# You need to make sure you have the ZeroSeg library and that is available as an import
import sys
import time
import json
import requests
import socket
import urllib
import string
from decimal import Decimal
import ZeroSeg.led as led
device = led.sevensegment(cascaded=2)
device.brightness(15)
# Display something while we load up
device.write_text(1,"---")
def get_data():
# channel if and the auth key need to be replaced with your own
url = "https://www.googleapis.com/youtube/v3/channels?part=statistics&id=[channel-id]&key=[auth-key]"
res = requests.get(url)
if(res.status_code==200):
json_data = json.loads(res.text)
return json_data
return {}
# Start with high values so everything will run as soon as its started up
loop_count = 590
display_count = 40
display = 0
while True:
try:
time.sleep(0.1)
loop_count += 1
display_count += 1
if loop_count == 600:
loop_count = 0
data = get_data()
subscribers = Decimal(int(data["items"][0]["statistics"]["subscriberCount"]))
views = int(data["items"][0]["statistics"]["viewCount"])
print(subscribers)
print(views)
if display_count == 50:
display_count = 0
if display == 0:
display = 1
device.write_number(1, views, leftJustify=True)
views_s = map(int, str(views))
# This replaces a couple of numbers with a version that has a decimal point set
# The decimal point acts as the thousands seperator, a little odd but it makes it a lot more readable
device.letter(1, 8, views_s[0], 1)
device.letter(1, 5, views_s[3], 1)
elif display == 1:
display = 0
device.write_number(1, subscribers, leftJustify=True)
device.letter(1, 8, int (subscribers / 1000), 1)
except KeyboardInterrupt:
device.clear()
sys.exit(-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment