Created
May 25, 2018 13:06
-
-
Save ri0t/b107032b48545765b407720c2f3dfc84 to your computer and use it in GitHub Desktop.
LAC18 Summary extractor
This file contains 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
def ical_import_filter(original, log): | |
summary = original.summary | |
stuff = summary.split('\n', maxsplit=5) | |
# if not(stuff[0].startswith('Author:') and stuff[1].startswith('Type:') and stuff[2].startswith('Topics:') and stuff[3].startswith('Keywords:') and stuff[4].startswith('Abstract')): | |
# log(str(summary.replace('\n', '@@@\n')), lvl=hilight) | |
data = { | |
'author': [], | |
'event_type': 'Unknown', | |
'event_id': 'Unknown', | |
'event_keywords': [], | |
'event_topics': [], | |
'abstract': ['-'], | |
'keywords': "", | |
'topics': "", | |
'speakers': "", | |
'size': 3 | |
} | |
for line in stuff: | |
if line.startswith('Author: '): | |
authors = line.split('Author: ')[1] | |
for author in authors.split('| '): | |
data['author'].append(author.split(':')[1].lstrip()) | |
elif line.startswith('Type: '): | |
data['event_type'] = line.split('Type: ')[1] | |
elif line.startswith('Topics: '): | |
data['event_topics'] = line.split('Topics: ')[1].split(', ') | |
elif line.startswith('Keywords: '): | |
data['event_keywords'] = line.split('Keywords: ')[1].split(', ') | |
elif line.startswith('Abstract: '): | |
data['abstract'].append(line.split('Abstract: ')[1]) | |
elif 'ID: ' in line: | |
more_abstract, data['event_id'] = line.split('ID: ', maxsplit=1) | |
data['abstract'].append(more_abstract) | |
else: | |
data['abstract'].append(line) | |
data['abstract'] = " ".join(data['abstract']).lstrip("- ") | |
if len(data['abstract']) > 100: | |
data['size'] = 4 | |
if len(data['abstract']) > 250: | |
data['size'] = 5 | |
keyword = '<span class="label label-default">%s</span>\n' | |
for word in data['event_keywords']: | |
data['keywords'] += keyword % word | |
for topic in data['event_topics']: | |
data['topics'] += keyword % topic | |
data['keywords'] = data['keywords'].rstrip('\n') | |
data['topics'] = data['topics'].rstrip('\n') | |
if len(data['author']) > 1: | |
for speaker in data['author']: | |
data['speakers'] += " " + speaker + ", " | |
data['speakers'] = data['speakers'].rstrip(', ') | |
else: | |
data['speakers'] = data['author'][0] | |
new_summary = """<div class="event_summary"> | |
<h5> {speakers} - Type: {event_type}""".format(**data) | |
if len(data['topics']) > 0: | |
new_summary += " - <small>Topics: {topics}</small>".format(**data) | |
new_summary += """</h5>\n<h{size}>{abstract}</h{size}> | |
<div class="row"> | |
<div class="col-md-10"> | |
{keywords} | |
</div> | |
<div class="col-md-2"> | |
<small>Talk ID: {event_id}</small> | |
</div> | |
</div> | |
</div> | |
""".format(**data) | |
original.summary = new_summary | |
return original | |
# 'Author: 1:LAC team\nType: Lightning Talks\nAbstract: A set of lightning talks by you!\nID: 103' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment