commit
f0965547e9
6 changed files with 99 additions and 0 deletions
@ -0,0 +1,4 @@ |
|||||
|
.vscode |
||||
|
test |
||||
|
venv |
||||
|
*.csv |
||||
@ -0,0 +1,22 @@ |
|||||
|
FROM python:3.9 |
||||
|
|
||||
|
RUN /usr/local/bin/python -m pip install --upgrade pip |
||||
|
|
||||
|
ENV PROJECT_USER=lbapi |
||||
|
ENV PROJECT_USER_UID=1000 |
||||
|
ENV PROJECT_USER_GID=1000 |
||||
|
ENV PROJECT_USER_HOME=/home/${PROJECT_USER} |
||||
|
ENV PROJECT_USER_APP_HOME=${PROJECT_USER_HOME}/lbapi |
||||
|
|
||||
|
RUN groupadd -r --gid ${PROJECT_USER_GID} ${PROJECT_USER} |
||||
|
RUN useradd --system --no-log-init --uid ${PROJECT_USER_UID} --gid ${PROJECT_USER_GID} --home-dir ${PROJECT_USER_HOME} --create-home --shell /bin/bash ${PROJECT_USER} |
||||
|
|
||||
|
RUN mkdir -p ${PROJECT_USER_APP_HOME} && chown -R ${PROJECT_USER}:${PROJECT_USER} ${PROJECT_USER_APP_HOME} |
||||
|
|
||||
|
USER ${PROJECT_USER} |
||||
|
|
||||
|
WORKDIR ${PROJECT_USER_APP_HOME} |
||||
|
COPY --chown=${PROJECT_USER_UID}:${PROJECT_USER_GID} requirements.txt export_csv.py ./ |
||||
|
RUN pip3 install -r requirements.txt |
||||
|
|
||||
|
CMD ["python3", "export_csv.py"] |
||||
@ -0,0 +1,9 @@ |
|||||
|
# CSV Export - Localbitcoins |
||||
|
|
||||
|
Exports your trades as a seller out onto CSV to stdout |
||||
|
|
||||
|
``` |
||||
|
virtualenv venv |
||||
|
source venv/bin/activate |
||||
|
pip3 install -r requirements.txt |
||||
|
``` |
||||
@ -0,0 +1,9 @@ |
|||||
|
version: '3' |
||||
|
services: |
||||
|
lb_csv_export: |
||||
|
build: . |
||||
|
image: "lb_csv_export" |
||||
|
environment: |
||||
|
- LB_HMAC_KEY=LB_HMAC_KEY |
||||
|
- LB_HMAC_SECRET=LB_HMAC_SECRET |
||||
|
|
||||
@ -0,0 +1,54 @@ |
|||||
|
#! /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 |
||||
@ -0,0 +1 @@ |
|||||
|
lbcapi==1.0.3 |
||||
Loading…
Reference in new issue