File size: 2,591 Bytes
47f6a53
b2ed551
47f6a53
 
 
 
 
 
 
 
 
 
75487aa
b2ed551
bc71b9f
984b382
 
 
1bbb697
47f6a53
d8d8f21
bdcefcc
75487aa
b2ed551
75487aa
b2ed551
47f6a53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1ba3ced
 
47f6a53
bc71b9f
984b382
bc71b9f
984b382
bc71b9f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a8fcd03
b233a95
bc71b9f
b233a95
 
 
 
bc71b9f
 
b233a95
b2ed551
bc71b9f
 
 
 
b2ed551
1bbb697
47f6a53
bc71b9f
984b382
bc71b9f
984b382
47f6a53
1bbb697
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
import gradio as gr

from daily import fetch_daily
from intraday import fetch_intraday
from info import fetch_info
from qresult import fetch_qresult
from result import fetch_result
from balance import fetch_balance
from cashflow import fetch_cashflow
from dividend import fetch_dividend
from split import fetch_split
from other import fetch_other
from index import fetch_index


# -----------------------------
# Data fetch function
# -----------------------------
def fetch_data(mode, req_type, name):
    req_type = req_type.lower()
    symbol = name

    if req_type == "index":
        return fetch_index()
    elif req_type == "daily":
        return fetch_daily(symbol, "NSE")
    elif req_type == "intraday":
        return fetch_intraday(symbol)
    elif req_type == "info":
        return fetch_info(symbol)
    elif req_type == "qresult":
        return fetch_qresult(symbol)
    elif req_type == "result":
        return fetch_result(symbol)
    elif req_type == "balance":
        return fetch_balance(symbol)
    elif req_type == "cashflow":
        return fetch_cashflow(symbol)
    elif req_type == "dividend":
        return fetch_dividend(symbol)
    elif req_type == "split":
        return fetch_split(symbol)
    elif req_type == "other":
        return fetch_other(symbol)
    else:
        return f"<h1>No handler for {req_type}</h1>"


# -----------------------------
# UI
# -----------------------------
with gr.Blocks(title="Stock / Index App") as iface:

    gr.Markdown("### **Stock / Index Data Fetcher**")

    # ----- Top bar -----
    with gr.Row():
        mode_input = gr.Textbox(
            label="Mode",
            value="stock",
            placeholder="stock / index",
            scale=1
        )

        symbol = gr.Textbox(
            label="Symbol / Index Name",
            value="PNB",
            placeholder="Enter symbol",
            scale=2
        )

        req_type = gr.Dropdown(
            label="Request Type",
            choices=[
                "info","intraday","daily","qresult","result","balance","cashflow",
                "dividend","split","index","open","preopen","ce","pe","future","bhav","highlow"
            ],
            value="info",
            scale=2
        )

        btn = gr.Button("Fetch", scale=1)

    # ----- Output -----
    output = gr.HTML(label="Output")

    btn.click(fetch_data, inputs=[mode_input, req_type, symbol], outputs=output)


# -----------------------------
# Launch
# -----------------------------
if __name__ == "__main__":
    iface.launch(server_name="0.0.0.0", server_port=7860)