import streamlit as st import os import xml.etree.ElementTree as ET # Function to create search URL on Wikipedia def create_search_url_wikipedia(search_query): base_url = "https://www.wikipedia.org/search-redirect.php?family=wikipedia&language=en&search=" return base_url + search_query.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and') # Function to scan for XML files and generate links in a markdown table def scan_for_xml_files_and_generate_links(): xml_files = [f for f in os.listdir('.') if f.endswith('.xml')] if not xml_files: # Check if the list is empty st.markdown("No XML files found in the directory.") return # Start of the markdown table markdown_table = "Filename | Abbreviation | Full Name | Links\n--- | --- | --- | ---\n" for xml_file in xml_files: tree = ET.parse(xml_file) root = tree.getroot() for org in root.findall(".//nc:Organization", namespaces={'nc': 'http://niem.gov/niem/niem-core/2.0'}): short_name = org.find("nc:OrganizationAbbreviationText", namespaces={'nc': 'http://niem.gov/niem/niem-core/2.0'}).text long_name = org.find("nc:OrganizationName", namespaces={'nc': 'http://niem.gov/niem/niem-core/2.0'}).text links = f"[Abbreviation Wikipedia]({create_search_url_wikipedia(short_name)}) | [Full Name Wikipedia]({create_search_url_wikipedia(long_name)})" markdown_table += f"{xml_file} | {short_name} | {long_name} | {links}\n" # Display the markdown table st.markdown(markdown_table) # Streamlit UI def app(): st.title("Freedom of Information Act (FOIA) Open Data 🌍📊") st.write(""" The Freedom of Information Act (FOIA) empowers individuals by granting access to previously unreleased information and documents controlled by the United States government. Championing transparency and accountability, FOIA serves as a foundation for democratic engagement and open government initiatives. 🎉✨ Below is a list of datasets available under FOIA, alongside guessed Wikipedia URLs for more information. 📚🔍 # (FOIA.Gov)[https://www.foia.gov/foia-dataset-download.html] # (Data.Gov)[https://catalog.data.gov/dataset?tags=foia] """) # Example datasets under FOIA datasets = [ "Provider Taxonomy", "Consumer Complaint Database", "Medicare Provider Utilization and Payment Data", "Global Terrorism Database", "National Nutrient Database", "Patent Grant Full Text Data", "Toxic Release Inventory", "Residential Energy Consumption Survey", ] # Displaying the datasets table st.markdown("### FOIA Datasets and Wikipedia URLs") for dataset in datasets: st.markdown(f"- **{dataset}**: [Wikipedia]({create_search_url_wikipedia(dataset)})") st.markdown("### Organizations in Found XML Files") scan_for_xml_files_and_generate_links() if __name__ == "__main__": app()