52 lines
1.6 KiB
Python
Executable file
52 lines
1.6 KiB
Python
Executable file
#!/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):
|
|
appname = app["Item Description"]
|
|
filename = os.path.join(outdir, f'{appname.replace('/', '_')}.ipa')
|
|
if os.path.exists(filename):
|
|
print(f"{appname} exists, skipping")
|
|
else:
|
|
print(f"Downloading {appname}")
|
|
subprocess.run(["ipatool", "download", "--app-id", app["id"], "-o", filename])
|
|
|
|
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()
|