checked backup script, changed exception logging to exception method
This commit is contained in:
parent
6715c46721
commit
e13cb033dd
28
backup.py
28
backup.py
@ -1,5 +1,5 @@
|
|||||||
from fmframework.io.csv import export_scrobbles
|
from fmframework.io.csv import export_scrobbles
|
||||||
from fmframework.net.network import Network
|
from fmframework.net.network import Network, LastFMNetworkException
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
@ -7,32 +7,28 @@ import logging
|
|||||||
|
|
||||||
logger = logging.getLogger('fmframework')
|
logger = logging.getLogger('fmframework')
|
||||||
|
|
||||||
log_format = '%(asctime)s %(levelname)s %(name)s - %(funcName)s - %(message)s'
|
|
||||||
|
|
||||||
file_handler = logging.FileHandler(".fm/backup.log")
|
file_handler = logging.FileHandler(".fm/backup.log")
|
||||||
formatter = logging.Formatter(log_format)
|
file_handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(name)s - %(funcName)s - %(message)s'))
|
||||||
file_handler.setFormatter(formatter)
|
|
||||||
|
|
||||||
logger.addHandler(file_handler)
|
logger.addHandler(file_handler)
|
||||||
|
|
||||||
stream_log_format = '%(levelname)s %(name)s:%(funcName)s - %(message)s'
|
|
||||||
stream_formatter = logging.Formatter(stream_log_format)
|
|
||||||
|
|
||||||
stream_handler = logging.StreamHandler()
|
stream_handler = logging.StreamHandler()
|
||||||
stream_handler.setFormatter(stream_formatter)
|
stream_handler.setFormatter(logging.Formatter('%(levelname)s %(name)s:%(funcName)s - %(message)s'))
|
||||||
|
|
||||||
logger.addHandler(stream_handler)
|
logger.addHandler(stream_handler)
|
||||||
|
|
||||||
|
|
||||||
def backup_scrobbles(file_path):
|
def backup_scrobbles(file_path):
|
||||||
net = Network(username='sarsoo', api_key=os.environ['FMKEY'])
|
net = Network(username='sarsoo', api_key=os.environ['FMKEY'])
|
||||||
|
|
||||||
scrobbles = net.get_recent_tracks()
|
try:
|
||||||
|
scrobbles = net.get_recent_tracks()
|
||||||
if not os.path.exists(file_path):
|
|
||||||
os.makedirs(file_path)
|
|
||||||
|
|
||||||
export_scrobbles(scrobbles, file_path)
|
if not os.path.exists(file_path):
|
||||||
|
os.makedirs(file_path)
|
||||||
|
|
||||||
|
export_scrobbles(scrobbles, file_path)
|
||||||
|
|
||||||
|
except LastFMNetworkException:
|
||||||
|
logger.exception('error during scrobble retrieval')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -35,8 +35,8 @@ def get_populated_album_chart(net: Network, username: str, from_date: date, to_d
|
|||||||
logger.debug(f'populating {counter+1} of {len(chart)}')
|
logger.debug(f'populating {counter+1} of {len(chart)}')
|
||||||
try:
|
try:
|
||||||
albums.append(net.get_album(name=scraped.name, artist=scraped.artist.name))
|
albums.append(net.get_album(name=scraped.name, artist=scraped.artist.name))
|
||||||
except LastFMNetworkException as e:
|
except LastFMNetworkException:
|
||||||
logger.error(f'error occured during album retrieval - {e}')
|
logger.exception(f'error occured during album retrieval')
|
||||||
|
|
||||||
return albums
|
return albums
|
||||||
|
|
||||||
|
7
reqirements.txt
Normal file
7
reqirements.txt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
certifi==2020.6.20
|
||||||
|
chardet==3.0.4
|
||||||
|
idna==2.10
|
||||||
|
numpy==1.19.0
|
||||||
|
opencv-python==4.2.0.34
|
||||||
|
requests==2.24.0
|
||||||
|
urllib3==1.25.9
|
Loading…
Reference in New Issue
Block a user