Skip to content

Commit

Permalink
add get_tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
vs committed Oct 3, 2023
1 parent ff5effd commit e62cbd5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
28 changes: 27 additions & 1 deletion outscraper/api_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import requests
from time import sleep
from typing import Union
from typing import Union, Tuple

from .utils import as_list, parse_fields

Expand Down Expand Up @@ -29,6 +29,32 @@ def __init__(self, api_key: str, requests_pause: int = 5) -> None:
}
self._requests_pause = requests_pause

def get_tasks(self, query: str = '', last_id: str = '', page_size: int = 10) -> Tuple[list, bool]:
'''
Fetch user UI tasks.
Parameters:
query (str): parameter specifies the search query (tag).
last_id (str): parameter specifies the last task ID. It's commonly used in pagination.
page_size (str): parameter specifies the number of items to return.
Returns:
list: requests history
See: https://app.outscraper.com/api-docs#tag/Outscraper-Platform-UI/paths/~1tasks/get
'''
response = requests.get(f'{self._api_url}/tasks?query={query}&lastId={last_id}&pageSize={page_size}', headers=self._api_headers)

if 199 < response.status_code < 300:
data = response.json()

if 'errorMessage' in data:
raise Exception(f'Error: {data["errorMessage"]}')

return data['tasks'], data['has_more']

raise Exception(f'Response status code: {response.status_code}')

def get_requests_history(self, type: str = 'running') -> list:
'''
Fetch up to 100 of your last requests.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def readme():

setup(
name='outscraper',
version='4.0.2',
version='4.0.1',
description='Python bindings for the Outscraper API',
long_description=readme(),
classifiers = ['Programming Language :: Python',
Expand Down

0 comments on commit e62cbd5

Please sign in to comment.