Skip to content

Instantly share code, notes, and snippets.

@pierrebeaucamp
Last active December 14, 2015 22:27
Show Gist options
  • Save pierrebeaucamp/8839152 to your computer and use it in GitHub Desktop.
Save pierrebeaucamp/8839152 to your computer and use it in GitHub Desktop.
Soundcloud Alarm
import os
import requests
import time
from random import choice, randint
if __name__ == "__main__":
# Let's track the time
start_time = time.time()
# Turns on the Receiver (ooh, he likes it)
os.system("printf '%s\r\n' PO | nc 10.0.0.2 8102")
time.sleep(2)
os.system("printf '%s\r\n' 06FN | nc 10.0.0.2 8102")
# Nulls the Volume
for i in range(200):
os.system("printf '%s\r\b' VD | nc 10.0.0.2 8102")
# Turns it on a nice Volume to wake up
for i in range(50):
os.system("printf '%s\r\b' VU | nc 10.0.0.2 8102")
# Whos favorites are we listening to?
users = ['5727592', '8058060']
def playSoundcloud():
# Gets the JSON from Soundcloud
url = 'https://api.soundcloud.com/users/' + choice(users) + '/favorites.json?client_id=f8dc78d527a14157cce82626661b9607'
r = requests.get(url)
j = r.json()
# Plays a Sound
os.system('wget ' + j[randint(0, len(j))]['stream_url'] + '?client_id=f8dc78d527a14157cce82626661b9607' + ' -O - | mplayer -cache 8192 -')
while ((time.time() - start_time) < 1800):
playSoundcloud()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment