frinkiac.py 1.4 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": {'url': None, 'comment': 'see https://github.com/MitchellAW/CompuGlobal'},
  12. "use_official_api": False,
  13. "require_api_key": False,
  14. "results": 'JSON',
  15. }
  16. categories = ['images']
  17. BASE = 'https://frinkiac.com/'
  18. SEARCH_URL = '{base}api/search?{query}'
  19. RESULT_URL = '{base}?{query}'
  20. THUMB_URL = '{base}img/{episode}/{timestamp}/medium.jpg'
  21. IMAGE_URL = '{base}img/{episode}/{timestamp}.jpg'
  22. def request(query, params):
  23. params['url'] = SEARCH_URL.format(base=BASE, query=urlencode({'q': query}))
  24. return params
  25. def response(resp):
  26. results = []
  27. response_data = loads(resp.text)
  28. for result in response_data:
  29. episode = result['Episode']
  30. timestamp = result['Timestamp']
  31. results.append(
  32. {
  33. 'template': 'images.html',
  34. 'url': RESULT_URL.format(base=BASE, query=urlencode({'p': 'caption', 'e': episode, 't': timestamp})),
  35. 'title': episode,
  36. 'content': '',
  37. 'thumbnail_src': THUMB_URL.format(base=BASE, episode=episode, timestamp=timestamp),
  38. 'img_src': IMAGE_URL.format(base=BASE, episode=episode, timestamp=timestamp),
  39. }
  40. )
  41. return results