summaryrefslogtreecommitdiff
path: root/searx/engines/mediawiki.py
diff options
context:
space:
mode:
authorasciimoo <asciimoo@gmail.com>2013-10-23 23:53:27 +0200
committerasciimoo <asciimoo@gmail.com>2013-10-23 23:53:27 +0200
commit75a2a6fb73219c2502e527187cab0547d685f7f3 (patch)
tree7974fcb13baab604a7069fafa934bc364bc5c1a4 /searx/engines/mediawiki.py
parentb15cd555469090a5a02953e2990a46e4941bc8f6 (diff)
downloadsearxng-75a2a6fb73219c2502e527187cab0547d685f7f3.tar.gz
searxng-75a2a6fb73219c2502e527187cab0547d685f7f3.zip
[enh] mediawiki engine added
Diffstat (limited to 'searx/engines/mediawiki.py')
-rw-r--r--searx/engines/mediawiki.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/searx/engines/mediawiki.py b/searx/engines/mediawiki.py
new file mode 100644
index 000000000..ff2d85d52
--- /dev/null
+++ b/searx/engines/mediawiki.py
@@ -0,0 +1,23 @@
+from json import loads
+from urllib import urlencode, quote
+
+url = 'https://en.wikipedia.org/'
+
+number_of_results = 10
+
+def request(query, params):
+ search_url = url + 'w/api.php?action=query&list=search&{query}&srprop=timestamp&format=json'
+ params['url'] = search_url.format(query=urlencode({'srsearch': query}))
+ return params
+
+
+def response(resp):
+ search_results = loads(resp.text)
+ results = []
+ res = search_results.get('query', {}).get('search', [])
+ if not len(res):
+ return results
+ for result in res[:int(number_of_results)]:
+ results.append({'url': url + 'wiki/' + quote(result['title'].replace(' ', '_').encode('utf-8')), 'title': result['title']})
+ return results
+