import csv import shlex import subprocess import uuid import argparse def get_missed_tracks_from_csv(file_path): missed_tracks = [] with open(file_path, mode='r') as csv_file: print(f"Reading from {file_path}") csv_reader = csv.DictReader(csv_file) for row in csv_reader: isrc = row['isrc'] tuid = int(row['tuid']) missed_tracks.append((isrc, tuid)) return missed_tracks def main(csv_file_path): missed_tracks = get_missed_tracks_from_csv(csv_file_path) total_tracks = len(missed_tracks) print(f"Total rows to process: {total_tracks}") print("Starting batch...") for index, track in enumerate(missed_tracks, start=1): isrc = track[0] tuid = track[1] # hit refresh endpoint for each isrc and tuid that needs to be refreshed if isrc and tuid: oa_user_id = 'alw:1791' correlation_id = str(uuid.uuid4()) command = f"curl -d '{{ \"tuid\": {tuid} }}' -H 'Content-Type: application/json' -H 'Orchard-User-Id: {oa_user_id}' -H 'Correlation-Id: {correlation_id}' -X PUT https://ows-masters-registry.theorchard.io/ownership/isrc/{isrc}/refresh" curl_result = subprocess.run( shlex.split(command), stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8' ) if index % 100 == 0: print(f"Processing {index}/{total_tracks}") print("Batch finished, exiting.") if __name__ == "__main__": parser = argparse.ArgumentParser(description='Takes a csv file with isrc and tuid columns and hits the refresh endpoint for each') parser.add_argument('csv_file', type=str, help='Path to the CSV file') args = parser.parse_args() main(args.csv_file)