Skip to content

Instantly share code, notes, and snippets.

@redraw
Created April 22, 2023 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save redraw/6146faef4eb7a1b867a17feb2f765729 to your computer and use it in GitHub Desktop.
Save redraw/6146faef4eb7a1b867a17feb2f765729 to your computer and use it in GitHub Desktop.
python songkick.py 119277-cornelius
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