-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReportGenerator.py
77 lines (69 loc) · 3.24 KB
/
ReportGenerator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import markdown
import codecs
import requests
#import pypandoc
#from md2pdf.core import md2pdf
def markdown_generator(dictreport, query, nResults):
#Header information
title = query
sep = '----- \n'
H1 = '> - Showing top ('+str(nResults)+') relevant results from PubMed Central \n'
H2 = '> - Articles dating from range 2000-2010 \n'
H3 = '> - Most commonly referenced words in abstract: list here \n'
header = '# '+title+' (Summary Report) \n'
with open('Report.md', 'w', encoding="utf-8") as f:
f.write(header+sep+H1+H2+H3+'\n')
for PMC in dictreport:
ref = dictreport[PMC]
article_title = sep+'\n'+ '### '+ref['Title']+'\n \n'
authors = '* Author(s): '+', '.join(ref['Authors'])+'\n'
date = '* Date: '+ref['Date']+'\n'
DOI = '* DOI: '+ref['DOI']+'\n'
abstract = '+ Abstract: '+ref['Abstract']+'\n'
f.write(article_title+authors+date+DOI+'\n'+abstract)
def markdown_generator_with_images(dictreport, query, nResults):
#Header information
title = query
sep = '----- \n'
H1 = '> - Showing top ('+str(nResults)+') most relevant results from PubMed Central \n'
H2 = '> - Articles dating from range 2000-2010 \n'
H3 = '> - Most commonly referenced words in abstract: list here \n'
header = '# '+title+' (Summary Report) \n'
with open('Report.md', 'w', encoding="utf-8") as f:
f.write(header+sep+H1+H2+H3+'\n')
for PMC in dictreport:
ref = dictreport[PMC]
article_title = sep+'\n'+ '### '+ref['Title']+'\n \n'
authors = '* Author(s): '+', '.join(ref['Authors'])+'\n'
date = '* Date: '+ref['Date']+'\n'
DOI = '* DOI: '+ref['DOI']+'\n'
abstract = '+ Abstract: '+ref['Abstract']+'\n'
images = '\n'.join(['![alt text]('+i+')' for i in ref['Images']])+'\n'
f.write(article_title+authors+date+DOI+'\n'+abstract+images)
def html_generator(dictreport, query, nResults):
#Header information
title = query
sep = '----- \n'
H1 = '> - Showing top ('+str(nResults)+') most relevant results from PubMed Central \n'
H2 = '> - Articles dating from range 2000-2010 \n'
H3 = '> - Most commonly referenced words in abstract: list here \n'
header = '# '+title+' (Summary Report) \n'
with open('', 'w', encoding="utf-8") as f:
f.write(header+sep+H1+H2+H3+'\n')
for PMC in dictreport:
ref = dictreport[PMC]
article_title = sep+'\n'+ '### '+ref['Title']+'\n \n'
authors = '* Author(s): '+', '.join(ref['Authors'])+'\n'
date = '* Date: '+ref['Date']+'\n'
DOI = '* DOI: '+ref['DOI']+'\n'
abstract = '+ Abstract: '+ref['Abstract']+'\n'
images = '\n'.join(['![alt text]('+i+')' for i in ref['Images']])+'\n'
f.write(article_title+authors+date+DOI+'\n'+abstract+images)
def markdown_to_html():
input_file = codecs.open("Report.md", mode="r", encoding="utf-8")
text = input_file.read()
html = markdown.markdown(text)
output_file = codecs.open("templates/report.html", "w",
encoding="utf-8",
errors="xmlcharrefreplace")
output_file.write(html)