Skip to content

Commit cf74068

Browse files
author
vs
committed
add geocoding + reverse_geocoding
1 parent c417cf1 commit cf74068

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

outscraper/api_client.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,3 +1004,63 @@ def capterra_reviews(self, query: Union[list, str], limit: int = 100, sort: str
10041004
}, headers=self._api_headers)
10051005

10061006
return self._handle_response(response, wait_async, async_request)
1007+
1008+
def geocoding(self, query: Union[list, str], ui: bool = None, fields: Union[list, str] = None, async_request: bool = False, webhook: str = None) -> list:
1009+
'''
1010+
Translates human-readable addresses into locations on the map (latitude, longitude).
1011+
1012+
Parameters:
1013+
query (list | str): addresses specifying the location for which you want to get the coordinates (e.g., 321 California Ave, Palo Alto, CA 94306, Central Park, NY). Using a lists allows multiple queries (up to 250) to be sent in one request and save on network latency time.
1014+
ui (bool): parameter defines whether a task will be executed as a UI task. This is commonly used when you want to create a regular platform task with API. Using this parameter overwrites the async_request parameter to `True`.
1015+
fields (list | str): parameter defines which fields you want to include with each item returned in the response. By default, it returns all fields.
1016+
async_request (bool): parameter defines the way you want to submit your task to Outscraper. It can be set to `False` (default) to send a task and wait until you got your results, or `True` to submit your task and retrieve the results later using a request ID with `get_request_archive`. Each response is available for `2` hours after a request has been completed.
1017+
webhook (str): parameter defines the URL address (callback) to which Outscraper will create a POST request with a JSON body once a task/request is finished. Using this parameter overwrites the webhook from integrations.
1018+
1019+
Returns:
1020+
list: json result
1021+
1022+
See: https://app.outscraper.com/api-docs#tag/Other-Services/paths/~1geocoding/get
1023+
'''
1024+
1025+
queries = as_list(query)
1026+
wait_async = async_request or len(queries) > 50
1027+
1028+
response = requests.get(f'{self._api_url}/geocoding', params={
1029+
'query': queries,
1030+
'async': wait_async,
1031+
'fields': parse_fields(fields),
1032+
'ui': ui,
1033+
'webhook': webhook,
1034+
}, headers=self._api_headers)
1035+
1036+
return self._handle_response(response, wait_async, async_request)
1037+
1038+
def reverse_geocoding(self, query: Union[list, str], ui: bool = None, fields: Union[list, str] = None, async_request: bool = False, webhook: str = None) -> list:
1039+
'''
1040+
Translate locations on the map into human-readable addresses.
1041+
1042+
Parameters:
1043+
query (list | str): the latitude and longitude coordinates specifying the location for which you want the closest, human-readable address (e.g., 40.7624284 -73.973794, 37.427074,-122.1439166). Using a lists allows multiple queries (up to 250) to be sent in one request and save on network latency time.
1044+
ui (bool): parameter defines whether a task will be executed as a UI task. This is commonly used when you want to create a regular platform task with API. Using this parameter overwrites the async_request parameter to `True`.
1045+
fields (list | str): parameter defines which fields you want to include with each item returned in the response. By default, it returns all fields.
1046+
async_request (bool): parameter defines the way you want to submit your task to Outscraper. It can be set to `False` (default) to send a task and wait until you got your results, or `True` to submit your task and retrieve the results later using a request ID with `get_request_archive`. Each response is available for `2` hours after a request has been completed.
1047+
webhook (str): parameter defines the URL address (callback) to which Outscraper will create a POST request with a JSON body once a task/request is finished. Using this parameter overwrites the webhook from integrations.
1048+
1049+
Returns:
1050+
list: json result
1051+
1052+
See: https://app.outscraper.com/api-docs#tag/Other-Services/paths/~1reverse-geocoding/get
1053+
'''
1054+
1055+
queries = as_list(query)
1056+
wait_async = async_request or len(queries) > 50
1057+
1058+
response = requests.get(f'{self._api_url}/reverse-geocoding', params={
1059+
'query': queries,
1060+
'async': wait_async,
1061+
'fields': parse_fields(fields),
1062+
'ui': ui,
1063+
'webhook': webhook,
1064+
}, headers=self._api_headers)
1065+
1066+
return self._handle_response(response, wait_async, async_request)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def readme():
88

99
setup(
1010
name='outscraper',
11-
version='5.4.1',
11+
version='5.5.0',
1212
description='Python bindings for the Outscraper API',
1313
long_description=readme(),
1414
classifiers = ['Programming Language :: Python',

0 commit comments

Comments
 (0)