remix867 commited on
Commit
c61aff8
·
1 Parent(s): a9eca1a

Fixed Formatting issues with output JSON

Browse files
Files changed (1) hide show
  1. app.py +17 -12
app.py CHANGED
@@ -24,27 +24,32 @@ def create_excel_file():
24
  def read_excel_file(uploaded_file, sheet_name):
25
  return pd.read_excel(uploaded_file, sheet_name=sheet_name)
26
 
 
 
 
 
 
 
 
27
  def generate_output(df, check_pointer, sheet_name):
28
  output_lines = []
29
  for _, row in df.iterrows():
30
- pipedrive_value = row["pipedrive"] if pd.notna(row["pipedrive"]) else ""
31
- bexio_value = row["bexio" if sheet_name != "Status" else "bexio_contact"] if pd.notna(row["bexio" if sheet_name != "Status" else "bexio_contact"]) else ""
32
- comment_value = row["comment"] if pd.notna(row["comment"]) else ""
33
 
34
- # Handle klicktipp_value differently for Salutation sheet
35
  if sheet_name != "Salutation" and "klicktipp" in df.columns:
36
- klicktipp_value = row["klicktipp"] if pd.notna(row["klicktipp"]) else ""
37
  else:
38
  klicktipp_value = ""
39
 
40
  if sheet_name == "Status":
41
  output_line = f'{{{{if(contains({check_pointer}; {pipedrive_value}); ",{{""comment"": ""{comment_value}"",""bexio_contact"": ""{bexio_value}"",""klicktipp_id"": ""{klicktipp_value}""}}" )}}}}'
42
  elif sheet_name == "Salutation":
43
- output_line = f'{{{{if({check_pointer} = "{pipedrive_value}"; "{{""comment"": ""{comment_value}"",""bexio_id"": ""{bexio_value}""}}")}}}}'
44
  else:
45
- output_line = f'{{{{if({check_pointer} = "{pipedrive_value}"; "{{""comment"": ""{comment_value}"",""bexio_id"": ""{bexio_value}"",""klicktipp_id"": ""{klicktipp_value}""}}")}}}}'
46
  output_lines.append(output_line)
47
-
48
  return "\n".join(output_lines)
49
 
50
  def main():
@@ -70,17 +75,17 @@ def main():
70
  sheets = ["Status", "Teacher", "Location", "Billing", "Salutation"]
71
  check_pointers = [check_pointer_status, check_pointer_teacher, check_pointer_location, check_pointer_billing, check_pointer_salutation]
72
 
73
- combined_results = []
74
  for sheet, check_pointer in zip(sheets, check_pointers):
75
  df = read_excel_file(uploaded_file, sheet)
76
  result = generate_output(df, check_pointer, sheet)
77
- combined_results.append(result)
78
 
79
  final_output = f'''
80
  {{
81
  "data": [
82
- {{"comment": "Pipedrive","bexio_id": "88","klicktipp_id": "11093548"}},
83
- {",".join(combined_results)}
84
  ]
85
  }}
86
  '''
 
24
  def read_excel_file(uploaded_file, sheet_name):
25
  return pd.read_excel(uploaded_file, sheet_name=sheet_name)
26
 
27
+ def format_value(value):
28
+ if pd.notna(value):
29
+ if isinstance(value, (int, float)):
30
+ return f"{value:.0f}"
31
+ return str(value)
32
+ return ""
33
+
34
  def generate_output(df, check_pointer, sheet_name):
35
  output_lines = []
36
  for _, row in df.iterrows():
37
+ pipedrive_value = format_value(row["pipedrive"])
38
+ bexio_value = format_value(row["bexio" if sheet_name != "Status" else "bexio_contact"])
39
+ comment_value = format_value(row["comment"])
40
 
 
41
  if sheet_name != "Salutation" and "klicktipp" in df.columns:
42
+ klicktipp_value = format_value(row["klicktipp"])
43
  else:
44
  klicktipp_value = ""
45
 
46
  if sheet_name == "Status":
47
  output_line = f'{{{{if(contains({check_pointer}; {pipedrive_value}); ",{{""comment"": ""{comment_value}"",""bexio_contact"": ""{bexio_value}"",""klicktipp_id"": ""{klicktipp_value}""}}" )}}}}'
48
  elif sheet_name == "Salutation":
49
+ output_line = f'{{{{if({check_pointer} = "{pipedrive_value}"; ",{{""comment"": ""{comment_value}"",""bexio_salutation"": ""{bexio_value}""}}")}}}}'
50
  else:
51
+ output_line = f'{{{{if({check_pointer} = "{pipedrive_value}"; ",{{""comment"": ""{comment_value}"",""bexio_id"": ""{bexio_value}"",""klicktipp_id"": ""{klicktipp_value}""}}")}}}}'
52
  output_lines.append(output_line)
 
53
  return "\n".join(output_lines)
54
 
55
  def main():
 
75
  sheets = ["Status", "Teacher", "Location", "Billing", "Salutation"]
76
  check_pointers = [check_pointer_status, check_pointer_teacher, check_pointer_location, check_pointer_billing, check_pointer_salutation]
77
 
78
+ all_output_lines = []
79
  for sheet, check_pointer in zip(sheets, check_pointers):
80
  df = read_excel_file(uploaded_file, sheet)
81
  result = generate_output(df, check_pointer, sheet)
82
+ all_output_lines.extend(result) # Extend the list instead of appending
83
 
84
  final_output = f'''
85
  {{
86
  "data": [
87
+ {{"comment": "Pipedrive","bexio_id": "88","klicktipp_id": "11093548"}}
88
+ {"".join(all_output_lines)}
89
  ]
90
  }}
91
  '''