Created
June 14, 2019 19:18
-
-
Save jarhill0/5dc17437831442602b76494688fa2a8a to your computer and use it in GitHub Desktop.
Get Kishi Bashi's shows and build a nice markdown table.
This file contains hidden or 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
"""Get Kishi Bashi's shows and build a nice markdown table.""" | |
from datetime import datetime | |
from urllib.parse import urlparse | |
import requests | |
def main(): | |
shows = requests.get('https://rest.bandsintown.com/artists/Kishi Bashi/events', | |
params={'date': 'upcoming', | |
'app_id': 'squarespace-joyful-reagan', | |
}).json() | |
print(header()) | |
print('\n'.join(row(show) for show in shows)) | |
def header(): | |
return 'Date | City | Venue | Tickets\n---|---|---|---' | |
def row(show): | |
return '{date} | {city} | {venue} | {tickets}'.format(date=date(show), | |
city=city(show), | |
venue=venue(show), | |
tickets=tickets(show)) | |
def date(show): | |
return datetime.strptime(show['datetime'], '%Y-%m-%dT%X').strftime('%b %-d') | |
def city(show): | |
return pretty_city(show['venue']) | |
def pretty_city(place): | |
city = place['city'] | |
if place['country'] == 'United States': | |
area = place['region'] | |
else: | |
area = place['country'] | |
return '{}, {}'.format(city, area) | |
def venue(show): | |
return show['venue']['name'] | |
def tickets(show): | |
tickets_dict = get_tickets_dict(show['offers']) | |
if tickets_dict is None: | |
return '' | |
tickets_url = clean_url(tickets_dict['url']) | |
return '[Tickets]({})'.format(tickets_url) | |
def clean_url(url): | |
parsed = urlparse(url) | |
return '{scheme}://{netloc}{path}'.format(scheme=parsed.scheme, | |
netloc=parsed.netloc, | |
path=parsed.path) | |
def get_tickets_dict(offers): | |
for d in offers: | |
if d['type'] == 'Tickets': | |
return d | |
return None | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment