You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.7 KiB
54 lines
1.7 KiB
#! /bin/python3
|
|
|
|
from lbcapi import api
|
|
import sys
|
|
import os
|
|
from urllib.parse import urlparse
|
|
from urllib.parse import parse_qs
|
|
|
|
import pdb
|
|
|
|
arg_count = len(sys.argv)
|
|
max_records = -1
|
|
if arg_count == 2:
|
|
# print("A max count of", sys.argv[1] ,"has been provided")
|
|
max_records = int(sys.argv[1])
|
|
|
|
|
|
if "LB_HMAC_KEY" in os.environ and "LB_HMAC_SECRET" in os.environ :
|
|
hmac_key = os.environ["LB_HMAC_KEY"]
|
|
hmac_secret = os.environ["LB_HMAC_SECRET"]
|
|
else :
|
|
print("LB_HMAC_KEY and LB_HMAC_SECRET env variables must be set")
|
|
exit(1)
|
|
|
|
conn = api.hmac(hmac_key, hmac_secret)
|
|
|
|
exported_count = 0
|
|
|
|
# print("About to call the API for the first time")
|
|
params = {'order_by': ['-closed_at'], 'fields': 'released_at,contact_id,amount, closed_at, canceled_at'}
|
|
api_res = conn.call('GET', '/api/dashboard/released/seller/', params = params).json()
|
|
|
|
trades = api_res["data"]["contact_list"]
|
|
next_page_available = True
|
|
|
|
while next_page_available == True :
|
|
# import pdb; pdb.set_trace()
|
|
|
|
for trade in trades:
|
|
data = trade["data"]
|
|
print(data["released_at"] + "," + str(data["contact_id"]) + "," + data["amount"])
|
|
|
|
exported_count = exported_count + 1
|
|
if max_records != -1 and exported_count == max_records:
|
|
exit(0)
|
|
if "pagination" in api_res and "next" in api_res["pagination"] :
|
|
# print("We have a next page!")
|
|
pagination_data = urlparse(api_res["pagination"]["next"])
|
|
next_params = parse_qs(pagination_data.query)
|
|
api_res = conn.call('GET', '/api/dashboard/released/seller/', params = next_params).json()
|
|
trades = api_res["data"]["contact_list"]
|
|
else :
|
|
# print("No next page available!")
|
|
next_page_available = False
|
|
|