def pdfgen(relevant_extracts, sector, keywords):
today = datetime.datetime.today()
today.replace(second=0, microsecond=0)
outputdir = join('..', 'output')
if not exists(outputdir):
mkdir(outputdir)
chdir(outputdir)
doc = SimpleDocTemplate('%s_%s.pdf' % (sector, today.strftime("%Y-%m-%d_%H.%M")))
template = PageTemplate('normal', [Frame(2.5*cm, 2.5*cm, 15*cm, 25*cm, id='F1')])
doc.addPageTemplates(template)
Story = [Spacer(1,0.5*inch)]
styleSheet=getSampleStyleSheet()
style = styleSheet['BodyText']
title = Paragraph('<para align=center><b>%s Industry Earnings Call Transcripts Report</b></para>' % sector,
style)
Story.append(title)
subtitle = Paragraph('<para align=center>Keywords: %s</para>' % ", ".join(keywords),
style)
Story.append(subtitle)
Story.append(Spacer(1,0.5*inch))
for extract in relevant_extracts:
Story.append(Paragraph("From %s" % extract["title"], h1))
Story.append(Paragraph("Published on %s at %s" % (extract["date"], extract["time"]), h1))
text = Preformatted(extract["bodyContent"].encode('utf8'), style, maxLineLength=100)
Story.append(text)
Story.append(Spacer(1,0.2*inch))
doc.build(Story)
评论列表
文章目录