Created
July 27, 2017 09:05
-
-
Save lindemann09/ef3cad4822d9b40e0b2a0e82a24a2b2a to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
# coding: utf8 | |
import csv | |
import datetime | |
from orderedset import OrderedSet | |
from docx import Document | |
def _get_formated_date(time_string): | |
ret = datetime.datetime.strptime(time_string, '%Y-%m-%d %H:%M') | |
ret = ret.strftime('%A, %d/%b/%Y') | |
return ret | |
def _get_formated_time(time_string): | |
ret = datetime.datetime.strptime(time_string, '%Y-%m-%d %H:%M') | |
ret = ret.time() | |
ret = ret.strftime("%I:%M%p").lower() | |
return ret | |
def _main(): | |
document = Document() | |
with open('programm/ESCoP2017_sessions_2017-07-25_10-54-36.csv', 'rb') as csvfile: | |
reader = csv.DictReader(csvfile, delimiter=',', quotechar='"') | |
for row in reader: | |
document.add_heading(unicode(row['session_title'], 'utf-8'), 0) | |
document.add_paragraph( | |
'Time: {}: {} - {}'.format( | |
_get_formated_date(row['session_start']), | |
_get_formated_time(row['session_start']), | |
_get_formated_time(row['session_end']), | |
) | |
) | |
document.add_paragraph('Location: {}'.format(unicode(row['session_room'], 'utf-8'))) | |
for x in xrange(1, 5): | |
authors = row['p{}_authors'.format(x)] | |
authors = authors.split(',') | |
authors = [a.strip() for a in authors] | |
authors = ', '.join(authors) | |
authors = unicode(authors, 'utf-8') | |
organisations = row['p{}_organisations'.format(x)].split(';') | |
organisations = [o.strip() for o in organisations] | |
organisations = OrderedSet(organisations) | |
organisations = ', '.join(organisations) | |
organisations = unicode(organisations, 'utf-8') | |
document.add_heading(unicode(row['p{}_title'.format(x)], 'utf-8'), 1) | |
p = document.add_paragraph() | |
p.add_run(authors).italic = True | |
# p.add_run('\n') | |
# p.add_run(organisations) | |
document.add_paragraph(organisations) | |
document.add_page_break() | |
document.save('program.docx') | |
if __name__ == "__main__": | |
_main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment