from weasyprint import HTML import os import json def makeReport(name, links, preds, instnames, age): #sort links = sorted(links) preds = sorted(preds) instnames = sorted(instnames) name = name.strip() name = name.replace('%20', '-') with open('./report/template.html', 'r') as f: template_data = f.read() template_data = template_data.replace('{{INPUT_NAME}}', name) template_data = template_data.replace('{{ES_AGE}}', str(age)) links_str = "" for l in links: links_str += "
  • " links_str += '{0}'.format(l) links_str += "
  • " template_data = template_data.replace('{{SOCIAL_URLS}}', links_str) preds_str = "" for p in preds: preds_str += "
  • " preds_str += p preds_str += "
  • " template_data = template_data.replace('{{GOOGLE_PREDS}}', preds_str) insta_str = "" for i in instnames: insta_str += "
  • " insta_str += 'https://instagram.com/{0}'.format(i) insta_str += "
  • " template_data = template_data.replace('{{INSTA_PROFILES}}', insta_str) with open('tmp.html', 'w') as t: t.write(template_data) doc = HTML('tmp.html') doc.write_pdf('{0}_Report.pdf'.format(name)) os.remove('tmp.html') def makeJSONReport(name, links, preds, instnames, age, fn): data = {} links = sorted(links) preds = sorted(preds) instnames = sorted(instnames) name = name.strip() name = name.replace('%20', '-') data['name'] = name data['age'] = str(age) data['social_urls'] = links data['google_predictions'] = preds data['instagram_names'] = instnames with open(fn, 'w') as o: json.dump(data, o)