Create up.py
Browse files
up.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
from bs4 import BeautifulSoup
|
| 4 |
+
|
| 5 |
+
# Function to fetch live recitals from the GDPR website
|
| 6 |
+
def fetch_gdpr_recitals():
|
| 7 |
+
url = "https://gdpr-info.eu/recitals/"
|
| 8 |
+
response = requests.get(url)
|
| 9 |
+
|
| 10 |
+
# Check if the request was successful
|
| 11 |
+
if response.status_code != 200:
|
| 12 |
+
st.error("Failed to fetch data from the GDPR website.")
|
| 13 |
+
return {}
|
| 14 |
+
|
| 15 |
+
soup = BeautifulSoup(response.content, 'html.parser')
|
| 16 |
+
|
| 17 |
+
recitals = {}
|
| 18 |
+
# Locate all recital links
|
| 19 |
+
articles = soup.find_all('div', class_='artikel')
|
| 20 |
+
|
| 21 |
+
# Extract each recital's link and title
|
| 22 |
+
for i, article in enumerate(articles):
|
| 23 |
+
if i >= 3: # Limit to the first 3 recitals
|
| 24 |
+
break
|
| 25 |
+
link = article.find('a')['href']
|
| 26 |
+
number = article.find('span', class_='nummer').text.strip('()')
|
| 27 |
+
title = article.find('span', class_='titel').text.strip()
|
| 28 |
+
|
| 29 |
+
# Fetch the content of each recital
|
| 30 |
+
rec_response = requests.get(link)
|
| 31 |
+
if rec_response.status_code == 200:
|
| 32 |
+
rec_soup = BeautifulSoup(rec_response.content, 'html.parser')
|
| 33 |
+
content = rec_soup.find('div', class_='entry-content').get_text(strip=True)
|
| 34 |
+
recitals[number] = {'title': title, 'content': content}
|
| 35 |
+
else:
|
| 36 |
+
st.error(f"Failed to fetch recital {number} from {link}")
|
| 37 |
+
|
| 38 |
+
return recitals
|
| 39 |
+
|
| 40 |
+
def display_up_page():
|
| 41 |
+
st.title("UP Page - GDPR Recitals")
|
| 42 |
+
|
| 43 |
+
# Fetch and display live recitals
|
| 44 |
+
if st.button("Fetch Live Recitals"):
|
| 45 |
+
with st.spinner("Fetching updates..."):
|
| 46 |
+
recitals = fetch_gdpr_recitals()
|
| 47 |
+
if recitals:
|
| 48 |
+
for number, details in recitals.items():
|
| 49 |
+
st.markdown(f"*Recital {number}: {details['title']}*")
|
| 50 |
+
st.write(details['content'])
|
| 51 |
+
else:
|
| 52 |
+
st.write("No recitals found.")
|
| 53 |
+
|
| 54 |
+
# Call the function to display the UP page content
|
| 55 |
+
if __name__ == "__main__":
|
| 56 |
+
display_up_page()
|