shyameati commited on
Commit
3d04e63
·
1 Parent(s): 5896acb

Validates ticker

Browse files
Files changed (2) hide show
  1. app.py +12 -1
  2. index.html +15 -8
app.py CHANGED
@@ -175,7 +175,18 @@ def check_symbol(symbol: str):
175
 
176
  exists = any(r["symbol"].upper() == symbol for r in ds)
177
 
 
 
 
 
 
 
 
 
 
178
  return {
179
  "symbol": symbol,
180
- "exists": exists
 
181
  }
 
 
175
 
176
  exists = any(r["symbol"].upper() == symbol for r in ds)
177
 
178
+ if not exists:
179
+ logger.warning(f"Symbol not found: {symbol}")
180
+ return {
181
+ "symbol": symbol,
182
+ "exists": False,
183
+ "message": f"Symbol '{symbol}' does not exist in the dataset."
184
+ }
185
+
186
+ logger.info(f"Symbol exists: {symbol}")
187
  return {
188
  "symbol": symbol,
189
+ "exists": True,
190
+ "message": f"Symbol '{symbol}' exists in the dataset."
191
  }
192
+
index.html CHANGED
@@ -23,22 +23,29 @@ async function checkTicker() {
23
  const ticker = document.getElementById("tickerInput").value.trim().toUpperCase();
24
  const resultDiv = document.getElementById("result");
25
 
 
 
26
  if (!ticker) {
27
- resultDiv.innerHTML = "Please enter a ticker.";
28
  return;
29
  }
30
 
31
- const response = await fetch(`/check/${ticker}`);
32
- const data = await response.json();
 
 
 
 
 
 
 
33
 
34
- if (data.exists) {
35
- resultDiv.innerHTML = `<span style="color: green;"> ${ticker} exists in the dataset</span>`;
36
- } else {
37
- resultDiv.innerHTML = `<span style="color: red;">✘ ${ticker} does NOT exist in the dataset</span>`;
38
  }
39
  }
40
  </script>
41
 
42
  </body>
43
  </html>
44
-
 
23
  const ticker = document.getElementById("tickerInput").value.trim().toUpperCase();
24
  const resultDiv = document.getElementById("result");
25
 
26
+ resultDiv.innerHTML = ""; // clear previous result
27
+
28
  if (!ticker) {
29
+ resultDiv.innerHTML = `<span style="color: red;">Please enter a ticker.</span>`;
30
  return;
31
  }
32
 
33
+ try {
34
+ const response = await fetch(`/check/${ticker}`);
35
+ const data = await response.json();
36
+
37
+ if (data.exists) {
38
+ resultDiv.innerHTML = `<span style="color: green;">✔ ${data.message}</span>`;
39
+ } else {
40
+ resultDiv.innerHTML = `<span style="color: red;">✘ ${data.message}</span>`;
41
+ }
42
 
43
+ } catch (err) {
44
+ resultDiv.innerHTML = `<span style="color: red;">Error connecting to server.</span>`;
45
+ console.error("Network error:", err);
 
46
  }
47
  }
48
  </script>
49
 
50
  </body>
51
  </html>