Update app.py
Browse files
app.py
CHANGED
@@ -61,10 +61,16 @@ def process_file(file):
|
|
61 |
if "Shipping Province" in df.columns:
|
62 |
output_df["Province/State"] = df["Shipping Province"]
|
63 |
|
64 |
-
# 6. ZipCode (pad 4-digit US zips
|
65 |
if "Shipping ZIP" in df.columns:
|
66 |
-
zip_raw = df["Shipping ZIP"].astype(str).str.
|
67 |
-
output_df["
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
# 7. CountryCode
|
70 |
if "Shipping Country Code" in df.columns:
|
@@ -110,18 +116,8 @@ def process_file(file):
|
|
110 |
today_hk = datetime.now(hk_tz).strftime("%y%m%d")
|
111 |
output_file_name = f"yunexpress {today_hk}.xlsx"
|
112 |
|
113 |
-
#
|
114 |
-
|
115 |
-
output_df.to_excel(writer, index=False, sheet_name='YunExpress')
|
116 |
-
workbook = writer.book
|
117 |
-
worksheet = writer.sheets['YunExpress']
|
118 |
-
|
119 |
-
# Find the zero-based column index of "ZipCode"
|
120 |
-
zip_col_idx = output_df.columns.get_loc("ZipCode")
|
121 |
-
# Create a 5-digit text format
|
122 |
-
fmt_text = workbook.add_format({'num_format': '00000', 'align': 'left'})
|
123 |
-
# Apply to the entire column
|
124 |
-
worksheet.set_column(zip_col_idx, zip_col_idx, 8, fmt_text)
|
125 |
|
126 |
return output_df, output_file_name
|
127 |
|
@@ -156,4 +152,4 @@ with gr.Blocks(title="Shipping - YunExpress") as demo:
|
|
156 |
"""
|
157 |
)
|
158 |
|
159 |
-
demo.launch()
|
|
|
61 |
if "Shipping Province" in df.columns:
|
62 |
output_df["Province/State"] = df["Shipping Province"]
|
63 |
|
64 |
+
# 6. ZipCode (pad 4-digit US zips with a leading zero + apostrophe for text)
|
65 |
if "Shipping ZIP" in df.columns:
|
66 |
+
zip_raw = df["Shipping ZIP"].astype(str).str.strip()
|
67 |
+
mask_us = output_df["CountryCode"] == "US"
|
68 |
+
mask_4 = zip_raw.str.len() == 4
|
69 |
+
# pad to 5 digits
|
70 |
+
zip_padded = zip_raw.where(~(mask_us & mask_4), "0" + zip_raw)
|
71 |
+
# prefix apostrophe so Excel treats it as text and preserves leading zero
|
72 |
+
zip_final = zip_padded.where(~(mask_us & mask_4), "'" + zip_padded)
|
73 |
+
output_df["ZipCode"] = zip_final
|
74 |
|
75 |
# 7. CountryCode
|
76 |
if "Shipping Country Code" in df.columns:
|
|
|
116 |
today_hk = datetime.now(hk_tz).strftime("%y%m%d")
|
117 |
output_file_name = f"yunexpress {today_hk}.xlsx"
|
118 |
|
119 |
+
# Save to Excel
|
120 |
+
output_df.to_excel(output_file_name, index=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
|
122 |
return output_df, output_file_name
|
123 |
|
|
|
152 |
"""
|
153 |
)
|
154 |
|
155 |
+
demo.launch()
|