Created
April 22, 2023 20:47
-
-
Save redraw/6146faef4eb7a1b867a17feb2f765729 to your computer and use it in GitHub Desktop.
python songkick.py 119277-cornelius
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import time | |
import json | |
import requests | |
API_KEY = "bes5VlOjJoyrXx6O" | |
def fetch(session, artist_id, page): | |
response = session.get( | |
f"https://api.songkick.com/api/3.0/artists/{artist_id}/gigography.json", | |
params={"apikey": API_KEY, "page": page} | |
) | |
return response | |
def scrape(artist_id, artist_name): | |
session = requests.Session() | |
events = [] | |
page = 1 | |
while True: | |
response = fetch(session, artist_id, page) | |
if not response.ok: | |
print(response.status_code, response.json()) | |
if input("seguir? y/n") in ("n", "N"): | |
break | |
results = response.json()['resultsPage']['results'] | |
if not results: | |
break | |
page += 1 | |
events += results['event'] | |
print(f"[events={len(events)}] {page=} done.") | |
time.sleep(1) | |
filename = f"{artist_name}.json" | |
with open(filename, "w") as f: | |
json.dump(events, f) | |
print(f"{filename} saved!") | |
if __name__ == "__main__": | |
artist_id, artist_name = sys.argv[1].split("-") | |
scrape(artist_id, artist_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment