forked from serpapi/google-search-results-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testwrapper.py
28 lines (25 loc) · 872 Bytes
/
testwrapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from serpwrapper import QUERY
import sys
class NotEnoughArgsError(Exception):
pass
def test_query():
"""Tests an API call to get a HTML content"""
params = {}
if len(sys.argv) < 3 :
raise NotEnoughArgsError(
"SERP API requires user to put in Query and Location as command-line arguments"
)
params['query'] = sys.argv[1]
params['location'] = sys.argv[2]
if len(sys.argv) == 4:
params['ui_lang'] = sys.argv[3]
if len(sys.argv) == 5:
params['country'] = sys.argv[4]
if len(sys.argv) == 6:
params['num_results'] = sys.argv[5] if sys.argv[5] else None
# print query, location
query_instance = QUERY(None)
return query_instance.retrieve_html(params)
# assert isinstance(response, dict)
# assert response['id'] == 1396, "The ID should be in the response"
test_query()