Traduciendo country_codes

This commit is contained in:
Daniel Cortes
2020-06-03 21:29:35 -04:00
parent c654f447b1
commit 50b5694865
2 changed files with 20 additions and 19 deletions

View File

@@ -2,20 +2,21 @@ import fetcher.musicbrainz as mb
from utils import pretty_print_json from utils import pretty_print_json
def translate_artist(artist): def full_country_name(country_code):
type = artist.get('type', None) from country_list import countries_for_language
if type == 'Person': return dict(countries_for_language('es')).get(country_code, country_code)
artist['type'] = 'Persona'
elif type == 'Group':
artist['type'] = 'Grupo' def translate_artist_type(artist_type):
elif type == 'Orchestra': translation = {
artist['type'] = 'Orquesta' 'Person': 'Persona',
elif type == 'Choir': 'Group': 'Grupo',
artist['type'] = 'Coro' 'Orchestra': 'Orquesta',
elif type == 'Character': 'Choir': 'Coro',
artist['type'] = 'Personaje' 'Character': 'Personaje',
elif type == 'Other': 'Other': 'Otro',
artist['type'] = 'Otro' }
return translation.get(artist_type, artist_type)
def map_artist(mb_artist): def map_artist(mb_artist):
@@ -24,13 +25,11 @@ def map_artist(mb_artist):
'name': mb_artist.get('name'), 'name': mb_artist.get('name'),
'sort_name': mb_artist.get('sort_name'), 'sort_name': mb_artist.get('sort_name'),
'disambiguation': mb_artist.get('disambiguation'), 'disambiguation': mb_artist.get('disambiguation'),
'type': mb_artist.get('type'), 'type': translate_artist_type(mb_artist.get('type')),
'country': mb_artist.get('country'), 'country': full_country_name(mb_artist.get('country')),
'tags': sorted(mb_artist.get('tags', []), key=lambda tag: tag['count'], reverse=True), 'tags': sorted(mb_artist.get('tags', []), key=lambda tag: tag['count'], reverse=True),
} }
translate_artist(artist)
return artist return artist
@@ -193,6 +192,7 @@ def get_recording(mbid):
return map_recording(mb_recording) return map_recording(mb_recording)
def get_recordings_of_release(mbid, limit, page): def get_recordings_of_release(mbid, limit, page):
mb_recordings = mb.browse_recordings(params={'release': mbid}, includes=['artist-credits'], limit=limit, offset=limit * (page - 1)) mb_recordings = mb.browse_recordings(params={'release': mbid}, includes=['artist-credits'], limit=limit, offset=limit * (page - 1))
if 'error' in mb_recordings: if 'error' in mb_recordings:

View File

@@ -8,3 +8,4 @@ redis # To comunicate with redis
requests # Saner request library requests # Saner request library
blake3 # To use blake3 hashing, since python seeds every hash on hashlib and is different between instances blake3 # To use blake3 hashing, since python seeds every hash on hashlib and is different between instances
gunicorn # To run the server on production gunicorn # To run the server on production
country_list # To transform country codes to their names