Subham9126 commited on
Commit
b63e95d
·
verified ·
1 Parent(s): 50ce546

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+
4
+ def fetch_train_html(train_no, date):
5
+ url = "https://enquiry.indianrail.gov.in/mntes/tr?opt=TrainRunning&subOpt=FindRunningInstance"
6
+
7
+ headers = {
8
+ "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:142.0) Gecko/20100101 Firefox/142.0",
9
+ "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
10
+ "Accept-Language": "en-US,en;q=0.5",
11
+ "Content-Type": "application/x-www-form-urlencoded",
12
+ "Upgrade-Insecure-Requests": "1",
13
+ "Sec-Fetch-Dest": "document",
14
+ "Sec-Fetch-Mode": "navigate",
15
+ "Sec-Fetch-Site": "same-origin",
16
+ "Sec-Fetch-User": "?1",
17
+ "Priority": "u=0, i",
18
+ "Referer": "https://enquiry.indianrail.gov.in/mntes/"
19
+ }
20
+
21
+ data = {
22
+ "lan": "en",
23
+ "jDate": date,
24
+ "trainNo": train_no
25
+ }
26
+
27
+ try:
28
+ resp = requests.post(url, headers=headers, data=data, timeout=20)
29
+ if resp.status_code == 200:
30
+ # Return first 1000 chars to avoid huge output
31
+ return resp.text[:1000]
32
+ else:
33
+ return f"Failed to fetch. Status code: {resp.status_code}"
34
+ except Exception as e:
35
+ return f"Error: {e}"
36
+
37
+ # Gradio interface
38
+ iface = gr.Interface(
39
+ fn=fetch_train_html,
40
+ inputs=[
41
+ gr.Textbox(label="Train Number", value="13019"),
42
+ gr.Textbox(label="Date (DD-MMM-YYYY)", value="16-Sep-2025")
43
+ ],
44
+ outputs="textbox",
45
+ title="NTES Train Running Test",
46
+ description="Test if NTES train-running HTML can be fetched via requests"
47
+ )
48
+
49
+ iface.launch()