Make base search url a member of the request class
Since the request class is loaded prior to values being read from the user's dotenv, the WHOOGLE_RESULT_PER_PAGE var wasn't being used for searches. This moves the definition of the base search url to be intialized in the request class to address this issue. Fixes #497main
parent
d8dcdc7455
commit
b96e3a0acb
|
@ -9,8 +9,6 @@ import os
|
|||
from stem import Signal, SocketError
|
||||
from stem.control import Controller
|
||||
|
||||
SEARCH_URL = 'https://www.google.com/search?gbv=1&num=' + str(
|
||||
os.getenv('WHOOGLE_RESULTS_PER_PAGE', 10)) + '&q='
|
||||
MAPS_URL = 'https://maps.google.com/maps'
|
||||
AUTOCOMPLETE_URL = ('https://suggestqueries.google.com/'
|
||||
'complete/search?client=toolbar&')
|
||||
|
@ -151,6 +149,8 @@ class Request:
|
|||
"""
|
||||
|
||||
def __init__(self, normal_ua, root_path, config: Config):
|
||||
self.search_url = 'https://www.google.com/search?gbv=1&num=' + str(
|
||||
os.getenv('WHOOGLE_RESULTS_PER_PAGE', 10)) + '&q='
|
||||
# Send heartbeat to Tor, used in determining if the user can or cannot
|
||||
# enable Tor for future requests
|
||||
send_tor_signal(Signal.HEARTBEAT)
|
||||
|
@ -224,7 +224,7 @@ class Request:
|
|||
return [_.attrib['data'] for _ in
|
||||
root.findall('.//suggestion/[@data]')]
|
||||
|
||||
def send(self, base_url=SEARCH_URL, query='', attempt=0,
|
||||
def send(self, base_url='', query='', attempt=0,
|
||||
force_mobile=False) -> Response:
|
||||
"""Sends an outbound request to a URL. Optionally sends the request
|
||||
using Tor, if enabled by the user.
|
||||
|
@ -285,7 +285,7 @@ class Request:
|
|||
disable=True)
|
||||
|
||||
response = requests.get(
|
||||
base_url + query,
|
||||
(base_url or self.search_url) + query,
|
||||
proxies=self.proxies,
|
||||
headers=headers,
|
||||
cookies=cookies)
|
||||
|
@ -295,6 +295,6 @@ class Request:
|
|||
attempt += 1
|
||||
if attempt > 10:
|
||||
raise TorError("Tor query failed -- max attempts exceeded 10")
|
||||
return self.send(base_url, query, attempt)
|
||||
return self.send((base_url or self.search_url), query, attempt)
|
||||
|
||||
return response
|
||||
|
|
Loading…
Reference in New Issue