2020-02-21 12:05:41 +01:00
|
|
|
import json
|
|
|
|
try:
|
2020-02-26 11:59:14 +01:00
|
|
|
from google import google
|
2020-02-21 12:05:41 +01:00
|
|
|
except ImportError:
|
2020-02-26 11:59:14 +01:00
|
|
|
print("GoogleAPI not installed. Command : pip install git+https://github.com/abenassi/Google-Search-API")
|
2020-02-21 12:05:41 +01:00
|
|
|
|
|
|
|
misperrors = {'error': 'Error'}
|
|
|
|
mispattributes = {'input': ['url'], 'output': ['text']}
|
2020-02-26 11:59:14 +01:00
|
|
|
moduleinfo = {'author': 'Oun & Gindt', 'module-type': ['hover'],
|
|
|
|
'description': 'An expansion hover module to expand google search information about an URL'}
|
2020-02-21 12:05:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
def handler(q=False):
|
2020-02-26 11:59:14 +01:00
|
|
|
if q is False:
|
|
|
|
return False
|
|
|
|
request = json.loads(q)
|
|
|
|
if not request.get('url'):
|
|
|
|
return {'error': "Unsupported attributes type"}
|
|
|
|
num_page = 1
|
|
|
|
res = ""
|
|
|
|
search_results = google.search(request['url'], num_page)
|
|
|
|
for i in range(3):
|
|
|
|
res += "("+str(i+1)+")" + '\t'
|
|
|
|
res += json.dumps(search_results[i].description, ensure_ascii=False)
|
|
|
|
res += '\n\n'
|
|
|
|
return {'results': [{'types': mispattributes['output'], 'values':res}]}
|
2020-02-21 12:05:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
def introspection():
|
2020-02-26 11:59:14 +01:00
|
|
|
return mispattributes
|
2020-02-21 12:05:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
def version():
|
2020-02-26 11:59:14 +01:00
|
|
|
return moduleinfo
|