Skip to content

Commit 0b8829c

Browse files
DataUrbanEconGeekRosa
andauthored
Add G2 reviews and trustpilot reviews (#17)
Co-authored-by: Rosa <arosa@harriswilliams.com>
1 parent 169e952 commit 0b8829c

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

outscraper/api_client.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,3 +813,80 @@ def youtube_comments(self, query: Union[list, str], per_query: int = 100, langua
813813
}, headers=self._api_headers)
814814

815815
return self._handle_response(response, wait_async, async_request)
816+
817+
def g2_reviews(self, query: Union[list, str], limit: int = 100, sort: str = 'g2_default', cutoff: int = None,
818+
fields: Union[list, str] = None, async_request: bool = False, ui: bool = None, webhook: str = None
819+
) -> list:
820+
'''
821+
Returns reviews from a list of products.
822+
823+
Parameters:
824+
query (list | str): Links to G2 products (e.g., https://www.g2.com/products/outscraper). Using a lists allows multiple queries (up to 250) to be sent in one request and save on network latency time.
825+
limit (int): parameter specifies the limit of reviews to get from one query.
826+
sort (str): parameter specifies one of the sorting types. Available values: "g2_default", "most_recent", "most_helpful", "highest_rated", "lowest_rated".
827+
cutoff (int): parameter specifies the oldest timestamp value for items. Using the cutoff parameter overwrites sort parameter to most recent.
828+
fields (list | str): parameter defines which fields you want to include with each item returned in the response. By default, it returns all fields.
829+
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.
830+
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`.
831+
832+
Returns:
833+
list: json result
834+
835+
See: https://app.outscraper.com/api-docs#tag/YouTube/paths/~1g2~1reviews/get
836+
'''
837+
838+
queries = as_list(query)
839+
wait_async = async_request or limit > 499 or len(queries) > 10
840+
841+
response = requests.get(f'{self._api_url}/g2/reviews', params={
842+
'query': queries,
843+
'limit': limit,
844+
'sort': sort,
845+
'cutoff': cutoff,
846+
'async': wait_async,
847+
'fields': parse_fields(fields),
848+
'ui': ui,
849+
'webhook': webhook,
850+
}, headers=self._api_headers)
851+
852+
return self._handle_response(response, wait_async, async_request)
853+
854+
def trustpilot_reviews(self, query: Union[list, str], limit: int = 100, languages: str = 'default', sort: str = '',
855+
cutoff: int = None, fields: Union[list, str] = None, async_request: bool = False, ui: bool = None,
856+
webhook: str = None
857+
) -> list:
858+
'''
859+
Returns reviews from Trustpilot businesses. In case no reviews were found by your search criteria, your search request will consume the usage of one review.
860+
861+
Parameters:
862+
query (list | str): Links to Trustpilot pages or domain names (e.g., outscraper.com, https://www.trustpilot.com/review/outscraper.com).
863+
limit (int): parameter specifies the limit of reviews to get from one query.
864+
languages (str): parameter specifies one of the language filters. Available values: "default", "all", "en", "es", "de".
865+
sort (str): parameter specifies one of the sorting types. Available values: "recency".
866+
cutoff (int): parameter specifies the oldest timestamp value for items. Using the cutoff parameter overwrites sort parameter. Therefore, the latest records will be at the beginning (newest first).
867+
fields (list | str): parameter defines which fields you want to include with each item returned in the response. By default, it returns all fields.
868+
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.
869+
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`.
870+
871+
Returns:
872+
list: json result
873+
874+
See: https://app.outscraper.com/api-docs#tag/Trustpilot/paths/~1trustpilot~1reviews/get
875+
'''
876+
877+
queries = as_list(query)
878+
wait_async = async_request or limit > 499 or len(queries) > 10
879+
880+
response = requests.get(f'{self._api_url}/trustpilot/reviews', params={
881+
'query': queries,
882+
'limit': limit,
883+
'languages': languages,
884+
'sort': sort,
885+
'cutoff': cutoff,
886+
'async': wait_async,
887+
'fields': parse_fields(fields),
888+
'ui': ui,
889+
'webhook': webhook,
890+
}, headers=self._api_headers)
891+
892+
return self._handle_response(response, wait_async, async_request)

0 commit comments

Comments
 (0)