Create lit.py
Browse files
lit.py
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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: Scrape the website to find the .ods file link
|
22 |
+
response = requests.get(url, headers=headers)
|
23 |
+
if response.status_code == 200:
|
24 |
+
soup = BeautifulSoup(response.content, 'html.parser')
|
25 |
+
|
26 |
+
# Find all anchor tags
|
27 |
+
links = soup.find_all('a')
|
28 |
+
|
29 |
+
# Search for the link containing the specific text
|
30 |
+
file_url = None
|
31 |
+
for link in links:
|
32 |
+
link_text = link.get_text(strip=True)
|
33 |
+
if "Visa decisions made from 1 January 2024 to" in link_text:
|
34 |
+
file_url = link.get('href')
|
35 |
+
break
|
36 |
+
|
37 |
+
# If the link was found, proceed to download the file
|
38 |
+
if file_url:
|
39 |
+
# Make the link absolute if it is relative
|
40 |
+
if not file_url.startswith('http'):
|
41 |
+
file_url = requests.compat.urljoin(url, file_url)
|
42 |
+
|
43 |
+
st.write(f"Found visa decision file: [Download Link]({file_url})")
|
44 |
+
|
45 |
+
# Step 2: Download the .ods file
|
46 |
+
file_response = requests.get(file_url, headers=headers)
|
47 |
+
|
48 |
+
if file_response.status_code == 200:
|
49 |
+
ods_file = BytesIO(file_response.content)
|
50 |
+
|
51 |
+
try:
|
52 |
+
# Step 3: Read the .ods file into a DataFrame
|
53 |
+
df = pd.read_excel(ods_file, engine='odf')
|
54 |
+
|
55 |
+
# Clean up the DataFrame by dropping unnecessary columns
|
56 |
+
df.drop(columns=["Unnamed: 0", "Unnamed: 1"], inplace=True, errors='ignore')
|
57 |
+
|
58 |
+
# Drop empty rows and reset index
|
59 |
+
df.dropna(how='all', inplace=True)
|
60 |
+
df.reset_index(drop=True, inplace=True)
|
61 |
+
|
62 |
+
# Identify the header row and reformat DataFrame
|
63 |
+
for idx, row in df.iterrows():
|
64 |
+
if row['Unnamed: 2'] == 'Application Number' and row['Unnamed: 3'] == 'Decision':
|
65 |
+
df.columns = ['Application Number', 'Decision']
|
66 |
+
df = df.iloc[idx + 1:] # Skip the header row
|
67 |
+
break
|
68 |
+
|
69 |
+
# Reset index after cleaning
|
70 |
+
df.reset_index(drop=True, inplace=True)
|
71 |
+
|
72 |
+
# Convert "Application Number" to string for consistency
|
73 |
+
df['Application Number'] = df['Application Number'].astype(str)
|
74 |
+
|
75 |
+
# Display the DataFrame in Streamlit
|
76 |
+
st.subheader("Visa Application Decisions")
|
77 |
+
st.dataframe(df)
|
78 |
+
|
79 |
+
# Step 4: Get user input for application number using Streamlit
|
80 |
+
user_application_number = st.text_input("Enter your Application Number")
|
81 |
+
|
82 |
+
# Step 5: Check if the application number exists in the DataFrame
|
83 |
+
if user_application_number:
|
84 |
+
result = df[df['Application Number'] == user_application_number]
|
85 |
+
|
86 |
+
if not result.empty:
|
87 |
+
st.success(f"Congratulations! Your visa application ({user_application_number}) has been {result.iloc[0]['Decision']}.")
|
88 |
+
else:
|
89 |
+
st.error(f"No record found for Application Number: {user_application_number}.")
|
90 |
+
|
91 |
+
except Exception as e:
|
92 |
+
st.error(f"Error reading the .ods file: {e}")
|
93 |
+
else:
|
94 |
+
st.error(f"Failed to download the file. Status code: {file_response.status_code}")
|
95 |
+
else:
|
96 |
+
st.error("The specified link was not found.")
|
97 |
+
else:
|
98 |
+
st.error(f"Failed to retrieve the webpage. Status code: {response.status_code}")
|