mirror of
https://github.com/searxng/searxng
synced 2024-01-01 18:24:07 +00:00
Merge pull request #504 from kvch/frinkiac-engine
Simpson screenshot search engine
This commit is contained in:
commit
4a0ccabefa
44
searx/engines/frinkiac.py
Normal file
44
searx/engines/frinkiac.py
Normal file
@ -0,0 +1,44 @@
|
||||
"""
|
||||
Frinkiac (Images)
|
||||
|
||||
@website https://www.frinkiac.com
|
||||
@provide-api no
|
||||
@using-api no
|
||||
@results JSON
|
||||
@stable no
|
||||
@parse url, title, img_src
|
||||
"""
|
||||
|
||||
from json import loads
|
||||
from urllib import urlencode
|
||||
|
||||
categories = ['images']
|
||||
|
||||
BASE = 'https://frinkiac.com/'
|
||||
SEARCH_URL = '{base}api/search?{query}'
|
||||
RESULT_URL = '{base}?{query}'
|
||||
THUMB_URL = '{base}img/{episode}/{timestamp}/medium.jpg'
|
||||
IMAGE_URL = '{base}img/{episode}/{timestamp}.jpg'
|
||||
|
||||
|
||||
def request(query, params):
|
||||
params['url'] = SEARCH_URL.format(base=BASE, query=urlencode({'q': query}))
|
||||
return params
|
||||
|
||||
|
||||
def response(resp):
|
||||
results = []
|
||||
response_data = loads(resp.text)
|
||||
for result in response_data:
|
||||
episode = result['Episode']
|
||||
timestamp = result['Timestamp']
|
||||
|
||||
results.append({'template': 'images.html',
|
||||
'url': RESULT_URL.format(base=BASE,
|
||||
query=urlencode({'p': 'caption', 'e': episode, 't': timestamp})),
|
||||
'title': episode,
|
||||
'content': '',
|
||||
'thumbnail_src': THUMB_URL.format(base=BASE, episode=episode, timestamp=timestamp),
|
||||
'img_src': IMAGE_URL.format(base=BASE, episode=episode, timestamp=timestamp)})
|
||||
|
||||
return results
|
@ -110,6 +110,11 @@ engines:
|
||||
# Or you can use the html non-stable engine, activated by default
|
||||
engine : flickr_noapi
|
||||
|
||||
- name : frinkiac
|
||||
engine : frinkiac
|
||||
shortcut : frk
|
||||
disabled : True
|
||||
|
||||
- name : gigablast
|
||||
engine : gigablast
|
||||
shortcut : gb
|
||||
|
49
tests/unit/engines/test_frinkiac.py
Normal file
49
tests/unit/engines/test_frinkiac.py
Normal file
@ -0,0 +1,49 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from collections import defaultdict
|
||||
import mock
|
||||
from json import dumps
|
||||
from searx.engines import frinkiac
|
||||
from searx.testing import SearxTestCase
|
||||
|
||||
|
||||
class TestFrinkiacEngine(SearxTestCase):
|
||||
|
||||
def test_request(self):
|
||||
query = 'test_query'
|
||||
request_dict = defaultdict(dict)
|
||||
params = frinkiac.request(query, request_dict)
|
||||
self.assertTrue('url' in params)
|
||||
|
||||
def test_response(self):
|
||||
self.assertRaises(AttributeError, frinkiac.response, None)
|
||||
self.assertRaises(AttributeError, frinkiac.response, [])
|
||||
self.assertRaises(AttributeError, frinkiac.response, '')
|
||||
self.assertRaises(AttributeError, frinkiac.response, '[]')
|
||||
|
||||
text = """
|
||||
[{"Id":770931,
|
||||
"Episode":"S06E18",
|
||||
"Timestamp":534616,
|
||||
"Filename":""},
|
||||
{"Id":1657080,
|
||||
"Episode":"S12E14",
|
||||
"Timestamp":910868,
|
||||
"Filename":""},
|
||||
{"Id":1943753,
|
||||
"Episode":"S14E21",
|
||||
"Timestamp":773439,
|
||||
"Filename":""},
|
||||
{"Id":107835,
|
||||
"Episode":"S02E03",
|
||||
"Timestamp":531709,
|
||||
"Filename":""}]
|
||||
"""
|
||||
|
||||
response = mock.Mock(text=text)
|
||||
results = frinkiac.response(response)
|
||||
self.assertEqual(type(results), list)
|
||||
self.assertEqual(len(results), 4)
|
||||
self.assertEqual(results[0]['title'], u'S06E18')
|
||||
self.assertEqual(results[0]['url'], 'https://frinkiac.com/?p=caption&e=S06E18&t=534616')
|
||||
self.assertEqual(results[0]['thumbnail_src'], 'https://frinkiac.com/img/S06E18/534616/medium.jpg')
|
||||
self.assertEqual(results[0]['img_src'], 'https://frinkiac.com/img/S06E18/534616.jpg')
|
Loading…
Reference in New Issue
Block a user