spotframework/alarm.py

48 lines
1.1 KiB
Python
Raw Normal View History

import spotframework.net.user as userclass
import spotframework.net.network as networkclass
import spotframework.log.log as log
import os
import datetime
2019-04-30 23:56:55 +01:00
def checkPhone():
response = os.system("ping -c 1 -w5 " + os.environ['PHONEIP'] + " > /dev/null 2>&1")
2019-05-14 13:05:25 +01:00
log.log('checking for phone')
2019-04-30 23:56:55 +01:00
if response == 0:
return True
else:
return False
if __name__ == '__main__':
2019-05-14 13:05:25 +01:00
try:
2019-04-30 23:56:55 +01:00
2019-05-14 13:05:25 +01:00
network = networkclass.network(userclass.User())
2019-04-30 23:56:55 +01:00
2019-05-14 13:05:25 +01:00
found = False
2019-05-14 13:05:25 +01:00
for i in range(0, 36):
if checkPhone():
found = True
break
2019-05-14 13:05:25 +01:00
if found:
2019-05-14 13:05:25 +01:00
date = datetime.datetime.now()
2019-05-14 13:05:25 +01:00
playlists = network.getUserPlaylists()
2019-05-14 13:05:25 +01:00
playlisturi = next((i.uri for i in playlists if i.name == date.strftime("%B %-y").lower()), os.environ['SPOTALARMURI'])
2019-05-14 13:05:25 +01:00
network.play(playlisturi, network.getDeviceID(os.environ['SPOTALARMDEVICENAME']))
network.setShuffle(True)
network.setVolume(os.environ['SPOTALARMVOLUME'])
network.next()
log.dumpLog()
except:
log.dumpLog()