translated.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. """
  2. MyMemory Translated
  3. @website https://mymemory.translated.net/
  4. @provide-api yes (https://mymemory.translated.net/doc/spec.php)
  5. @using-api yes
  6. @results JSON
  7. @stable yes
  8. @parse url, title, content
  9. """
  10. engine_type = 'online_dictionnary'
  11. categories = ['general']
  12. url = 'https://api.mymemory.translated.net/get?q={query}&langpair={from_lang}|{to_lang}{key}'
  13. web_url = 'https://mymemory.translated.net/en/{from_lang}/{to_lang}/{query}'
  14. weight = 100
  15. https_support = True
  16. api_key = ''
  17. def request(query, params):
  18. if api_key:
  19. key_form = '&key=' + api_key
  20. else:
  21. key_form = ''
  22. params['url'] = url.format(from_lang=params['from_lang'][1],
  23. to_lang=params['to_lang'][1],
  24. query=params['query'],
  25. key=key_form)
  26. return params
  27. def response(resp):
  28. results = []
  29. results.append({
  30. 'url': web_url.format(
  31. from_lang=resp.search_params['from_lang'][2],
  32. to_lang=resp.search_params['to_lang'][2],
  33. query=resp.search_params['query']),
  34. 'title': '[{0}-{1}] {2}'.format(
  35. resp.search_params['from_lang'][1],
  36. resp.search_params['to_lang'][1],
  37. resp.search_params['query']),
  38. 'content': resp.json()['responseData']['translatedText']
  39. })
  40. return results