Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:04
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
parses outside lands lineup and generates a json of artists along with Spotify, Echo Nest and Rdio IDs
import sys
from bs4 import BeautifulSoup
import json
import pyen
en = pyen.Pyen()
def get_fid(artist, idspace):
if 'foreign_ids' in artist and len(artist['foreign_ids']) > 0:
for fids in artist['foreign_ids']:
if fids['catalog'] == idspace:
return fids['foreign_id']
return None
def en_artist_lookup(name):
response = en.get('artist/search', name=name,
bucket=['id:spotify', 'id:rdio-US'])
artists = response['artists']
if len(artists) > 0:
artist = artists[0]
print artist
enid = artist['id']
spid = get_fid(artist, 'spotify')
rdio = get_fid(artist, 'rdio-US')
if rdio:
rdio = rdio.split(':')[2]
print name, '/', artist['name'], enid, spid, rdio
ids = {
return ids
return {}
if __name__ == '__main__':
lineup = []
f = open(sys.argv[1])
html_doc =
soup = BeautifulSoup(html_doc)
for a in soup.find_all('a', class_='band'):
name = a.text.strip()
ids = en_artist_lookup(name)
artist = {
'artist' : name,
'link' : a['href'],
'ids' : ids
out = open('lineup_2014.json', 'w')
print >> out, json.dumps(lineup, indent=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment