Skip to content

Commit e62cbd5

Browse files
author
vs
committed
add get_tasks
1 parent ff5effd commit e62cbd5

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

outscraper/api_client.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import requests
22
from time import sleep
3-
from typing import Union
3+
from typing import Union, Tuple
44

55
from .utils import as_list, parse_fields
66

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

32+
def get_tasks(self, query: str = '', last_id: str = '', page_size: int = 10) -> Tuple[list, bool]:
33+
'''
34+
Fetch user UI tasks.
35+
36+
Parameters:
37+
query (str): parameter specifies the search query (tag).
38+
last_id (str): parameter specifies the last task ID. It's commonly used in pagination.
39+
page_size (str): parameter specifies the number of items to return.
40+
41+
Returns:
42+
list: requests history
43+
44+
See: https://app.outscraper.com/api-docs#tag/Outscraper-Platform-UI/paths/~1tasks/get
45+
'''
46+
response = requests.get(f'{self._api_url}/tasks?query={query}&lastId={last_id}&pageSize={page_size}', headers=self._api_headers)
47+
48+
if 199 < response.status_code < 300:
49+
data = response.json()
50+
51+
if 'errorMessage' in data:
52+
raise Exception(f'Error: {data["errorMessage"]}')
53+
54+
return data['tasks'], data['has_more']
55+
56+
raise Exception(f'Response status code: {response.status_code}')
57+
3258
def get_requests_history(self, type: str = 'running') -> list:
3359
'''
3460
Fetch up to 100 of your last requests.

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='4.0.2',
11+
version='4.0.1',
1212
description='Python bindings for the Outscraper API',
1313
long_description=readme(),
1414
classifiers = ['Programming Language :: Python',

0 commit comments

Comments
 (0)