Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- """
- Raspberry Pi Youtube Counter for CheapAssReviews Channel
- Cheapassreviews.com
- Helped me:
- http://stackoverflow.com/questions/36252027/how-to-use-youtube-api-v3-for-realtime-subscribers
- https://max7219.readthedocs.io/en/latest/
- http://raspi.tv/2013/8-x-8-led-array-driven-by-max7219-on-the-raspberry-pi-via-python
- http://www.raspberrypi-spy.co.uk/2012/06/simple-guide-to-the-rpi-gpio-header-and-pins/
- http://raspberrypi.stackexchange.com/questions/8734/execute-script-on-start-up
- """
- import RPi.GPIO as GPIO
- import math
- import os
- import sys
- import httplib2
- import json
- import urllib
- import time
- import random
- import socket
- from select import select
- import max7219.led as led
- #channel id and API key
- channel_id = "ENTER YOUR CHANNEL ID HERE" # channel id
- #channel_id = "UCtinbF-Q-fVthA0qrFQTgXQ" # casey
- api_key = "ENTER YOUR API KEY HERE"
- lookup_url = "https://www.googleapis.com/youtube/v3/channels?part=statistics&id=" + channel_id + "&key=" + api_key
- #Change brightness here
- brightness_setting = 1 # I hate bright lights
- def is_connected():
- try:
- host = socket.gethostbyname("www.google.com")
- s = socket.create_connection((host, 80), 2)
- return True
- except:
- pass
- return False
- def main():
- # create seven segment device
- device = led.sevensegment(cascaded=1)
- device.brightness(brightness_setting)
- device.clear()
- while 1:
- try:
- # Catches the webpage from google
- soup = urllib.urlopen(lookup_url)
- markup = soup.read()
- # Access the part of the JSON object that we care about
- feed_json = json.loads(markup)
- sub_count = feed_json["items"][0]["statistics"]["subscriberCount"]
- # Tells us how great we are (writes to display
- device.write_text(0, sub_count)
- except:
- # If can't get new number, screen goes blank
- device.clear()
- time.sleep(1)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement