omgy commited on
Commit
e2eaeaf
·
verified ·
1 Parent(s): 2440317

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +10 -23
main.py CHANGED
@@ -868,22 +868,6 @@ def build_report_html(data: dict, report_id: str, language_mode: str) -> str:
868
  /* Content wrapper */
869
  .content{{padding:16px;max-width:720px;margin:0 auto}}
870
 
871
- /* Offline badge */
872
- .offline-badge{{
873
- background:#E8F5E9;
874
- border:1px solid #A5D6A7;
875
- color:#1B5E20;
876
- padding:10px 16px;
877
- border-radius:12px;
878
- font-size:13px;
879
- text-align:center;
880
- margin-bottom:14px;
881
- display:flex;
882
- align-items:center;
883
- justify-content:center;
884
- gap:8px;
885
- }}
886
-
887
  /* Print button */
888
  .btn-print{{
889
  display:block;
@@ -1003,7 +987,7 @@ def build_report_html(data: dict, report_id: str, language_mode: str) -> str:
1003
  /* Print styles */
1004
  @media print{{
1005
  body{{background:white;font-size:13px}}
1006
- .btn-print,.offline-badge{{display:none}}
1007
  .header{{background:#2E7D32 !important;-webkit-print-color-adjust:exact}}
1008
  .card{{box-shadow:none;border:1px solid #e0e0e0;break-inside:avoid}}
1009
  .content{{padding:0}}
@@ -1033,10 +1017,6 @@ def build_report_html(data: dict, report_id: str, language_mode: str) -> str:
1033
 
1034
  <div class="content">
1035
 
1036
- <div class="offline-badge">
1037
- ✅ This page works completely offline — save it!
1038
- </div>
1039
-
1040
  <button class="btn-print" onclick="window.print()">
1041
  🖨️ Save as PDF / Print
1042
  </button>
@@ -1068,7 +1048,10 @@ def save_report(report_id: str, html: str):
1068
  print(f"[REPORT] Saved → {os.path.abspath(path)} ({len(html)} bytes)")
1069
 
1070
  def fix_base_url(base_url: str) -> str:
1071
- url = base_url.rstrip("/").replace(" ", "-")
 
 
 
1072
  if "hf.space" in url and url.startswith("http://"):
1073
  url = "https://" + url[7:]
1074
  return url
@@ -1173,7 +1156,11 @@ async def sms_webhook(request: Request):
1173
  remember_bot_reply(reply_text)
1174
  enqueue_reply(phone, reply_text, language_mode)
1175
 
1176
- base_url = str(request.base_url).rstrip("/")
 
 
 
 
1177
  report_id = generate_report_id(phone, message)
1178
 
1179
  threading.Thread(
 
868
  /* Content wrapper */
869
  .content{{padding:16px;max-width:720px;margin:0 auto}}
870
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
871
  /* Print button */
872
  .btn-print{{
873
  display:block;
 
987
  /* Print styles */
988
  @media print{{
989
  body{{background:white;font-size:13px}}
990
+ .btn-print{{display:none}}
991
  .header{{background:#2E7D32 !important;-webkit-print-color-adjust:exact}}
992
  .card{{box-shadow:none;border:1px solid #e0e0e0;break-inside:avoid}}
993
  .content{{padding:0}}
 
1017
 
1018
  <div class="content">
1019
 
 
 
 
 
1020
  <button class="btn-print" onclick="window.print()">
1021
  🖨️ Save as PDF / Print
1022
  </button>
 
1048
  print(f"[REPORT] Saved → {os.path.abspath(path)} ({len(html)} bytes)")
1049
 
1050
  def fix_base_url(base_url: str) -> str:
1051
+ """Final safety net — cleans any remaining URL issues"""
1052
+ url = base_url.strip().rstrip("/")
1053
+ url = url.replace(" ", "-") # spaces in HF space name
1054
+ url = re.sub(r"([^:])//+", r"\1/", url) # double slashes
1055
  if "hf.space" in url and url.startswith("http://"):
1056
  url = "https://" + url[7:]
1057
  return url
 
1156
  remember_bot_reply(reply_text)
1157
  enqueue_reply(phone, reply_text, language_mode)
1158
 
1159
+ # Fix HF Spaces URL — request.base_url returns "http://omgy sms.hf.space/"
1160
+ # with a literal space in the space name. Fix it immediately at capture.
1161
+ base_url = str(request.base_url).rstrip("/").replace(" ", "-")
1162
+ if "hf.space" in base_url and base_url.startswith("http://"):
1163
+ base_url = "https://" + base_url[7:]
1164
  report_id = generate_report_id(phone, message)
1165
 
1166
  threading.Thread(