Coverage for src/aggregator/stats_from_files.py: 100%
18 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-05-14 23:08 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-05-14 23:08 +0000
1"""Module for adding artists stats."""
2import datetime
3import json
5from src.aggregator.stats_utils import (
6 change_artist_data,
7 change_track_data,
8 get_artist_response_template,
9 get_artist_albums_ids,
10 get_ids_from_file_names
11)
14def stats_from_files_main(
15 timeout, request_count,
16 file_path, artist_count, albums_path,
17 headers, extensions
18):
19 """Main function for stats data aggregation."""
20 print(f'[T] Time: {datetime.datetime.now()}')
22 artist_ids = get_ids_from_file_names(file_path)
24 for artist_id in artist_ids[artist_count:]:
25 response, request_count = get_artist_response_template(
26 artist_id=artist_id,
27 timeout=timeout,
28 request_count=request_count,
29 headers=headers,
30 extensions=extensions
31 )
32 print(
33 f"Artist Stats {artist_id}"
34 f" - [*] [Request {request_count}"
35 f" - {response.status_code}] - Number {artist_count}"
36 )
38 change_artist_data(response, artist_id, file_path)
40 albums_ids = get_artist_albums_ids(artist_id, file_path)
42 artist_albums = get_ids_from_file_names(albums_path)
44 for album_id in albums_ids:
45 if album_id in artist_albums:
46 with open(
47 f'{albums_path}/album-{album_id}.json',
48 mode='r',
49 encoding='utf-8'
50 ) as album_file:
51 album_data = json.load(album_file)
53 change_track_data(album_data, artist_id, file_path)
54 artist_count += 1
57# if __name__ == '__main__':
58# stats_from_files_main(
59# timeout=1,
60# request_count=0,
61# file_path="src/aggregator/resources/artists",
62# artist_count=0,
63# albums_path="src/aggregator/resources/albums"
64# headers=client_headers,
65# extensions=get_artist_stats_extensions
66# )