|
import requests |
|
import pandas as pd |
|
from io import BytesIO |
|
from bs4 import BeautifulSoup |
|
import streamlit as st |
|
|
|
|
|
st.title("Visa Application Status Checker") |
|
|
|
|
|
url = "https://www.ireland.ie/en/india/newdelhi/services/visas/processing-times-and-decisions/" |
|
|
|
|
|
headers = { |
|
"User-Agent": ( |
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " |
|
"(KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36" |
|
) |
|
} |
|
|
|
|
|
@st.cache_data(ttl=3600, max_entries=1) |
|
def fetch_ods_file(): |
|
response = requests.get(url, headers=headers) |
|
if response.status_code == 200: |
|
soup = BeautifulSoup(response.content, 'html.parser') |
|
|
|
|
|
links = soup.find_all('a') |
|
|
|
|
|
file_url = None |
|
for link in links: |
|
link_text = link.get_text(strip=True) |
|
if "Visa decisions made from 1 January 2024 to" in link_text: |
|
file_url = link.get('href') |
|
file_name = link_text |
|
break |
|
|
|
if file_url: |
|
|
|
if not file_url.startswith('http'): |
|
file_url = requests.compat.urljoin(url, file_url) |
|
|
|
file_response = requests.get(file_url, headers=headers) |
|
|
|
if file_response.status_code == 200: |
|
return BytesIO(file_response.content), file_name |
|
else: |
|
st.error(f"Failed to download the file. Status code: {file_response.status_code}") |
|
else: |
|
st.error("The specified link was not found.") |
|
else: |
|
st.error(f"Failed to retrieve the webpage. Status code: {response.status_code}") |
|
return None, None |
|
|
|
|
|
ods_file, cached_file_name = fetch_ods_file() |
|
|
|
if ods_file: |
|
try: |
|
|
|
df = pd.read_excel(ods_file, engine='odf') |
|
|
|
|
|
df.drop(columns=["Unnamed: 0", "Unnamed: 1"], inplace=True, errors='ignore') |
|
|
|
|
|
df.dropna(how='all', inplace=True) |
|
df.reset_index(drop=True, inplace=True) |
|
|
|
|
|
for idx, row in df.iterrows(): |
|
if row['Unnamed: 2'] == 'Application Number' and row['Unnamed: 3'] == 'Decision': |
|
df.columns = ['Application Number', 'Decision'] |
|
df = df.iloc[idx + 1:] |
|
break |
|
|
|
|
|
df.reset_index(drop=True, inplace=True) |
|
|
|
|
|
df['Application Number'] = df['Application Number'].astype(str) |
|
|
|
|
|
user_input = st.text_input("Enter your Application Number (including IRL if applicable):") |
|
|
|
if user_input: |
|
|
|
if "irl" in user_input.lower(): |
|
try: |
|
application_number = int("".join(filter(str.isdigit, user_input.lower().split("irl")[-1]))) |
|
if len(str(application_number)) < 8: |
|
st.warning("Please enter a valid application number with at least 8 digits after IRL.") |
|
st.stop() |
|
except ValueError: |
|
st.error("Invalid input after IRL. Please enter only digits.") |
|
st.stop() |
|
else: |
|
if not user_input.isdigit() or len(user_input) < 8: |
|
st.warning("Please enter at least 8 digits for your VISA application number.") |
|
st.stop() |
|
application_number = int(user_input) |
|
|
|
|
|
result = df[df['Application Number'] == str(application_number)] |
|
|
|
if not result.empty: |
|
decision = result.iloc[0]['Decision'] |
|
st.success(f"Application Number: **{application_number}**\n\nDecision: **{decision}**") |
|
else: |
|
st.warning(f"No record found for Application Number: {application_number}.") |
|
|
|
|
|
df['Application Number'] = df['Application Number'].astype(int) |
|
df['Difference'] = abs(df['Application Number'] - application_number) |
|
nearest_records = df.nsmallest(2, 'Difference') |
|
|
|
if not nearest_records.empty: |
|
st.subheader("Nearest Application Numbers") |
|
st.table(nearest_records[['Application Number', 'Decision', 'Difference']]) |
|
else: |
|
st.info("No nearest application numbers found.") |
|
|
|
except Exception as e: |
|
st.error(f"Error reading the .ods file: {e}") |
|
else: |
|
st.error("No file data available.") |
|
|