forked from LucasBerbesson/notification-box
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify.py
91 lines (73 loc) · 2.97 KB
/
notify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import requests
from time import sleep
from xml.etree import ElementTree
import subprocess
from gpiozero import RGBLED
##################
INSTAGRAM_USER_ID = "XXXXXXXXXXXXXXXXXXXXXX"
INSTAGRAM_ACCESS_TOKEN = "XXXXXXXXXXXXXXXXXXXXXX"
YOUTUBE_CHANNEL_ID = "XXXXXXXXXXXXXXXXXXXXXX"
GOOGLE_API_KEY = "XXXXXXXXXXXXXXXXXXXXXX"
FACEBOOK_PAGE_URL = "XXXXXXXXXXXXXXXXXXXXXX"
# Time in seconds between two requests
REFRESH_TIME = 1
# Make a special sound every 100 followers
APPLAUSE_THRESHOLD = 100
# Raspberry GPIO where the RED pin of your LED strip is connected
RED_PIN = 9
# Raspberry GPIO where the GREEN pin of your LED strip is connected
GREEN_PIN = 10
# Raspberry GPIO where the BLUE pin of your LED strip is connected
BLUE_PIN = 11
##################
fk_url = "http://api.facebook.com/restserver.php?method=links.getStats&urls=" + FACEBOOK_PAGE_URL
yt_url = "https://www.googleapis.com/youtube/v3/channels?part=statistics&id=" + YOUTUBE_CHANNEL_ID + "&fields=items/statistics/subscriberCount&key=" + GOOGLE_API_KEY
insta_url = "https://api.instagram.com/v1/users/" + INSTAGRAM_USER_ID + "/?access_token=" + INSTAGRAM_ACCESS_TOKEN
likes = new_likes = subscribers = new_subscribers = followers = new_followers = 0
led = RGBLED(red=RED_PIN, green=GREEN_PIN, blue=BLUE_PIN)
green = red = blue = 0
while True:
fk_response = requests.get(fk_url)
yt_response = requests.get(yt_url)
insta_response = requests.get(insta_url)
if fk_response.status_code == 200:
tree = ElementTree.fromstring(fk_response.content)
new_likes = int(tree[0][5].text)
if yt_response.status_code == 200:
new_subscribers = int(yt_response.json()['items'][0]['statistics']['subscriberCount'])
if insta_response.status_code == 200:
new_followers = int(insta_response.json()['data']['counts']['followed_by'])
if new_likes - likes > 0:
blue = 1
if new_likes % APPLAUSE_THRESHOLD == 0:
subprocess.call(["sudo", "omxplayer", "applause.wav"])
else:
subprocess.call(["sudo", "omxplayer", "blop.wav"])
sleep(0.1)
if new_subscribers - subscribers > 0:
red = 1
if new_subscribers % APPLAUSE_THRESHOLD == 0:
subprocess.call(["sudo", "omxplayer", "applause.wav"])
else:
subprocess.call(["sudo", "omxplayer", "blop.wav"])
sleep(0.1)
if new_followers - followers > 0:
green = 1
if new_followers % APPLAUSE_THRESHOLD == 0:
subprocess.call(["sudo", "omxplayer", "applause.wav"])
else:
subprocess.call(["sudo", "omxplayer", "blop.wav"])
sleep(0.1)
led.color = (red, green, blue)
sleep(1)
red = green = blue = 0
led.color = (red, green, blue)
likes = new_likes
followers = new_followers
subscribers = new_subscribers
sleep(REFRESH_TIME)
# import pygame.mixer
# from pygame.mixer import Sound
# pygame.mixer.init(48000, -16, 1, 1024)
# elec_ping = pygame.mixer.Sound("samples/elec_ping.wav")
# elec_ping.play()