Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # coding: utf8
  3.  
  4. import csv
  5. import datetime
  6.  
  7. from orderedset import OrderedSet
  8. from docx import Document
  9.  
  10.  
  11. def _get_formated_date(time_string):
  12. ret = datetime.datetime.strptime(time_string, '%Y-%m-%d %H:%M')
  13. ret = ret.strftime('%A, %d/%b/%Y')
  14. return ret
  15.  
  16. def _get_formated_time(time_string):
  17. ret = datetime.datetime.strptime(time_string, '%Y-%m-%d %H:%M')
  18. ret = ret.time()
  19. ret = ret.strftime("%I:%M%p").lower()
  20. return ret
  21.  
  22. def _main():
  23. document = Document()
  24.  
  25. with open('programm/ESCoP2017_sessions_2017-07-25_10-54-36.csv', 'rb') as csvfile:
  26. reader = csv.DictReader(csvfile, delimiter=',', quotechar='"')
  27.  
  28. for row in reader:
  29. document.add_heading(unicode(row['session_title'], 'utf-8'), 0)
  30. document.add_paragraph(
  31. 'Time: {}: {} - {}'.format(
  32. _get_formated_date(row['session_start']),
  33. _get_formated_time(row['session_start']),
  34. _get_formated_time(row['session_end']),
  35. )
  36. )
  37.  
  38. document.add_paragraph('Location: {}'.format(unicode(row['session_room'], 'utf-8')))
  39.  
  40.  
  41. for x in xrange(1, 5):
  42. authors = row['p{}_authors'.format(x)]
  43. authors = authors.split(',')
  44. authors = [a.strip() for a in authors]
  45. authors = ', '.join(authors)
  46. authors = unicode(authors, 'utf-8')
  47.  
  48. organisations = row['p{}_organisations'.format(x)].split(';')
  49. organisations = [o.strip() for o in organisations]
  50. organisations = OrderedSet(organisations)
  51. organisations = ', '.join(organisations)
  52. organisations = unicode(organisations, 'utf-8')
  53.  
  54. document.add_heading(unicode(row['p{}_title'.format(x)], 'utf-8'), 1)
  55.  
  56. p = document.add_paragraph()
  57. p.add_run(authors).italic = True
  58. # p.add_run('\n')
  59. # p.add_run(organisations)
  60.  
  61. document.add_paragraph(organisations)
  62.  
  63. document.add_page_break()
  64.  
  65. document.save('program.docx')
  66.  
  67. if __name__ == "__main__":
  68. _main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement