Coverage for src/aggregator/save_artist.py: 0%

19 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-05-14 23:08 +0000

1"""Module for saving an artist in the database.""" 

2import json 

3import time 

4 

5import requests 

6 

7from server_vars import SERVER_ADDRESS, SERVER_PORT 

8 

9ids = ['00FQb4jTyendYWaN8pK0wa', '0M2HHtY3OOQzIZxrHkbJLT'] 

10 

11for artist_id in ids: 

12 with open(f'resources/artists/artist-{artist_id}.json', 'r', encoding='utf-8') as file: 

13 data = json.load(file) 

14 

15 header = { 

16 'Content-Type': 'application/json' 

17 } 

18 

19 json_string = json.dumps( 

20 data 

21 ) 

22 response = requests.post( 

23 f'http://{SERVER_ADDRESS}:{SERVER_PORT}/saveArtist', 

24 headers=header, 

25 data=json_string, 

26 timeout=10 

27 ) 

28 print(f"{response.text} - Status Code: {response.status_code}") 

29 time.sleep(1) 

30 

31 if response.status_code != 200: 

32 print(f"Status Code: {response.status_code}, Retrying...") 

33 time.sleep(5) 

34 response = requests.post( 

35 f'http://{SERVER_ADDRESS}:{SERVER_PORT}/saveArtist', 

36 headers=header, 

37 data=json_string, 

38 timeout=10 

39 ) 

40 print(f"{response.text} - Status Code: {response.status_code}") 

41 time.sleep(1)