Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement