mirror of
https://github.com/agresdominik/predictify.git
synced 2026-04-21 17:55:49 +00:00
Refactored to own logger
This commit is contained in:
+7
-4
@@ -1,15 +1,16 @@
|
|||||||
import json
|
import json
|
||||||
import logging as log
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from auth import simple_authenticate
|
from auth import simple_authenticate
|
||||||
from database_handler import Database, Table
|
from database_handler import Database, Table
|
||||||
|
from logger import LoggerWrapper
|
||||||
from spotify_api import get_multiple_field_information
|
from spotify_api import get_multiple_field_information
|
||||||
|
|
||||||
# Define the absolute folder path to the folder containing the gdrp retrieved data
|
# Define the absolute folder path to the folder containing the gdrp retrieved data
|
||||||
folder_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'data', 'gdpr_data')
|
folder_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'data', 'gdpr_data')
|
||||||
# Define the db
|
# Define the db
|
||||||
db = Database()
|
db = Database()
|
||||||
|
log = LoggerWrapper()
|
||||||
|
|
||||||
|
|
||||||
def _read_gdrp_data() -> list:
|
def _read_gdrp_data() -> list:
|
||||||
@@ -20,7 +21,7 @@ def _read_gdrp_data() -> list:
|
|||||||
:return: all_songs_played: A dict with an items field containing all songs played for the user
|
:return: all_songs_played: A dict with an items field containing all songs played for the user
|
||||||
"""
|
"""
|
||||||
all_songs_played = []
|
all_songs_played = []
|
||||||
|
try:
|
||||||
for filename in os.listdir(folder_path):
|
for filename in os.listdir(folder_path):
|
||||||
|
|
||||||
if filename.endswith('.json'):
|
if filename.endswith('.json'):
|
||||||
@@ -45,7 +46,9 @@ def _read_gdrp_data() -> list:
|
|||||||
}
|
}
|
||||||
all_songs_played.append(track)
|
all_songs_played.append(track)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f'Missing field: {e}')
|
log.warning(f'Missing field from gdpr data: {e}')
|
||||||
|
except Exception as e:
|
||||||
|
log.error(f'Failed to read gdpr data: {e}')
|
||||||
|
|
||||||
all_songs_played = sorted(all_songs_played, key=lambda x: x['timestamp'])
|
all_songs_played = sorted(all_songs_played, key=lambda x: x['timestamp'])
|
||||||
return all_songs_played
|
return all_songs_played
|
||||||
@@ -139,7 +142,7 @@ def _insert_data_into_db(all_songs_played: list):
|
|||||||
log.error(f'Failed adding {entry} to database, error {e}')
|
log.error(f'Failed adding {entry} to database, error {e}')
|
||||||
|
|
||||||
|
|
||||||
def export_gdpr_data(n_limit: int = 100):
|
def export_gdpr_data(n_limit: int = 100) -> None:
|
||||||
all_songs_played = _read_gdrp_data()
|
all_songs_played = _read_gdrp_data()
|
||||||
all_songs_played = all_songs_played[-n_limit:]
|
all_songs_played = all_songs_played[-n_limit:]
|
||||||
all_songs_catalogued = _populate_ids(all_songs_played)
|
all_songs_catalogued = _populate_ids(all_songs_played)
|
||||||
|
|||||||
Reference in New Issue
Block a user