Create lit1.py
Browse files
lit1.py
ADDED
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import pandas as pd
|
3 |
+
from io import BytesIO
|
4 |
+
from bs4 import BeautifulSoup
|
5 |
+
import streamlit as st
|
6 |
+
|
7 |
+
# Streamlit app title
|
8 |
+
st.title("Visa Application Status Checker")
|
9 |
+
|
10 |
+
# URL of the website to scrape
|
11 |
+
url = "https://www.ireland.ie/en/india/newdelhi/services/visas/processing-times-and-decisions/"
|
12 |
+
|
13 |
+
# Headers to mimic a browser request
|
14 |
+
headers = {
|
15 |
+
"User-Agent": (
|
16 |
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
|
17 |
+
"(KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"
|
18 |
+
)
|
19 |
+
}
|
20 |
+
|
21 |
+
# Step 1: Function to fetch and cache the .ods file
|
22 |
+
@st.cache_data(ttl=3600, max_entries=1)
|
23 |
+
def fetch_ods_file():
|
24 |
+
response = requests.get(url, headers=headers)
|
25 |
+
if response.status_code == 200:
|
26 |
+
soup = BeautifulSoup(response.content, 'html.parser')
|
27 |
+
|
28 |
+
# Find all anchor tags
|
29 |
+
links = soup.find_all('a')
|
30 |
+
|
31 |
+
# Search for the link containing the specific text
|
32 |
+
file_url = None
|
33 |
+
for link in links:
|
34 |
+
link_text = link.get_text(strip=True)
|
35 |
+
if "Visa decisions made from 1 January 2024 to" in link_text:
|
36 |
+
file_url = link.get('href')
|
37 |
+
file_name = link_text
|
38 |
+
break
|
39 |
+
|
40 |
+
if file_url:
|
41 |
+
# Make the link absolute if it is relative
|
42 |
+
if not file_url.startswith('http'):
|
43 |
+
file_url = requests.compat.urljoin(url, file_url)
|
44 |
+
|
45 |
+
file_response = requests.get(file_url, headers=headers)
|
46 |
+
|
47 |
+
if file_response.status_code == 200:
|
48 |
+
return BytesIO(file_response.content), file_name
|
49 |
+
else:
|
50 |
+
st.error(f"Failed to download the file. Status code: {file_response.status_code}")
|
51 |
+
else:
|
52 |
+
st.error("The specified link was not found.")
|
53 |
+
else:
|
54 |
+
st.error(f"Failed to retrieve the webpage. Status code: {response.status_code}")
|
55 |
+
return None, None
|
56 |
+
|
57 |
+
# Step 2: Fetch the cached .ods file
|
58 |
+
ods_file, cached_file_name = fetch_ods_file()
|
59 |
+
|
60 |
+
if ods_file:
|
61 |
+
try:
|
62 |
+
# Step 3: Read the .ods file into a DataFrame
|
63 |
+
df = pd.read_excel(ods_file, engine='odf')
|
64 |
+
|
65 |
+
# Clean up the DataFrame by dropping unnecessary columns
|
66 |
+
df.drop(columns=["Unnamed: 0", "Unnamed: 1"], inplace=True, errors='ignore')
|
67 |
+
|
68 |
+
# Drop empty rows and reset index
|
69 |
+
df.dropna(how='all', inplace=True)
|
70 |
+
df.reset_index(drop=True, inplace=True)
|
71 |
+
|
72 |
+
# Identify the header row and reformat DataFrame
|
73 |
+
for idx, row in df.iterrows():
|
74 |
+
if row['Unnamed: 2'] == 'Application Number' and row['Unnamed: 3'] == 'Decision':
|
75 |
+
df.columns = ['Application Number', 'Decision']
|
76 |
+
df = df.iloc[idx + 1:] # Skip the header row
|
77 |
+
break
|
78 |
+
|
79 |
+
# Reset index after cleaning
|
80 |
+
df.reset_index(drop=True, inplace=True)
|
81 |
+
|
82 |
+
# Convert "Application Number" to string for consistency
|
83 |
+
df['Application Number'] = df['Application Number'].astype(str)
|
84 |
+
|
85 |
+
# Step 4: Get user input for application number using Streamlit
|
86 |
+
user_input = st.text_input("Enter your Application Number (including IRL if applicable):")
|
87 |
+
|
88 |
+
if user_input:
|
89 |
+
# Input validation logic
|
90 |
+
if "irl" in user_input.lower():
|
91 |
+
try:
|
92 |
+
application_number = int("".join(filter(str.isdigit, user_input.lower().split("irl")[-1])))
|
93 |
+
if len(str(application_number)) < 8:
|
94 |
+
st.warning("Please enter a valid application number with at least 8 digits after IRL.")
|
95 |
+
st.stop()
|
96 |
+
except ValueError:
|
97 |
+
st.error("Invalid input after IRL. Please enter only digits.")
|
98 |
+
st.stop()
|
99 |
+
else:
|
100 |
+
if not user_input.isdigit() or len(user_input) < 8:
|
101 |
+
st.warning("Please enter at least 8 digits for your VISA application number.")
|
102 |
+
st.stop()
|
103 |
+
application_number = int(user_input)
|
104 |
+
|
105 |
+
# Check if the application number exists in the DataFrame
|
106 |
+
result = df[df['Application Number'] == str(application_number)]
|
107 |
+
|
108 |
+
if not result.empty:
|
109 |
+
decision = result.iloc[0]['Decision']
|
110 |
+
st.success(f"Application Number: **{application_number}**\n\nDecision: **{decision}**")
|
111 |
+
else:
|
112 |
+
st.warning(f"No record found for Application Number: {application_number}.")
|
113 |
+
|
114 |
+
# Find the nearest application numbers
|
115 |
+
df['Application Number'] = df['Application Number'].astype(int)
|
116 |
+
df['Difference'] = abs(df['Application Number'] - application_number)
|
117 |
+
nearest_records = df.nsmallest(2, 'Difference')
|
118 |
+
|
119 |
+
if not nearest_records.empty:
|
120 |
+
st.subheader("Nearest Application Numbers")
|
121 |
+
st.table(nearest_records[['Application Number', 'Decision', 'Difference']])
|
122 |
+
else:
|
123 |
+
st.info("No nearest application numbers found.")
|
124 |
+
|
125 |
+
except Exception as e:
|
126 |
+
st.error(f"Error reading the .ods file: {e}")
|
127 |
+
else:
|
128 |
+
st.error("No file data available.")
|