Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sanitizing markdown and getting social media names #63

Merged
merged 10 commits into from
Apr 2, 2020
16 changes: 14 additions & 2 deletions blottertrax/description_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def get_reply(self, parsed_submission: ParsedSubmission) -> str:

life_span = '' if has_life_span is False else '({} to {})'.format(life_span_begin, life_span_end)
tags = ', '.join(map(lambda t: t['name'], artist['tag-list'][:5])) if has_tags else 'none'
socials = ', '.join(map(lambda u: '[{}]({})'.format(u['type'], u['target']),
artist['url-relation-list'])) if has_socials else 'none'
socials = ', '.join(map(self.format_network_to_friendly_name, artist['url-relation-list'])) if has_socials else 'none'


return templates.musicbrainz_artist_info.strip().format(
artist['name'],
Expand All @@ -58,3 +58,15 @@ def _get_artist_by_id(self, artist_id: str):
return self.musicbrainz.get_artist_by_id(
id=artist_id, includes=['tags', 'ratings', 'annotation', 'url-rels', 'user-tags']
)['artist']

@classmethod
def format_network_to_friendly_name(cls, info) -> str:
martijnboers marked this conversation as resolved.
Show resolved Hide resolved
social_network = ['twitter.com', 'facebook.com', 'instagram.com']
target = info['target']
link_type = info['type']
if link_type == 'social network':
for domain in social_network:
if domain in target:
link_type = domain.split('.')[0]
break
return '[{}]({})'.format(link_type, '\)'.join(target.split(')')))