Spaces:
Running
Running
Update app/ui_html.py
Browse files- app/ui_html.py +74 -140
app/ui_html.py
CHANGED
|
@@ -1,164 +1,98 @@
|
|
| 1 |
-
|
| 2 |
-
from . import screener
|
| 3 |
-
|
| 4 |
-
def build_frontend_html():
|
| 5 |
-
return """
|
| 6 |
<!DOCTYPE html>
|
| 7 |
-
<html
|
| 8 |
<head>
|
| 9 |
-
<meta charset="
|
| 10 |
-
<title>Stock / Index
|
| 11 |
-
|
| 12 |
-
<style>
|
| 13 |
-
body {
|
| 14 |
-
font-family: Arial, sans-serif;
|
| 15 |
-
margin: 0;
|
| 16 |
-
padding: 10px;
|
| 17 |
-
}
|
| 18 |
-
.controls {
|
| 19 |
-
display: flex;
|
| 20 |
-
flex-wrap: wrap;
|
| 21 |
-
gap: 10px;
|
| 22 |
-
}
|
| 23 |
-
select, input, button {
|
| 24 |
-
padding: 6px;
|
| 25 |
-
font-size: 14px;
|
| 26 |
-
}
|
| 27 |
-
#response {
|
| 28 |
-
margin-top: 15px;
|
| 29 |
-
padding: 10px;
|
| 30 |
-
border: 1px solid #ccc;
|
| 31 |
-
height: calc(100vh - 120px);
|
| 32 |
-
overflow: auto;
|
| 33 |
-
}
|
| 34 |
-
</style>
|
| 35 |
</head>
|
| 36 |
-
|
| 37 |
<body>
|
| 38 |
|
| 39 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
<
|
| 42 |
-
|
| 43 |
-
<option value="stock">stock</option>
|
| 44 |
-
<option value="index">index</option>
|
| 45 |
-
<option value="screener">screener</option>
|
| 46 |
-
</select>
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
|
| 51 |
-
|
| 52 |
-
<input id="date_end" placeholder="YYYY-MM-DD">
|
| 53 |
|
| 54 |
-
|
| 55 |
-
</div>
|
| 56 |
-
|
| 57 |
-
<div id="response">Loading req_type list...</div>
|
| 58 |
|
| 59 |
<script>
|
| 60 |
-
const
|
| 61 |
-
let
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
doc.querySelectorAll("li").forEach(li => {
|
| 77 |
-
const mode = li.dataset.mode;
|
| 78 |
-
const type = li.dataset.type;
|
| 79 |
-
const names = (li.dataset.names || "").split(",").filter(Boolean);
|
| 80 |
-
|
| 81 |
-
if (mode && type) {
|
| 82 |
-
REQ_MAP[mode].push({ type, names });
|
| 83 |
-
}
|
| 84 |
});
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
}
|
| 88 |
-
|
| 89 |
-
/* ---------------- REQ TYPE ---------------- */
|
| 90 |
-
function updateReqType() {
|
| 91 |
-
const mode = document.getElementById("mode").value;
|
| 92 |
-
const sel = document.getElementById("req_type");
|
| 93 |
-
sel.innerHTML = "";
|
| 94 |
-
|
| 95 |
-
REQ_MAP[mode].forEach(r => {
|
| 96 |
-
const o = document.createElement("option");
|
| 97 |
-
o.value = r.type;
|
| 98 |
-
o.textContent = r.type;
|
| 99 |
-
sel.appendChild(o);
|
| 100 |
-
});
|
| 101 |
-
|
| 102 |
-
if (mode === "stock") sel.value = "info";
|
| 103 |
-
if (mode === "index") sel.value = "indices";
|
| 104 |
-
if (mode === "screener") sel.value = "from-high";
|
| 105 |
-
|
| 106 |
-
updateName();
|
| 107 |
}
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
o.value = n;
|
| 122 |
-
o.textContent = n;
|
| 123 |
-
sel.appendChild(o);
|
| 124 |
-
});
|
| 125 |
-
} else {
|
| 126 |
-
const o = document.createElement("option");
|
| 127 |
-
o.value = "";
|
| 128 |
-
o.textContent = "-- none --";
|
| 129 |
-
sel.appendChild(o);
|
| 130 |
-
}
|
| 131 |
-
|
| 132 |
-
if (mode === "stock") sel.value = "ITC";
|
| 133 |
-
if (mode === "index") sel.value = "NIFTY 50";
|
| 134 |
}
|
| 135 |
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
};
|
| 145 |
-
|
| 146 |
-
const res = await fetch(API_URL, {
|
| 147 |
-
method: "POST",
|
| 148 |
-
headers: {"Content-Type":"application/json"},
|
| 149 |
-
body: JSON.stringify(payload)
|
| 150 |
});
|
| 151 |
-
|
| 152 |
-
|
|
|
|
| 153 |
}
|
| 154 |
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
|
| 159 |
-
|
|
|
|
|
|
|
| 160 |
</script>
|
| 161 |
-
|
| 162 |
</body>
|
| 163 |
</html>
|
| 164 |
"""
|
|
|
|
| 1 |
+
HTML = """
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
<!DOCTYPE html>
|
| 3 |
+
<html>
|
| 4 |
<head>
|
| 5 |
+
<meta charset="utf-8">
|
| 6 |
+
<title>Stock / Index UI</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
</head>
|
|
|
|
| 8 |
<body>
|
| 9 |
|
| 10 |
+
<select id="mode">
|
| 11 |
+
<option value="stock">stock</option>
|
| 12 |
+
<option value="index">index</option>
|
| 13 |
+
<option value="screener">screener</option>
|
| 14 |
+
</select>
|
| 15 |
|
| 16 |
+
<select id="req_type"></select>
|
| 17 |
+
<select id="name"></select>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
<input id="date_start" placeholder="dd-mm-yyyy">
|
| 20 |
+
<input id="date_end" placeholder="dd-mm-yyyy">
|
| 21 |
|
| 22 |
+
<button onclick="fetchData()">Fetch</button>
|
|
|
|
| 23 |
|
| 24 |
+
<div id="response">Loading...</div>
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
<script>
|
| 27 |
+
const API="/api/fetch";
|
| 28 |
+
let META={stock:[],index:[],screener:[]};
|
| 29 |
+
|
| 30 |
+
async function init(){
|
| 31 |
+
const r=await fetch(API,{
|
| 32 |
+
method:"POST",
|
| 33 |
+
headers:{"Content-Type":"application/json"},
|
| 34 |
+
body:JSON.stringify({mode:"list"})
|
| 35 |
+
});
|
| 36 |
+
const html=await r.text();
|
| 37 |
+
const doc=new DOMParser().parseFromString(html,"text/html");
|
| 38 |
+
|
| 39 |
+
doc.querySelectorAll("li").forEach(li=>{
|
| 40 |
+
META[li.dataset.mode].push({
|
| 41 |
+
type:li.dataset.type,
|
| 42 |
+
names:(li.dataset.names||"").split(",").filter(Boolean)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
});
|
| 44 |
+
});
|
| 45 |
+
updateReq();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
}
|
| 47 |
|
| 48 |
+
function updateReq(){
|
| 49 |
+
req_type.innerHTML="";
|
| 50 |
+
META[mode.value].forEach(x=>{
|
| 51 |
+
let o=document.createElement("option");
|
| 52 |
+
o.value=x.type;o.text=x.type;
|
| 53 |
+
req_type.appendChild(o);
|
| 54 |
+
});
|
| 55 |
+
|
| 56 |
+
if(mode.value==="stock") req_type.value="info";
|
| 57 |
+
if(mode.value==="index") req_type.value="indices";
|
| 58 |
+
if(mode.value==="screener") req_type.value="from-high";
|
| 59 |
+
updateName();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
}
|
| 61 |
|
| 62 |
+
function updateName(){
|
| 63 |
+
name.innerHTML="";
|
| 64 |
+
const r=META[mode.value].find(x=>x.type===req_type.value);
|
| 65 |
+
if(r && r.names.length){
|
| 66 |
+
r.names.forEach(n=>{
|
| 67 |
+
let o=document.createElement("option");
|
| 68 |
+
o.value=n;o.text=n;
|
| 69 |
+
name.appendChild(o);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
});
|
| 71 |
+
} else {
|
| 72 |
+
name.innerHTML="<option></option>";
|
| 73 |
+
}
|
| 74 |
}
|
| 75 |
|
| 76 |
+
async function fetchData(){
|
| 77 |
+
const p={
|
| 78 |
+
mode:mode.value,
|
| 79 |
+
req_type:req_type.value,
|
| 80 |
+
name:name.value,
|
| 81 |
+
date_start:date_start.value,
|
| 82 |
+
date_end:date_end.value
|
| 83 |
+
};
|
| 84 |
+
const r=await fetch(API,{
|
| 85 |
+
method:"POST",
|
| 86 |
+
headers:{"Content-Type":"application/json"},
|
| 87 |
+
body:JSON.stringify(p)
|
| 88 |
+
});
|
| 89 |
+
response.innerHTML=await r.text();
|
| 90 |
+
}
|
| 91 |
|
| 92 |
+
mode.onchange=updateReq;
|
| 93 |
+
req_type.onchange=updateName;
|
| 94 |
+
init();
|
| 95 |
</script>
|
|
|
|
| 96 |
</body>
|
| 97 |
</html>
|
| 98 |
"""
|