Skip to content

Instantly share code, notes, and snippets.

@erinxocon
Created May 31, 2015 07:16
Show Gist options
  • Save erinxocon/ec90a9d27a329f9fef2f to your computer and use it in GitHub Desktop.
Save erinxocon/ec90a9d27a329f9fef2f to your computer and use it in GitHub Desktop.
Short script to pull attendance information for the bonnaroo lineup.
from bs4 import BeautifulSoup
import csv
import requests
def get_linup():
"""Returns a request response object of the lineup html"""
return requests.get('http://lineup.bonnaroo.com')
def get_artist_list(lineup):
"""Create an artist-id list to be used to search for their numbers"""
soup = BeautifulSoup(lineup.text)
artist_id_list = []
for i in soup.find_all('a', {'class': 'band'}):
artist_id_list.append(i['id'])
return artist_id_list
def get_people_added(artist_id_list):
"""
Use artist-id to look up how many people are attending the show and
write results to a csv file for future processing
"""
d = []
for i in artist_id_list:
url = 'http://lineup.bonnaroo.com/band/' + i + '/fpup?version=fb'
r = requests.get(url)
soup = BeautifulSoup(r.text)
artist_info = soup.find("div", {"class": "fl-pop-similar"})
count = artist_info.p.text.split(' ')[0]
artist = artist_info.p.a.text
print count, artist
d.append({'artist': artist.encode('utf-8'), 'count': count})
with open('bonnaroo.csv', 'w') as csvfile:
fieldnames = ['artist', 'count']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for i in d:
writer.writerow(i)
if __name__ == '__main__':
lineup = get_linup()
artist_list = get_artist_list(lineup)
get_people_added(artist_list)
beautifulsoup4==4.3.2
requests==2.6.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment