def get_short_url(url, nickname, ui_locales) -> dict:
"""
Shortens the url via external service.
:param url: Url as string, which should be shortened
:param nickname: current users nickname
:param ui_locales: language of the discussion
:rtype: dict
:return: dictionary with the url, services name and the url of the service or an error
"""
user.update_last_action(nickname)
try:
service = Shorteners.TINYURL
service_url = 'http://tinyurl.com/'
shortener = Shortener(service)
short_url = format(shortener.short(url))
except (ReadTimeout, ConnectionError, NewConnectionError) as e:
logger('getter', 'get_short_url', repr(e), error=True)
_tn = Translator(ui_locales)
prepared_dict = {'error': _tn.get(_.serviceNotAvailable)}
return prepared_dict
prepared_dict = dict()
prepared_dict['url'] = short_url
prepared_dict['service'] = service
prepared_dict['service_url'] = service_url
prepared_dict['error'] = ''
return prepared_dict
评论列表
文章目录