diff --git a/.gitignore b/.gitignore index 3bf7f81..919b269 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ tests/.excluded_sites # MacOS Folder Metadata File .DS_Store +/reports/ diff --git a/maigret/report.py b/maigret/report.py index 75e7769..6211995 100644 --- a/maigret/report.py +++ b/maigret/report.py @@ -3,9 +3,10 @@ from datetime import datetime import logging import os import xmind +import io +from xhtml2pdf import pisa from jinja2 import Template -from weasyprint import HTML, CSS import pycountry @@ -177,8 +178,20 @@ def save_html_pdf_report(username_results: list, filename:str=None, filenamepdf: supposed_data=filtered_supposed_data, generated_at=datetime.now().strftime('%Y-%m-%d %H:%M:%S'), ) - HTML(string=filled_template).write_pdf(filenamepdf, stylesheets=[CSS(filename=os.path.join(os.path.dirname(os.path.realpath(__file__)), - "resources/simple_report_pdf.css"))]) + csstext = "" + with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), + "resources/simple_report_pdf.css"), "r") as cssfile: + cssline = cssfile.readline() + csstext += cssline + while cssline: + cssline = cssfile.readline() + csstext += cssline + cssfile.close() + + pdffile = open(filenamepdf, "w+b") + pisa.pisaDocument(io.StringIO(filled_template), dest=pdffile, default_css=csstext) + pdffile.close() + def save_csv_report_to_file(username: str, results: dict, csvfile): print(results) diff --git a/maigret/resources/simple_report_pdf.css b/maigret/resources/simple_report_pdf.css index 291df93..9fda1b4 100644 --- a/maigret/resources/simple_report_pdf.css +++ b/maigret/resources/simple_report_pdf.css @@ -1,123 +1,41 @@ -/* -------------------------------------------------------------- - - typography.css - * Sets up some sensible default typography. - --------------------------------------------------------------- */ - -/* Default font settings. - The font-size percentage is of 16px. (0.75 * 16px = 12px) */ -html { font-size:100.01%; } -body { - font-size: 75%; - color: #222; - background: #fff; - font-family: "Helvetica Neue", Arial, Helvetica, sans-serif; +h2 { + font-size: 30px; + width: 100%; + display:block; +} +h3 { + font-size: 25px; + width: 100%; + display:block; +} +h4 { + font-size: 20px; + width: 100%; + display:block; +} +p { + margin: 0 0 5px; + display: block; } -/* Headings --------------------------------------------------------------- */ - -h1,h2,h3,h4,h5,h6 { font-weight: normal; color: #111; } - -h1 { font-size: 3em; line-height: 1; margin-bottom: 0.5em; } -h2 { font-size: 2em; margin-bottom: 0.75em; } -h3 { font-size: 1.5em; line-height: 1; margin-bottom: 1em; } -h4 { font-size: 1.2em; line-height: 1.25; margin-bottom: 1.25em; } -h5 { font-size: 1em; font-weight: bold; margin-bottom: 1.5em; } -h6 { font-size: 1em; font-weight: bold; } - -h1 img, h2 img, h3 img, -h4 img, h5 img, h6 img { - margin: 0; +table { + margin-bottom: 10px; + width:100%; +} +th { + font-weight: bold; +} +th,td,caption { + padding: 4px 10px 4px 5px; +} +table tr:nth-child(even) td, +table tr.even td { + background-color: #e5ecf9; } - -/* Text elements --------------------------------------------------------------- */ - -p { margin: 0 0 1.5em; } -/* - These can be used to pull an image at the start of a paragraph, so - that the text flows around it (usage:
Text
{{ k }}: {{ v }} -
+ {% endfor %} {% if countries_tuple_list %} - +Geo: {% for k, v in countries_tuple_list %}{{ k }} ({{ v }}){{ ", " if not loop.last }}{% endfor %} -
+ {% endif %}{% if interests_tuple_list %} - +Interests: {% for k, v in interests_tuple_list %}{{ k }} ({{ v }}){{ ", " if not loop.last }}{% endfor %} -
+ {% endif %}{% if first_seen %} - +First seen: {{ first_seen }} -
+ {% endif %}{{ brief }} -
+
- - {{ v.url_user }} -
+
+
+ |
+ + |
+
+
+ + {{ k }} ++ {% if v.status.tags %} +Tags: {{ v.status.tags | join(', ') }}
+ {% endif %}
+ + {{ v.url_user }} + + |
+