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():
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:
return True
else:
return False
if __name__ == '__main__':
network = networkclass.network(userclass.User())
found = False
try:
for i in range(0, 36):
if checkPhone():
found = True
break
network = networkclass.network(userclass.User())
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)
network.setVolume(os.environ['SPOTALARMVOLUME'])
network.next()
playlisturi = next((i.uri for i in playlists if i.name == date.strftime("%B %-y").lower()), os.environ['SPOTALARMURI'])
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__':
network = networkclass.network(userclass.User())
playlists = network.getUserPlaylists()
try:
for playlist in playlists:
playlist.tracks = network.getPlaylistTracks(playlist.playlistid)
path = sys.argv[1]
datepath = str(datetime.datetime.now()).split(' ')[0].replace('-', '/')
network = networkclass.network(userclass.User())
playlists = network.getUserPlaylists()
totalpath = os.path.join(path, datepath)
pathdir = os.path.dirname(totalpath)
if not os.path.exists(totalpath):
os.makedirs(totalpath)
for playlist in playlists:
playlist.tracks = network.getPlaylistTracks(playlist.playlistid)
for play in playlists:
csvwrite.exportPlaylist(play, totalpath)
path = sys.argv[1]
log.dumpLog()
datepath = str(datetime.datetime.now()).split(' ')[0].replace('-', '/')
totalpath = os.path.join(path, datepath)
pathdir = os.path.dirname(totalpath)
if not os.path.exists(totalpath):
os.makedirs(totalpath)
for play in playlists:
csvwrite.exportPlaylist(play, totalpath)
log.dumpLog()
except:
log.dumpLog()