Update loading_file.py (#7)
Browse files- Update loading_file.py (49602b8b6ef1dcd4d9550fafd579ca314bf3bf89)
- loading_file.py +7 -4
loading_file.py
CHANGED
@@ -3,8 +3,10 @@ from bs4 import BeautifulSoup
|
|
3 |
from io import BytesIO
|
4 |
import streamlit as st
|
5 |
|
6 |
-
# URL
|
7 |
url = "https://www.ireland.ie/en/india/newdelhi/services/visas/processing-times-and-decisions/"
|
|
|
|
|
8 |
headers = {
|
9 |
"User-Agent": (
|
10 |
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
|
@@ -19,11 +21,14 @@ def load_data_file():
|
|
19 |
soup = BeautifulSoup(response.content, 'html.parser')
|
20 |
links = soup.find_all('a')
|
21 |
|
|
|
22 |
file_url = None
|
|
|
23 |
for link in links:
|
24 |
link_text = link.get_text(strip=True)
|
25 |
if "Visa decisions made from 1 January 2024 to" in link_text:
|
26 |
file_url = link.get('href')
|
|
|
27 |
break
|
28 |
|
29 |
if file_url:
|
@@ -32,11 +37,9 @@ def load_data_file():
|
|
32 |
|
33 |
file_response = requests.get(file_url, headers=headers)
|
34 |
if file_response.status_code == 200:
|
35 |
-
return BytesIO(file_response.content),
|
36 |
else:
|
37 |
st.error(f"Failed to download the file. Status code: {file_response.status_code}")
|
38 |
-
else:
|
39 |
-
st.error("The specified link was not found.")
|
40 |
else:
|
41 |
st.error(f"Failed to retrieve the webpage. Status code: {response.status_code}")
|
42 |
return None, None
|
|
|
3 |
from io import BytesIO
|
4 |
import streamlit as st
|
5 |
|
6 |
+
# URL of the website to scrape
|
7 |
url = "https://www.ireland.ie/en/india/newdelhi/services/visas/processing-times-and-decisions/"
|
8 |
+
|
9 |
+
# Headers for the HTTP request
|
10 |
headers = {
|
11 |
"User-Agent": (
|
12 |
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
|
|
|
21 |
soup = BeautifulSoup(response.content, 'html.parser')
|
22 |
links = soup.find_all('a')
|
23 |
|
24 |
+
# Look for the link to the .ods file
|
25 |
file_url = None
|
26 |
+
file_name = None
|
27 |
for link in links:
|
28 |
link_text = link.get_text(strip=True)
|
29 |
if "Visa decisions made from 1 January 2024 to" in link_text:
|
30 |
file_url = link.get('href')
|
31 |
+
file_name = link_text
|
32 |
break
|
33 |
|
34 |
if file_url:
|
|
|
37 |
|
38 |
file_response = requests.get(file_url, headers=headers)
|
39 |
if file_response.status_code == 200:
|
40 |
+
return BytesIO(file_response.content), file_name
|
41 |
else:
|
42 |
st.error(f"Failed to download the file. Status code: {file_response.status_code}")
|
|
|
|
|
43 |
else:
|
44 |
st.error(f"Failed to retrieve the webpage. Status code: {response.status_code}")
|
45 |
return None, None
|