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.net.network import Network
|
||||
from fmframework.net.network import Network, LastFMNetworkException
|
||||
|
||||
import sys
|
||||
import os
|
||||
@ -7,32 +7,28 @@ import logging
|
||||
|
||||
logger = logging.getLogger('fmframework')
|
||||
|
||||
log_format = '%(asctime)s %(levelname)s %(name)s - %(funcName)s - %(message)s'
|
||||
|
||||
file_handler = logging.FileHandler(".fm/backup.log")
|
||||
formatter = logging.Formatter(log_format)
|
||||
file_handler.setFormatter(formatter)
|
||||
|
||||
file_handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(name)s - %(funcName)s - %(message)s'))
|
||||
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.setFormatter(stream_formatter)
|
||||
|
||||
stream_handler.setFormatter(logging.Formatter('%(levelname)s %(name)s:%(funcName)s - %(message)s'))
|
||||
logger.addHandler(stream_handler)
|
||||
|
||||
|
||||
def backup_scrobbles(file_path):
|
||||
net = Network(username='sarsoo', api_key=os.environ['FMKEY'])
|
||||
|
||||
scrobbles = net.get_recent_tracks()
|
||||
|
||||
if not os.path.exists(file_path):
|
||||
os.makedirs(file_path)
|
||||
try:
|
||||
scrobbles = net.get_recent_tracks()
|
||||
|
||||
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__':
|
||||
|
@ -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)}')
|
||||
try:
|
||||
albums.append(net.get_album(name=scraped.name, artist=scraped.artist.name))
|
||||
except LastFMNetworkException as e:
|
||||
logger.error(f'error occured during album retrieval - {e}')
|
||||
except LastFMNetworkException:
|
||||
logger.exception(f'error occured during album retrieval')
|
||||
|
||||
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