import os import json from string import Template ENVS = { "local": "http://0.0.0.0:8000", "dev": "https://dev-images-api.atlas.stream", "qa": "https://qa-images-api.atlas.stream", "prod": "https://images-api.atlas.stream", } LIMIT = 1000 def parse_fields(): result = set() for filename in os.listdir("data"): with open(f"data/{filename}", "r") as f: data = json.load(f) for item in data.get("items", []): id = item.get("id") if id: result.add((id, item.get("name", ""))) return result def render(title, items, base_url): with open(f"templates/row.html") as f: row_template = Template(f.read()) content = "\n".join( [ row_template.substitute(id=id, name=name, base_url=base_url) for id, name in items[:LIMIT] ] ) with open(f"templates/generic.html") as f: template = Template(f.read()) return template.substitute(title=title, content=content) def generate(): apple = [(id, name) for id, name in parse_fields() if id.startswith("pl.")] spotify = [(id, name) for id, name in parse_fields() if not id.startswith("pl.")] print(f"Apple qty: {len(apple)}") print(f"Spotify qty: {len(spotify)}") for env, url in ENVS.items(): with open(f"output/apple_playlists_{env}.html", "w") as f: f.write( render( f"Apple music ({env}: {url})", apple, f"{url}/v2/playlists/by_apple_music_id", ) ) with open(f"output/spotify_playlists_{env}.html", "w") as f: f.write( render( f"Spotify ({env}: {url})", spotify, f"{url}/v2/playlists/by_spotify_id", ) ) if __name__ == "__main__": generate()