summaryrefslogtreecommitdiff
path: root/searx/engines/9gag.py
diff options
context:
space:
mode:
authorta <alt3753.7@gmail.com>2022-08-22 17:35:07 +0700
committerta <alt3753.7@gmail.com>2022-08-22 17:35:07 +0700
commitdd9127492f85dc5cfa25fbb5351735ea2190b058 (patch)
treec06a7c7ef14636e80d914649d7875d8d2b47801a /searx/engines/9gag.py
parentb84ee9ac606e44eb105fe40e527fc226db6a6d19 (diff)
downloadsearxng-dd9127492f85dc5cfa25fbb5351735ea2190b058.tar.gz
searxng-dd9127492f85dc5cfa25fbb5351735ea2190b058.zip
add 9gag engine
9GAG is a social media website where users upload and share user-generated images and videos
Diffstat (limited to 'searx/engines/9gag.py')
-rw-r--r--searx/engines/9gag.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/searx/engines/9gag.py b/searx/engines/9gag.py
new file mode 100644
index 000000000..b142adc0e
--- /dev/null
+++ b/searx/engines/9gag.py
@@ -0,0 +1,66 @@
+# SPDX-License-Identifier: AGPL-3.0-or-later
+# lint: pylint
+# pylint: disable=C0103
+"""9GAG (social media)"""
+
+from json import loads
+from datetime import datetime
+from urllib.parse import urlencode
+
+about = {
+ "website": 'https://9gag.com/',
+ "wikidata_id": 'Q277421',
+ "official_api_documentation": None,
+ "use_official_api": True,
+ "require_api_key": False,
+ "results": 'JSON',
+}
+
+categories = ['social media']
+paging = True
+
+search_url = "https://9gag.com/v1/search-posts?{query}"
+page_size = 10
+
+
+def request(query, params):
+ query = urlencode({'query': query, 'c': (params['pageno'] - 1) * page_size})
+
+ params['url'] = search_url.format(query=query)
+
+ return params
+
+
+def response(resp):
+ results = []
+
+ json_results = loads(resp.text)['data']['posts']
+
+ for result in json_results:
+ result_type = result['type']
+
+ if result_type == 'Photo':
+ results.append(
+ {
+ 'template': 'images.html',
+ 'url': result['url'],
+ 'title': result['title'],
+ 'content': result['description'],
+ 'publishedDate': datetime.utcfromtimestamp(result['creationTs']),
+ 'img_src': result['images']['image700']['url'],
+ 'thumbnail_src': result['images']['imageFbThumbnail']['url'],
+ }
+ )
+ elif result_type == 'Animated':
+ results.append(
+ {
+ 'template': 'videos.html',
+ 'url': result['url'],
+ 'title': result['title'],
+ 'content': result['description'],
+ 'publishedDate': datetime.utcfromtimestamp(result['creationTs']),
+ 'thumbnail': result['images']['imageFbThumbnail']['url'],
+ }
+ )
+
+ return results