frinkiac.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. """
  3. Frinkiac (Images)
  4. """
  5. from json import loads
  6. from urllib.parse import urlencode
  7. # about
  8. about = {
  9. "website": 'https://frinkiac.com',
  10. "wikidata_id": 'Q24882614',
  11. "official_api_documentation": {
  12. 'url': None,
  13. 'comment': 'see https://github.com/MitchellAW/CompuGlobal'
  14. },
  15. "use_official_api": False,
  16. "require_api_key": False,
  17. "results": 'JSON',
  18. }
  19. categories = ['images']
  20. BASE = 'https://frinkiac.com/'
  21. SEARCH_URL = '{base}api/search?{query}'
  22. RESULT_URL = '{base}?{query}'
  23. THUMB_URL = '{base}img/{episode}/{timestamp}/medium.jpg'
  24. IMAGE_URL = '{base}img/{episode}/{timestamp}.jpg'
  25. def request(query, params):
  26. params['url'] = SEARCH_URL.format(base=BASE, query=urlencode({'q': query}))
  27. return params
  28. def response(resp):
  29. results = []
  30. response_data = loads(resp.text)
  31. for result in response_data:
  32. episode = result['Episode']
  33. timestamp = result['Timestamp']
  34. results.append({'template': 'images.html',
  35. 'url': RESULT_URL.format(base=BASE,
  36. query=urlencode({'p': 'caption', 'e': episode, 't': timestamp})),
  37. 'title': episode,
  38. 'content': '',
  39. 'thumbnail_src': THUMB_URL.format(base=BASE, episode=episode, timestamp=timestamp),
  40. 'img_src': IMAGE_URL.format(base=BASE, episode=episode, timestamp=timestamp)})
  41. return results