Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -45,7 +45,14 @@ def format_zip(zip_code) -> str:
|
|
| 45 |
if not z:
|
| 46 |
return ""
|
| 47 |
return z.zfill(5)[:5]
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
def flow_address_lines(lines, maxlen=35, maxlines=3):
|
| 50 |
"""Word-aware wrap into up to 3 lines, hard-splitting very long tokens."""
|
| 51 |
tokens = []
|
|
@@ -141,7 +148,7 @@ def build_ups_batch_no_header(file):
|
|
| 141 |
out["State/Prov/Other"] = to_str_series(df, "State")
|
| 142 |
out["Postal Code"] = zip_series(df, "ZipCode")
|
| 143 |
out["Telephone"] = to_str_series(df, "Phone Number")
|
| 144 |
-
out["Consignee Email"] = to_str_series(df, "Email")
|
| 145 |
|
| 146 |
# Dimensions / weight
|
| 147 |
out["Weight"] = to_num_str_series(df, "Weight")
|
|
@@ -166,7 +173,7 @@ def build_ups_batch_no_header(file):
|
|
| 166 |
out["Reference 3"] = to_num_str_series(df, "Customer Reference")
|
| 167 |
|
| 168 |
# QV Notification flags/addresses
|
| 169 |
-
out["QV Notif 1-Addr"] = to_str_series(df, "Email") # recipient email
|
| 170 |
out["QV Notif 1-Ship"] = "1"
|
| 171 |
out["QV Notif 1-Excp"] = "1"
|
| 172 |
out["QV Notif 1-Delv"] = "1"
|
|
|
|
| 45 |
if not z:
|
| 46 |
return ""
|
| 47 |
return z.zfill(5)[:5]
|
| 48 |
+
|
| 49 |
+
# Validate email format (must contain '@' and end with .domain)
|
| 50 |
+
def validate_email(s):
|
| 51 |
+
s = clean_text(s)
|
| 52 |
+
if not s or not re.match(r"^[^@]+@[^@]+\.[a-zA-Z]{2,}$", s):
|
| 53 |
+
return "" # blank out invalid emails
|
| 54 |
+
return s
|
| 55 |
+
|
| 56 |
def flow_address_lines(lines, maxlen=35, maxlines=3):
|
| 57 |
"""Word-aware wrap into up to 3 lines, hard-splitting very long tokens."""
|
| 58 |
tokens = []
|
|
|
|
| 148 |
out["State/Prov/Other"] = to_str_series(df, "State")
|
| 149 |
out["Postal Code"] = zip_series(df, "ZipCode")
|
| 150 |
out["Telephone"] = to_str_series(df, "Phone Number")
|
| 151 |
+
out["Consignee Email"] = to_str_series(df, "Email").apply(validate_email)
|
| 152 |
|
| 153 |
# Dimensions / weight
|
| 154 |
out["Weight"] = to_num_str_series(df, "Weight")
|
|
|
|
| 173 |
out["Reference 3"] = to_num_str_series(df, "Customer Reference")
|
| 174 |
|
| 175 |
# QV Notification flags/addresses
|
| 176 |
+
out["QV Notif 1-Addr"] = to_str_series(df, "Email").apply(validate_email) # recipient email
|
| 177 |
out["QV Notif 1-Ship"] = "1"
|
| 178 |
out["QV Notif 1-Excp"] = "1"
|
| 179 |
out["QV Notif 1-Delv"] = "1"
|