Update lit.py
Browse files
lit.py
CHANGED
@@ -18,104 +18,118 @@ headers = {
|
|
18 |
)
|
19 |
}
|
20 |
|
21 |
-
# Step 1:
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
if
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
-
|
|
|
44 |
|
45 |
-
#
|
46 |
-
|
47 |
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
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 |
-
# Step 4: Get user input for application number using Streamlit
|
76 |
-
user_application_number = st.text_input("Enter your Application Number")
|
77 |
|
78 |
-
#
|
79 |
-
|
80 |
-
|
|
|
81 |
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
result_table = pd.DataFrame({
|
101 |
-
"Nearest Application": ['Before', 'After'],
|
102 |
-
"Application Number": [pre_number['Application Number'].values[0] if not pre_number.empty else None,
|
103 |
-
post_number['Application Number'].values[0] if not post_number.empty else None],
|
104 |
-
"Decision": [pre_number['Decision'].values[0] if not pre_number.empty else None,
|
105 |
-
post_number['Decision'].values[0] if not post_number.empty else None],
|
106 |
-
"Difference": [pre_diff, post_diff]
|
107 |
-
})
|
108 |
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
st.error(f"Error reading the .ods file: {e}")
|
115 |
-
else:
|
116 |
-
st.error(f"Failed to download the file. Status code: {file_response.status_code}")
|
117 |
-
else:
|
118 |
-
st.error("The specified link was not found.")
|
119 |
-
else:
|
120 |
-
st.error(f"Failed to retrieve the webpage. Status code: {response.status_code}")
|
121 |
|
|
|
|
|
|
|
|
|
|
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_application_number = st.text_input("Enter your Application Number")
|
87 |
+
|
88 |
+
# Step 5: Check if the application number exists in the DataFrame
|
89 |
+
if user_application_number:
|
90 |
+
result = df[df['Application Number'] == user_application_number]
|
91 |
|
92 |
+
if not result.empty:
|
93 |
+
decision = result.iloc[0]['Decision']
|
94 |
+
if decision.lower() == 'approved':
|
95 |
+
st.success(f"Congratulations! Your visa application ({user_application_number}) has been Approved.")
|
96 |
+
elif decision.lower() == 'rejected':
|
97 |
+
st.error(f"Sorry, your visa application ({user_application_number}) has been Rejected.")
|
98 |
+
else:
|
99 |
+
st.warning(f"Your visa application ({user_application_number}) has a status of '{decision}'.")
|
100 |
+
else:
|
101 |
+
st.warning(f"No record found for Application Number: {user_application_number}.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
+
# Convert Application Numbers to integers for comparison
|
104 |
+
df['Application Number'] = df['Application Number'].astype(int)
|
105 |
+
try:
|
106 |
+
user_application_number_int = int(user_application_number)
|
107 |
|
108 |
+
# Step 6: Find the nearest pre and post application numbers
|
109 |
+
df_sorted = df.sort_values(by='Application Number')
|
110 |
+
pre_number = df_sorted[df_sorted['Application Number'] < user_application_number_int].tail(1)
|
111 |
+
post_number = df_sorted[df_sorted['Application Number'] > user_application_number_int].head(1)
|
112 |
+
|
113 |
+
# Prepare the results
|
114 |
+
pre_diff = user_application_number_int - pre_number['Application Number'].values[0] if not pre_number.empty else None
|
115 |
+
post_diff = post_number['Application Number'].values[0] - user_application_number_int if not post_number.empty else None
|
116 |
+
|
117 |
+
result_table = pd.DataFrame({
|
118 |
+
"Nearest Application": ['Before', 'After'],
|
119 |
+
"Application Number": [pre_number['Application Number'].values[0] if not pre_number.empty else None,
|
120 |
+
post_number['Application Number'].values[0] if not post_number.empty else None],
|
121 |
+
"Decision": [pre_number['Decision'].values[0] if not pre_number.empty else None,
|
122 |
+
post_number['Decision'].values[0] if not post_number.empty else None],
|
123 |
+
"Difference": [pre_diff, post_diff]
|
124 |
+
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
|
126 |
+
# Step 7: Display the nearest application numbers in tabular form
|
127 |
+
st.subheader("Nearest Application Numbers")
|
128 |
+
st.table(result_table)
|
129 |
+
except ValueError:
|
130 |
+
st.error("Invalid Application Number format. Please enter a numeric value.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
|
132 |
+
except Exception as e:
|
133 |
+
st.error(f"Error reading the .ods file: {e}")
|
134 |
+
else:
|
135 |
+
st.error("No file data available.")
|