SR05 commited on
Commit
21a5451
·
verified ·
1 Parent(s): 32b1206

Create loading_file.py

Browse files
Files changed (1) hide show
  1. loading_file.py +42 -0
loading_file.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from bs4 import BeautifulSoup
3
+ from io import BytesIO
4
+ import streamlit as st
5
+
6
+ # URL and headers for the file source
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 "
11
+ "(KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"
12
+ )
13
+ }
14
+
15
+ @st.cache_data(ttl=3600, max_entries=1)
16
+ def load_data_file():
17
+ response = requests.get(url, headers=headers)
18
+ if response.status_code == 200:
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:
30
+ if not file_url.startswith('http'):
31
+ file_url = requests.compat.urljoin(url, file_url)
32
+
33
+ file_response = requests.get(file_url, headers=headers)
34
+ if file_response.status_code == 200:
35
+ return BytesIO(file_response.content), link_text
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