-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadTicketLeoExport.py
More file actions
84 lines (66 loc) · 2.71 KB
/
loadTicketLeoExport.py
File metadata and controls
84 lines (66 loc) · 2.71 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import csv
import re
import pandas as pd
class loadTicketLeoExport:
def __init__(self):
self.exportAvailable = False
def openExport(self, path):
try:
# get the date from the excel sheet
# load the file with pandas to only extract the first row
df = pd.read_excel(path, sheet_name=0).columns[0]
self.date = str(re.findall("\d{2}.\d{2}.\d{4}", df)[0])
# load excle file. Cut of the first two lines, because our indexes are in the third line
df = pd.read_excel(path, sheet_name=0, skiprows=2)
self.customers = []
# interate the df and create the customers
for idx, row in df.iterrows():
if pd.isna(row["Nachname"]): # if there is no surname skip the entry
continue
# check if a prename is present. If not only use the surename
if pd.isna(row["Vorname"]):
name = row["Nachname"]
else:
name = row["Vorname"] + " " + row["Nachname"]
# create the customer as a dictionary for easy access to all fields
customer = {}
customer["place"] = row["Sitznummer"]
customer["name"] = name
customer["sortkey"] = row["Nachname"]
self.customers.append(customer)
# sort the list by name to get better sorting when creating print tickets
# here is determined in which order the tickets will be printed later. So sort carefully
self.customers = sorted(self.customers, key=lambda x: x["sortkey"])
self.exportAvailable = (
True # if the parsing was successful the export can be used
)
except Exception as e:
# if something went wrong mark as not available
print(type(e), e)
self.exportAvailable = False
def getDate(self):
if self.exportAvailable:
return self.date
else:
return "00.00."
def getTicketCnt(self):
if self.exportAvailable:
return len(self.customers)
else:
return 0
def getCustomer(self, index):
if self.exportAvailable:
try:
return self.customers[index]
except IndexError as e:
print("Customer selection out of range")
return None
else:
return ("", 0)
if __name__ == "__main__":
import os
sample_path = os.path.join(os.getcwd(), "Samples", "Das-Klassentreffen.xlsx")
loader = loadTicketLeoExport()
loader.openExport(sample_path)
print(loader.getTicketCnt())
print(loader.getDate())