fediversion/backend/scripts/find_artist.py
fullsizemalt 762d2b81ff
Some checks failed
Deploy Fediversion / deploy (push) Failing after 1s
feat: Add MSI, SCI, Disco Biscuits importers + refactor About page to be band-agnostic
2025-12-28 22:36:52 -08:00

48 lines
1.3 KiB
Python

import os
import sys
import requests
from dotenv import load_dotenv
load_dotenv()
API_KEY = os.getenv("SETLISTFM_API_KEY")
BASE_URL = "https://api.setlist.fm/rest/1.0"
def search_artist(name):
print(f"Searching for '{name}'...")
headers = {
"Accept": "application/json",
"x-api-key": API_KEY
}
url = f"{BASE_URL}/search/artists"
params = {"artistName": name, "sort": "relevance"}
try:
response = requests.get(url, headers=headers, params=params)
response.raise_for_status()
data = response.json()
artists = data.get("artist", [])
if not artists:
print("No artists found.")
return
print(f"Found {len(artists)} results:")
for artist in artists[:3]:
print(f" - Name: {artist.get('name')}")
print(f" MBID: {artist.get('mbid')}")
print(f" URL: {artist.get('url')}")
print(f" Disambiguation: {artist.get('disambiguation', 'N/A')}")
print("-" * 20)
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python find_artist.py <artist_name>")
sys.exit(1)
search_artist(sys.argv[1])