Skip to content

Instantly share code, notes, and snippets.

@jfialkoff
Last active December 12, 2015 05:48
Show Gist options
  • Save jfialkoff/4724457 to your computer and use it in GitHub Desktop.
Save jfialkoff/4724457 to your computer and use it in GitHub Desktop.
Takes a list of plain-text gigs (or events) in descending date order, and formats them for the web. Sample input in code.
"""
Takes a list of plain-text gigs (or events) in descending date order, and formats
them for the web in ascending date order. Here's an example of the input that's
expected (make sure to hit CTRL+D at the end of the input:
3/7: City Tap (Pay Notes) - 80%
City Tap (Philadelphia): City Tap House Philadelphia, PA
Shimmy
Drums: Alex (Pay Notes)
?Bass: Matt (Pay Notes)
?Trumpet: Dan (Pay Notes)
2/23: Swing Dance of Glory (Pay Notes) - 100%
The Rotunda (Philadelphia): The Rotunda Philadelphia, PA
Quartet/Swing
Drums: Alex (Pay Notes)
Guitar: Ryan (Pay Notes)
Bass: Joshua (Pay Notes)
http://event.link.com
- Some notes
- Some more notes
2/16, 10pm-1am: City Tap (Pay Notes) - 100%
City Tap (Philadelphia): City Tap House Philadelphia, PA
Shimmy
Bass: Matt (Pay Notes)
Drums: Alex (Pay Notes)
Trumpet: Dan (Pay Notes)
"""
import re
import sys
print("Copy and paste events below.")
event_text = sys.stdin.readlines()
line_pats = {
'title': r'(?P<title>.*?) \(.*',
'location': r'(?P<venue>.*?): (?P<address>.*)',
'description': r'(?P<description>.*)',
'musician': r'\??(?P<instrument>.*?): (?P<musician>.*?) \(.*',
'more_info': r'(?P<more_info>https?://.*)',
'note': r'- (?P<note>.*)',
'blank': r'\s*\n'
}
next_line = {
'title': ('location',),
'location': ('description',),
'description': ('musician',),
'musician': ('musician', 'more_info', 'note', 'blank'),
'more_info': ('note', 'blank',),
'note': ('note', 'blank'),
'blank': ('blank', 'title')
}
descriptions = {
'Shimmy': 'Josh Fialkoff and the Downtown Shimmy play live swing, ' +
'soul and blues.',
'Trio': 'The Josh Fialkoff Trio plays swing, soul and blues.',
'Quartet': 'The Josh Fialkoff Quartet plays swing, soul and blues.',
'Quartet/Swing': 'The Josh Fialkoff Quartet plays hot jazz and swing.'
}
events = []
line_types = next_line['blank']
next_line_type = None
for line in event_text:
for line_type in line_types:
pat = line_pats[line_type]
match = re.match(pat, line)
if match: break
if not match:
raise Exception("Was expecting %s line." % ','.join(line_types))
if line_type == 'title':
event = {'musicians': []}
events.insert(0, event)
if line_type == 'musician':
event['musicians'].append(match.groupdict())
elif line_type not in ('blank', 'note'):
event.update(match.groupdict())
line_types = next_line[line_type]
print("********************* BEGIN WEBSITE *********************")
for event in events:
print('<div id="event">')
print('\t<div class="event-title">%s</div>' % event['title'])
print('\t<div class="event-location"><a target="_blank" href="http://maps.google.com/?q=%s">%s</a></div>' % (
event['address'], event['venue']))
more_info = ''
if 'more_info' in event:
more_info = ('<a target="_blank" href="%s">More info here.</a>' %
event['more_info'])
description = event['description']
if description in descriptions:
description = descriptions[description]
description += " "
musicians = event['musicians']
for i, musician in enumerate(musicians):
if i == len(musicians) - 1:
if i == 0:
mformat = '%s on %s. '
else:
mformat = "and %s on %s."
else:
mformat = "%s on %s, "
description += mformat % (musician['musician'],
musician['instrument'].lower())
print('\t<div class="event-description">%s%s</div>' % (
description, more_info))
print('</div>\n')
print("********************* END WEBSITE *********************")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment