2019-04-30 23:02:29 +01:00
|
|
|
import spotframework.net.user as userclass
|
|
|
|
import spotframework.net.network as networkclass
|
2019-05-14 12:39:17 +01:00
|
|
|
import spotframework.log.log as log
|
2019-04-30 23:02:29 +01:00
|
|
|
|
2019-05-14 12:39:17 +01:00
|
|
|
import os
|
|
|
|
import datetime
|
2019-04-30 23:02:29 +01:00
|
|
|
|
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
|
|
|
|
|
2019-04-30 23:02:29 +01:00
|
|
|
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-08 22:41:47 +01:00
|
|
|
|
2019-05-14 13:05:25 +01:00
|
|
|
for i in range(0, 36):
|
|
|
|
if checkPhone():
|
|
|
|
found = True
|
|
|
|
break
|
2019-05-08 22:41:47 +01:00
|
|
|
|
2019-05-14 13:05:25 +01:00
|
|
|
if found:
|
2019-05-08 22:41:47 +01:00
|
|
|
|
2019-05-14 13:05:25 +01:00
|
|
|
date = datetime.datetime.now()
|
2019-05-08 22:41:47 +01:00
|
|
|
|
2019-05-14 13:05:25 +01:00
|
|
|
playlists = network.getUserPlaylists()
|
2019-04-30 23:16:54 +01:00
|
|
|
|
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 12:39:17 +01:00
|
|
|
|
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()
|