(back) Suggester V3: Process album in a separate way

(cherry picked from commit ebbeeccfb8535dbb67240d2c68c7dc9a4da7e7f8)
This commit is contained in:
2021-08-01 03:42:46 +02:00
parent 8121f3d751
commit 520d0be595
2 changed files with 43 additions and 24 deletions

View File

@@ -26,7 +26,7 @@ def get_tokens(data: str) -> list:
raise NoGoodDataException('Data is not correct to get tokens')
return [t['token'] for t in r.json()['tokens']]
def post_document(artist: str, artist_sugget: list, album: str, album_suggest: list) -> bool:
def post_document(artist: str = None, artist_sugget: list = None, album: str = None, album_suggest: list = None) -> bool:
element = {
"artist_suggest" : artist_sugget,
"artist": artist,
@@ -48,19 +48,36 @@ def post_document(artist: str, artist_sugget: list, album: str, album_suggest: l
# print('Post_element - Element created: ' + el_id)
return el_id
if __name__ == '__main__':
# Using readlines()
with open('/home/budd/workspace/iTunes/es-artists.json', 'r') as artist_file:
artists_lines = artist_file.readlines()
# Using readlines()
itunes_file = open('/home/budd/workspace/iTunes/es-artists.json', 'r')
lines = itunes_file.readlines()
with open('/home/budd/workspace/iTunes/es-albums.json', 'r') as artist_file:
albums_lines = artist_file.readlines()
# Strips the newline character
for line in lines:
data = json.loads(line)
if "Artist" in data:
try :
artist_input = get_tokens(data['Artist'])
album_input = get_tokens(data['Album'])
post_document(data['Artist'], artist_input, data['Album'], album_input)
except NoGoodDataException:
print('ERROR WITH DATA')
print(str(data))
# Strips the newline character
count = 0
for line in artists_lines:
data = json.loads(line)
if "Artist" in data:
try :
artist_input = get_tokens(data['Artist'])
post_document(artist=data['Artist'], artist_sugget=artist_input)
count += 1
except NoGoodDataException:
print('ERROR WITH DATA')
print(str(data))
for line in albums_lines:
data = json.loads(line)
if "Artist" in data:
try :
album_input = get_tokens(data['Album'])
post_document(album=data['Album'], album_suggest=album_input)
count += 1
except NoGoodDataException:
print('ERROR WITH DATA')
print(str(data))
print('Created documents: ' + str(count))