56 lines
1.4 KiB
Python
56 lines
1.4 KiB
Python
import requests
|
|
import json
|
|
import time
|
|
|
|
API_KEY = 'B3526FC8-82CB-4798-92C8-22AF05F9A49F'
|
|
BASE_URL = 'https://support.atl-group.ru/api/v3'
|
|
|
|
# Disable SSL warnings
|
|
import urllib3
|
|
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
|
|
|
def get_requests_page(start_index, row_count=10):
|
|
"""Get a page of requests."""
|
|
url = BASE_URL + '/requests'
|
|
params = {
|
|
'TECHNICIAN_KEY': API_KEY,
|
|
'listInfo': json.dumps({
|
|
'row_count': row_count,
|
|
'start_index': start_index,
|
|
'sort_field': 'id',
|
|
'sort_order': 'asc'
|
|
})
|
|
}
|
|
|
|
resp = requests.get(url, params=params, timeout=30, verify=False)
|
|
data = resp.json()
|
|
|
|
return data
|
|
|
|
# Test pagination
|
|
print('Testing pagination...')
|
|
start = 1
|
|
total_fetched = 0
|
|
|
|
while True:
|
|
data = get_requests_page(start, 10)
|
|
requests_list = data.get('requests', [])
|
|
list_info = data.get('list_info', {})
|
|
has_more = list_info.get('has_more_rows', False)
|
|
|
|
if not requests_list:
|
|
break
|
|
|
|
total_fetched += len(requests_list)
|
|
first_id = requests_list[0].get('id')
|
|
last_id = requests_list[-1].get('id')
|
|
print(f'Page starting at {start}: got {len(requests_list)} requests (IDs {first_id}-{last_id}), has_more={has_more}')
|
|
|
|
if not has_more:
|
|
break
|
|
|
|
start += 10
|
|
time.sleep(0.5) # Rate limiting
|
|
|
|
print(f'\nTotal fetched: {total_fetched}')
|