Your music, beautifully tracked. All yours. (coming soon) teal.fm
teal-fm atproto
at main 53 lines 1.7 kB view raw
1import json 2import os 3import sys 4 5def update_metadata(): 6 # Get CF_PAGES_URL from environment 7 cf_pages_url = os.environ.get('CF_PAGES_URL') 8 9 if not cf_pages_url: 10 print("CF_PAGES_URL environment variable not found") 11 sys.exit(1) 12 13 # Remove 'https://' if present 14 if cf_pages_url.startswith('https://'): 15 cf_pages_url = cf_pages_url[8:] 16 17 if os.environ.get('CF_PAGES_BRANCH') == 'main': 18 # trim pages url if we are building for prod 19 # TODO: remove this once we have a non-pages-dev url 20 cf_pages_url.split('.')[1:] 21 22 # Path to metadata file 23 metadata_path_pre = 'assets/client-metadata.json' 24 metadata_path = 'dist/client-metadata.json' 25 26 try: 27 # Read the JSON file 28 with open(metadata_path_pre, 'r') as file: 29 metadata = json.load(file) 30 31 # Replace all instances of 'alpha.teal.fm' with CF_PAGES_URL 32 metadata_str = json.dumps(metadata) 33 updated_metadata_str = metadata_str.replace('alpha.teal.fm', cf_pages_url) 34 updated_metadata = json.loads(updated_metadata_str) 35 36 # Write the updated JSON back to file 37 with open(metadata_path, 'w') as file: 38 json.dump(updated_metadata, file, indent=2) 39 40 print(f"Successfully updated {metadata_path} with {cf_pages_url}") 41 42 except FileNotFoundError: 43 print(f"Error: {metadata_path} not found") 44 sys.exit(1) 45 except json.JSONDecodeError: 46 print(f"Error: Invalid JSON in {metadata_path}") 47 sys.exit(1) 48 except Exception as e: 49 print(f"Error: {str(e)}") 50 sys.exit(1) 51 52if __name__ == "__main__": 53 update_metadata()