Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import sys
- import xml.etree.ElementTree as ET
- import pandas as pd
- import weasyprint
- html = '''
- <html>
- <head></head>
- <style>
- thead {{
- background-color: #70ad46;
- color: #ffffff;
- font-weight: bold;
- }}
- table {{
- border-collapse: collapse;
- font-size: 14px;
- }}
- table th:nth-child(3),
- table td:nth-child(3),
- table th:nth-child(5),
- table td:nth-child(5),
- table th:nth-child(6),
- table td:nth-child(6),
- table th:nth-child(7),
- table td:nth-child(7) {{
- font-size: 12px;
- }}
- table td, table th {{
- border: 1px #bcd9a9 solid;
- padding: 4px;
- }}
- tbody tr:nth-child(odd) {{
- background-color: #e2efdb;
- }}
- </style>
- <body>
- {table}
- </body>
- </html>
- '''
- rows = []
- cols = ['docid', 'ordner', 'hauptordner', 'bemerkung', 'status', 'revision', 'dokumentenart', 'Datum', 'bu-monat', 'bu-jahr', 'firma']
- print_cols = ['docid', 'hauptordner', 'bemerkung', 'dokumentenart', 'bu-monat', 'bu-jahr', 'firma']
- tree = ET.parse('export.xml')
- root = tree.getroot()
- for node in root:
- if not node.attrib.get('docid'):
- continue
- rows.append({
- 'docid': node.attrib.get('docid'),
- 'ordner': node.find('.//ordner').text,
- 'hauptordner': node.find('.//hauptordner').text,
- 'bemerkung': node.find('.//bemerkung').text,
- 'status': node.find('.//status').text,
- 'revision': node.find('.//revision').text,
- 'dokumentenart': node.find('.//dokumentenart').text,
- 'Datum': node.find('.//datum').text,
- 'bu-monat': node.find('.//bu-monat').text,
- 'bu-jahr': node.find('.//bu-jahr').text,
- 'firma': node.find('.//firma').text})
- file_name = 'export-' + rows[0]['firma'] + '-' + rows[0]['bu-jahr'] + rows[0]['bu-monat']
- df = pd.DataFrame(rows, columns=cols)
- df.index.name = 'No'
- df.to_csv(file_name + '.csv')
- with open(file_name + '.html', 'w') as f:
- f.write(html.format(table=df.to_html(columns=print_cols, index_names=False)))
- weasyprint.HTML(file_name + '.html').write_pdf(file_name + '.pdf')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement