-
Notifications
You must be signed in to change notification settings - Fork 0
/
csv2labelfile.py
53 lines (37 loc) · 1.32 KB
/
csv2labelfile.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
AST, 06.11.2018
Format of CSV input:
| Datum | Was? | Wo gekaut? | Wert? | Als Etikett drucken? |
|---|---|---|---|---|
| 21.10.2015 | Raspberry Pi 2 | XYZ | 19.10 | 75,99 € | 1 |
"""
import os
import sys
import csv
from codecs import open
MAXTEXTLENGTH = 52
with open('Inventar-Elektronikbauteile - Tabellenblatt1.csv', 'r', 'utf8') as fin:
with open('names.dat', 'w', 'utf8') as fout:
reader = csv.reader(fin)
for i,row in enumerate(reader):
if i==0:
## skip header line
continue
try:
date,item,seller,amount,price,total_price,shipping_costs,toprint = row
except ValueError as ex:
print("Error in line %d: %s, [%s]" % (i, ex, row))
sys.exit(1)
if not toprint:
## skip items not explicitly marked as to be printed
continue
## trim long titles
if len(item) > MAXTEXTLENGTH:
item = "%s..." % item[:MAXTEXTLENGTH]
fout.write("\\textbf{%s}\n" % item)
if seller:
fout.write("%s\n" % seller)
fout.write("\\small{%s, %s x %s}\n" % (date, amount, price))
fout.write('\n'*2)