Spaces:
Running
Running
File size: 2,171 Bytes
8bce80c 7040167 8bce80c 7040167 8bce80c 7040167 8bce80c 7040167 8bce80c 7040167 8bce80c 7040167 8bce80c 7040167 8bce80c 7040167 8bce80c 7040167 8bce80c 7040167 8bce80c 7040167 8bce80c 7040167 8bce80c 7040167 8bce80c 7040167 8bce80c 7040167 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
HTML = """
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Stock / Index UI</title>
</head>
<body>
<select id="mode">
<option value="stock">stock</option>
<option value="index">index</option>
<option value="screener">screener</option>
</select>
<select id="req_type"></select>
<select id="name"></select>
<input id="date_start" placeholder="dd-mm-yyyy">
<input id="date_end" placeholder="dd-mm-yyyy">
<button onclick="fetchData()">Fetch</button>
<div id="response">Loading...</div>
<script>
const API="/api/fetch";
let META={stock:[],index:[],screener:[]};
async function init(){
const r=await fetch(API,{
method:"POST",
headers:{"Content-Type":"application/json"},
body:JSON.stringify({mode:"list"})
});
const html=await r.text();
const doc=new DOMParser().parseFromString(html,"text/html");
doc.querySelectorAll("li").forEach(li=>{
META[li.dataset.mode].push({
type:li.dataset.type,
names:(li.dataset.names||"").split(",").filter(Boolean)
});
});
updateReq();
}
function updateReq(){
req_type.innerHTML="";
META[mode.value].forEach(x=>{
let o=document.createElement("option");
o.value=x.type;o.text=x.type;
req_type.appendChild(o);
});
if(mode.value==="stock") req_type.value="info";
if(mode.value==="index") req_type.value="indices";
if(mode.value==="screener") req_type.value="from-high";
updateName();
}
function updateName(){
name.innerHTML="";
const r=META[mode.value].find(x=>x.type===req_type.value);
if(r && r.names.length){
r.names.forEach(n=>{
let o=document.createElement("option");
o.value=n;o.text=n;
name.appendChild(o);
});
} else {
name.innerHTML="<option></option>";
}
}
async function fetchData(){
const p={
mode:mode.value,
req_type:req_type.value,
name:name.value,
date_start:date_start.value,
date_end:date_end.value
};
const r=await fetch(API,{
method:"POST",
headers:{"Content-Type":"application/json"},
body:JSON.stringify(p)
});
response.innerHTML=await r.text();
}
mode.onchange=updateReq;
req_type.onchange=updateName;
init();
</script>
</body>
</html>
"""
|