Last active
January 25, 2023 15:05
-
-
Save xoelop/7dc733e29298dda5b95b7864dc6887b9 to your computer and use it in GitHub Desktop.
Downloads all paid invoices on Stripe, collected automatically, between 2 dates, in PDF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# if .env, source .env | |
if test -f .env; then | |
source .env && | |
echo `date`: sourcing .env | |
fi | |
# mkdir if not exists | |
mkdir -p data/script_invoices | |
# download invoices created later or on this date (yyyy-mm-dd) | |
d_min=2022-10-01 | |
# transform d to timestamp | |
epochDate=$(date -j -f "%Y-%m-%d" "${d_min}" "+%s") | |
echo "epochDate: ${epochDate}" | |
# until | |
d_max=2022-12-31 | |
epochDateMax=$(date -j -f "%Y-%m-%d" "${d_max}" "+%s") | |
echo "epochDate: ${epochDate}" | |
curl -G https://api.stripe.com/v1/invoices \ | |
-u $STRIPE_SK: \ | |
-d created[gte]=${epochDate} \ | |
-d created[lte]=${epochDateMax} \ | |
-d limit=100 \ | |
-d collection_method=charge_automatically \ | |
-o data/script_invoices/invoices.json | |
# get invoice PDFs, save them to a .txt file | |
cat data/script_invoices/invoices.json | jq -r '.data[].invoice_pdf' > data/script_invoices/invoices_pdf_urls.txt | |
# make pdf folder it not exists | |
mkdir -p data/script_invoices/pdfs | |
# download files in parallel | |
cat data/script_invoices/invoices_pdf_urls.txt | parallel --gnu "wget -P data/script_invoices/pdfs {}" | |
# add .pdf extension to all files in folder | |
for f in data/script_invoices/pdfs/*; do mv "$f" "${f}.pdf"; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment