buzzbandit commited on
Commit
08aea85
Β·
verified Β·
1 Parent(s): 4703376

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -20
app.py CHANGED
@@ -338,16 +338,16 @@ def run_query(query_text, category, country, capacity, refresh):
338
  return df, ts, gr.update(choices=[""] + live_categories)
339
 
340
  # ---------------- Gradio UI ----------------
341
- with gr.Blocks(title="🧳 Torn Inventory Viewer") as iface:
342
- gr.Markdown("## 🧳 Torn Inventory Viewer")
343
- gr.Markdown("_Search Torn YATA travel stocks β€” timestamps shown in your local timezone._")
344
 
345
  # Convenience buttons
346
  with gr.Row():
347
  btn_short = gr.Button("🌸 Flushies (short haul)")
348
  btn_medium = gr.Button("🧸 Flushies (medium haul)")
349
  btn_long = gr.Button("🎁 Flushies (long haul)")
350
- btn_xanax = gr.Button("πŸ’Š Xanax")
351
  btn_temps = gr.Button("🧨 Temps")
352
 
353
  query_box = gr.Textbox(label="Search (semantic, e.g. 'flowers in England')")
@@ -392,24 +392,39 @@ with gr.Blocks(title="🧳 Torn Inventory Viewer") as iface:
392
  # --- JS: convert all UTC ISO timestamps to browser's local time ---
393
  gr.HTML("""
394
  <script>
395
- (function(){
396
- function convertTimesToLocal(){
397
- const elems = document.querySelectorAll("td, textarea, input");
398
- const fmt = new Intl.DateTimeFormat([], {year:"numeric", month:"2-digit", day:"2-digit",
399
- hour:"2-digit", minute:"2-digit", second:"2-digit"});
400
- elems.forEach(el=>{
401
- const text = el.value || el.textContent;
402
- if (text && /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$/.test(text.trim())){
403
- try{
404
- const dt = new Date(text.trim());
405
- const local = fmt.format(dt);
406
- if (el.value !== undefined) el.value = local;
407
- else el.textContent = local;
408
- }catch{}
409
- }
410
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
411
  }
412
- setInterval(convertTimesToLocal, 1000);
 
 
413
  })();
414
  </script>
415
  """)
 
338
  return df, ts, gr.update(choices=[""] + live_categories)
339
 
340
  # ---------------- Gradio UI ----------------
341
+ with gr.Blocks(title="🧳 Torn Foreign Stocks") as iface:
342
+ gr.Markdown("## 🧳 Torn Foreign Stocks")
343
+ gr.Markdown("_Search YATA's Foreign Stocks_")
344
 
345
  # Convenience buttons
346
  with gr.Row():
347
  btn_short = gr.Button("🌸 Flushies (short haul)")
348
  btn_medium = gr.Button("🧸 Flushies (medium haul)")
349
  btn_long = gr.Button("🎁 Flushies (long haul)")
350
+ btn_xanax = gr.Button("πŸ’Š Xanax (SA)")
351
  btn_temps = gr.Button("🧨 Temps")
352
 
353
  query_box = gr.Textbox(label="Search (semantic, e.g. 'flowers in England')")
 
392
  # --- JS: convert all UTC ISO timestamps to browser's local time ---
393
  gr.HTML("""
394
  <script>
395
+ (function () {
396
+ // Convert any ISO-UTC (…Z) timestamp found in component text/values to the browser's local time
397
+ function convertTimesToLocal() {
398
+ const isoRe = /\\b\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z\\b/g;
399
+ const fmt = new Intl.DateTimeFormat([], {
400
+ year: "numeric", month: "2-digit", day: "2-digit",
401
+ hour: "2-digit", minute: "2-digit", second: "2-digit"
 
 
 
 
 
 
 
 
402
  });
403
+
404
+ function processRoot(root) {
405
+ const elems = root.querySelectorAll("td, textarea, input, div, span");
406
+ elems.forEach(el => {
407
+ // Prefer .value for inputs/textareas; otherwise use textContent
408
+ if (typeof el.value === "string") {
409
+ const v = el.value;
410
+ if (isoRe.test(v)) {
411
+ el.value = v.replace(isoRe, m => fmt.format(new Date(m)));
412
+ }
413
+ } else if (el.textContent && isoRe.test(el.textContent)) {
414
+ el.textContent = el.textContent.replace(isoRe, m => fmt.format(new Date(m)));
415
+ }
416
+ });
417
+ }
418
+
419
+ // Handle regular DOM and Gradio's shadow DOM
420
+ const roots = [document];
421
+ const app = document.querySelector("gradio-app");
422
+ if (app && app.shadowRoot) roots.push(app.shadowRoot);
423
+ roots.forEach(processRoot);
424
  }
425
+
426
+ // Run periodically to catch re-renders
427
+ setInterval(convertTimesToLocal, 800);
428
  })();
429
  </script>
430
  """)