Skip to content

Commit

Permalink
Merge pull request #28 from TheTedLab/dev
Browse files Browse the repository at this point in the history
Dev edition merge [Profiling]
  • Loading branch information
TheTedLab authored May 14, 2024
2 parents 0317124 + 78fae98 commit 212e2b6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
41 changes: 40 additions & 1 deletion src/aggregator/app.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
"""Module application to collect data from Spotify."""
from loguru import logger
from loguru_config import LoguruConfig
from scalene import scalene_profiler

from src.aggregator.aggregator import aggregate
from src.aggregator.artist_aggregate import artist_aggregate_main
from src.aggregator.auth_credentials import access_token, token_type
from src.aggregator.auth_credentials import (
access_token, token_type, client_headers,
get_artist_stats_extensions, get_tracks_extensions
)
from src.aggregator.stats_from_files import stats_from_files_main
from src.aggregator.stats_update import stats_update_main
from src.aggregator.tracks_count import tracks_count

LoguruConfig.load("loguru-config.yaml")


def main():
"""Main function for application entrypoint."""
scalene_profiler.start()
logger.info("Starting general aggregator")
low, high = 1, 2
logger.debug(f"Low: {low}, High: {high}")
Expand All @@ -25,6 +33,37 @@ def main():
)
logger.info("Artist aggregator finished")

logger.info("Starting stats from files aggregator")
stats_from_files_main(
timeout=1,
request_count=0,
file_path="src/aggregator/resources/artists",
artist_count=0,
albums_path="src/aggregator/resources/albums",
headers=client_headers,
extensions=get_artist_stats_extensions
)
logger.info("Stats from files aggregator finished")

logger.info("Starting stats update aggregator")
stats_update_main(
artist_ids=[
'0M2HHtY3OOQzIZxrHkbJLT', '4tZwfgrHOc3mvqYlEYSvVi', '00FQb4jTyendYWaN8pK0wa'
],
timeout=1,
request_count=0,
file_path='src/aggregator/resources/artists',
headers=client_headers,
tracks_extensions=get_tracks_extensions,
artist_extensions=get_artist_stats_extensions
)
logger.info("Stats update aggregator finished")

logger.info("Starting tracks count")
tracks_count()
logger.info("Tracks count finished")
scalene_profiler.stop()


if __name__ == '__main__':
main()
3 changes: 2 additions & 1 deletion src/aggregator/stats_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ def change_artist_data(response, artist_id, file_path):
def change_track_data(response, artist_id, file_path):
"""Util function for track stats data aggregation or updating."""
tracks_data = response.get('data').get('albumUnion').get('tracks').get('items')
path = f'{file_path}/artist-{artist_id}.json'

for track in tracks_data:
track_data = track.get('track')
track_id = track_data.get('uri').split(':')[2]
track_playcount = track_data.get('playcount')

with open(
f'{file_path}/artist-{artist_id}.json',
file=path,
mode='r+',
encoding='utf-8'
) as artist_file:
Expand Down

0 comments on commit 212e2b6

Please sign in to comment.