From 1fda53e94719e6d35604f1a70bc3d62f61229220 Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Sun, 13 Oct 2024 15:17:15 -0400 Subject: [PATCH] Initial commit --- .envrc | 1 + .gitignore | 1 + flake.lock | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 26 ++++++++++++++++++++++ ipascrape.py | 46 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 135 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 flake.lock create mode 100644 flake.nix create mode 100755 ipascrape.py diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..8392d15 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..92b2793 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.direnv diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..376f488 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1728538411, + "narHash": "sha256-f0SBJz1eZ2yOuKUr5CA9BHULGXVSn6miBuUWdTyhUhU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b69de56fac8c2b6f8fd27f2eca01dcda8e0a4221", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..e704905 --- /dev/null +++ b/flake.nix @@ -0,0 +1,26 @@ +{ + description = "IPAScrape"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + outputs = { flake-utils, nixpkgs, ...}: + flake-utils.lib.eachDefaultSystem (system: + let pkgs = nixpkgs.legacyPackages.${system}; + ipatool = pkgs.ipatool.overrideAttrs { + # grab latest unreleased version, which allows downloading by app store ID + src = pkgs.fetchFromGitHub { + owner = "majd"; + repo = "ipatool"; + rev = "63ee6fc6a42a89d51c9caac632cefd65218825ab"; + hash = "sha256-dbsQC/CRcT1/XBVKX/k2AUcLAOeN3IuSLl4GpAGBWPI="; + }; + vendorHash = "sha256-v1hithTdsyNAQj0E9g1nRC90WdM9z4kAQuOh6OScJss="; + }; + in { + devShells.default = pkgs.mkShell { + buildInputs = [ ipatool pkgs.python3 ]; + }; + }); +} diff --git a/ipascrape.py b/ipascrape.py new file mode 100755 index 0000000..f647143 --- /dev/null +++ b/ipascrape.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +import argparse +import csv +import os +import subprocess + +def get_apps(filename): + with open(filename) as f: + c = csv.DictReader(f) + return [ + {**row, "id": row["Item Reference Number"]} + for row in c + if row['Content Type'] == 'iOS and tvOS Apps' + ] + +def apps_from_folder(dirname): + return (get_apps(os.path.join(dirname, "Store Transaction History.csv")) + + get_apps(os.path.join(dirname, "Store Transaction History - Free Apps.csv"))) + +def fetch_app(app, outdir): + print(f"Downloading {app["Item Description"]}") + subprocess.run(["ipatool", "download", "--app-id", app["id"], "-o", outdir]) + +def main(): + parser = argparse.ArgumentParser( + prog="ipascrape", + description="Scrape Apple data export CSVs for valid iOS IPAs connected to your account" + ) + parser.add_argument("-o", "--outputdir", required=True) + parser.add_argument("csvfile", nargs="+") + args = parser.parse_args() + + apps = [] + for filename in args.csvfile: + if os.path.isfile(filename): + apps.extend(get_apps(filename)) + elif os.path.isdir(filename): + apps.extend(apps_from_folder(filename)) + else: + print(f'{filename} does not exist, ignoring') + + for app in apps: + fetch_app(app, args.outputdir) + +if __name__ == "__main__": + main()