added dumping logs on error

This commit is contained in:
aj 2019-05-14 13:05:25 +01:00
parent 2046dda356
commit fa7748b0ae
2 changed files with 42 additions and 31 deletions

View File

@ -8,34 +8,40 @@ import datetime
def checkPhone(): def checkPhone():
response = os.system("ping -c 1 -w5 " + os.environ['PHONEIP'] + " > /dev/null 2>&1") response = os.system("ping -c 1 -w5 " + os.environ['PHONEIP'] + " > /dev/null 2>&1")
print('checking for phone') log.log('checking for phone')
if response == 0: if response == 0:
return True return True
else: else:
return False return False
if __name__ == '__main__': if __name__ == '__main__':
network = networkclass.network(userclass.User())
found = False try:
for i in range(0, 36): network = networkclass.network(userclass.User())
if checkPhone():
found = True
break
if found: found = False
date = datetime.datetime.now() for i in range(0, 36):
if checkPhone():
found = True
break
playlists = network.getUserPlaylists() if found:
playlisturi = next((i.uri for i in playlists if i.name == date.strftime("%B %-y").lower()), os.environ['SPOTALARMURI']) date = datetime.datetime.now()
network.play(playlisturi, network.getDeviceID(os.environ['SPOTALARMDEVICENAME'])) playlists = network.getUserPlaylists()
network.setShuffle(True) playlisturi = next((i.uri for i in playlists if i.name == date.strftime("%B %-y").lower()), os.environ['SPOTALARMURI'])
network.setVolume(os.environ['SPOTALARMVOLUME'])
network.next()
log.dumpLog() network.play(playlisturi, network.getDeviceID(os.environ['SPOTALARMDEVICENAME']))
network.setShuffle(True)
network.setVolume(os.environ['SPOTALARMVOLUME'])
network.next()
log.dumpLog()
except:
log.dumpLog()

View File

@ -9,22 +9,27 @@ import os
if __name__ == '__main__': if __name__ == '__main__':
network = networkclass.network(userclass.User()) try:
playlists = network.getUserPlaylists()
for playlist in playlists: network = networkclass.network(userclass.User())
playlist.tracks = network.getPlaylistTracks(playlist.playlistid) playlists = network.getUserPlaylists()
path = sys.argv[1] for playlist in playlists:
playlist.tracks = network.getPlaylistTracks(playlist.playlistid)
datepath = str(datetime.datetime.now()).split(' ')[0].replace('-', '/') path = sys.argv[1]
totalpath = os.path.join(path, datepath) datepath = str(datetime.datetime.now()).split(' ')[0].replace('-', '/')
pathdir = os.path.dirname(totalpath)
if not os.path.exists(totalpath):
os.makedirs(totalpath)
for play in playlists: totalpath = os.path.join(path, datepath)
csvwrite.exportPlaylist(play, totalpath) pathdir = os.path.dirname(totalpath)
if not os.path.exists(totalpath):
os.makedirs(totalpath)
log.dumpLog() for play in playlists:
csvwrite.exportPlaylist(play, totalpath)
log.dumpLog()
except:
log.dumpLog()