|
|
|
import requests |
|
import pandas as pd |
|
import streamlit as st |
|
from io import BytesIO |
|
from bs4 import BeautifulSoup |
|
|
|
|
|
|
|
@st.cache_data(ttl=3600) |
|
def fetch_data(): |
|
|
|
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" |
|
) |
|
} |
|
|
|
|
|
response = requests.get(url, headers=headers) |
|
if response.status_code != 200: |
|
st.error("Failed to fetch the webpage. Please try again later.") |
|
return None |
|
|
|
|
|
soup = BeautifulSoup(response.content, "html.parser") |
|
file_url = None |
|
for link in soup.find_all("a"): |
|
if "Visa decisions made from" in link.get_text(): |
|
file_url = link.get("href") |
|
if not file_url.startswith("http"): |
|
file_url = requests.compat.urljoin(url, file_url) |
|
break |
|
|
|
if not file_url: |
|
st.error("Could not find the visa decisions file link on the website.") |
|
return None |
|
|
|
|
|
ods_response = requests.get(file_url, headers=headers) |
|
if ods_response.status_code != 200: |
|
st.error("Failed to download the visa decisions file.") |
|
return None |
|
|
|
|
|
ods_file = BytesIO(ods_response.content) |
|
df = pd.read_excel(ods_file, engine="odf") |
|
|
|
|
|
df.dropna(how="all", inplace=True) |
|
df.reset_index(drop=True, inplace=True) |
|
|
|
|
|
if len(df.columns) > 2: |
|
df = df.iloc[:, :2] |
|
|
|
|
|
if len(df.columns) == 2: |
|
df.columns = ["Application Number", "Decision"] |
|
else: |
|
st.error("Insufficient data columns detected.") |
|
return None |
|
|
|
df["Application Number"] = df["Application Number"].astype(str) |
|
|
|
|
|
return df |
|
|
|
|
|
precomputed_df = fetch_data() |
|
|