awacke1 commited on
Commit
3568f5f
Β·
verified Β·
1 Parent(s): fdaad4e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -23
app.py CHANGED
@@ -79,27 +79,77 @@ def create_search_url_wikipedia(search_query):
79
  base_url = "https://www.wikipedia.org/search-redirect.php?family=wikipedia&language=en&search="
80
  return base_url + search_query.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and')
81
 
82
- def scan_for_xml_files_and_generate_links():
83
- xml_files = [f for f in os.listdir('.') if f.endswith('.xml')]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  if not xml_files:
85
- st.markdown("No XML files found in the directory.")
86
- return
87
-
88
- markdown_table = "Filename | Abbreviation | Full Name | Links\n--- | --- | --- | ---\n"
89
- for xml_file in xml_files:
90
- try:
91
- tree = ET.parse(xml_file)
92
- root = tree.getroot()
93
- for org in root.findall(".//nc:Organization", namespaces={'nc': 'http://niem.gov/niem/niem-core/2.0'}):
94
- short_name = org.find("nc:OrganizationAbbreviationText", namespaces={'nc': 'http://niem.gov/niem/niem-core/2.0'})
95
- long_name = org.find("nc:OrganizationName", namespaces={'nc': 'http://niem.gov/niem/niem-core/2.0'})
96
- if short_name is not None and long_name is not None:
97
- links = f"[Abbreviation Wikipedia]({create_search_url_wikipedia(short_name.text)}) | [Full Name Wikipedia]({create_search_url_wikipedia(long_name.text)})"
98
- markdown_table += f"{xml_file} | {short_name.text} | {long_name.text} | {links}\n"
99
- except ET.ParseError:
100
- st.warning(f"Could not parse XML file: {xml_file}")
101
-
102
- st.markdown(markdown_table)
103
 
104
  def search_foia_content(query: str, agency: str = None) -> Dict:
105
  results = {
@@ -115,7 +165,6 @@ def search_foia_content(query: str, agency: str = None) -> Dict:
115
  def main():
116
  st.title("Freedom of Information Act (FOIA) Explorer πŸŒπŸ“Š")
117
 
118
- # Tabs for different views
119
  tab1, tab2 = st.tabs(["Agency Browser", "FOIA Datasets & XML Scanner"])
120
 
121
  with tab1:
@@ -170,6 +219,7 @@ def main():
170
  st.header("FOIA Datasets & XML Scanner")
171
  st.write("""
172
  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. πŸŽ‰βœ¨
 
173
  """)
174
 
175
  st.markdown("""
@@ -192,8 +242,15 @@ def main():
192
  for dataset in datasets:
193
  st.markdown(f"- **{dataset}**: [Wikipedia]({create_search_url_wikipedia(dataset)})")
194
 
195
- st.markdown("### Organizations in Found XML Files")
196
- scan_for_xml_files_and_generate_links()
 
 
 
 
 
 
 
197
 
198
  if __name__ == "__main__":
199
  main()
 
79
  base_url = "https://www.wikipedia.org/search-redirect.php?family=wikipedia&language=en&search="
80
  return base_url + search_query.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and')
81
 
82
+ def process_foia_xml_file(filename: str):
83
+ """Process FOIA XML file and display results with emojis"""
84
+ try:
85
+ tree = ET.parse(filename)
86
+ root = tree.getroot()
87
+
88
+ # Namespace dictionary
89
+ ns = {
90
+ 'iepd': 'http://leisp.usdoj.gov/niem/FoiaAnnualReport/exchange/1.03',
91
+ 'foia': 'http://leisp.usdoj.gov/niem/FoiaAnnualReport/extension/1.03',
92
+ 'nc': 'http://niem.gov/niem/niem-core/2.0',
93
+ 'j': 'http://niem.gov/niem/domains/jxdm/4.1'
94
+ }
95
+
96
+ # Extract basic info
97
+ org = root.find(".//nc:Organization", ns)
98
+ org_name = org.find("nc:OrganizationName", ns).text if org is not None else "Unknown"
99
+ org_abbr = org.find("nc:OrganizationAbbreviationText", ns).text if org is not None else "N/A"
100
+ fiscal_year = root.find(".//foia:DocumentFiscalYearDate", ns).text if root.find(".//foia:DocumentFiscalYearDate", ns) is not None else "N/A"
101
+
102
+ st.subheader(f"πŸ“‹ {org_name} ({org_abbr}) FOIA Report {fiscal_year}")
103
+ st.write(f"[Wikipedia - {org_name}]({create_search_url_wikipedia(org_name)})")
104
+
105
+ # Processing Statistics
106
+ proc_stats = root.find(".//foia:ProcessedRequestSection/foia:ProcessingStatistics", ns)
107
+ if proc_stats is not None:
108
+ st.write("πŸ“Š **Request Processing Statistics**")
109
+ st.write(f"- Pending at Start: {proc_stats.find('foia:ProcessingStatisticsPendingAtStartQuantity', ns).text} ⏳")
110
+ st.write(f"- Received: {proc_stats.find('foia:ProcessingStatisticsReceivedQuantity', ns).text} πŸ“₯")
111
+ st.write(f"- Processed: {proc_stats.find('foia:ProcessingStatisticsProcessedQuantity', ns).text} βœ…")
112
+ st.write(f"- Pending at End: {proc_stats.find('foia:ProcessingStatisticsPendingAtEndQuantity', ns).text} ⏳")
113
+
114
+ # Request Dispositions
115
+ disp = root.find(".//foia:RequestDispositionSection/foia:RequestDisposition", ns)
116
+ if disp is not None:
117
+ st.write("πŸ“‘ **Request Dispositions**")
118
+ st.write(f"- Full Grants: {disp.find('foia:RequestDispositionFullGrantQuantity', ns).text} βœ…")
119
+ st.write(f"- Partial Grants: {disp.find('foia:RequestDispositionPartialGrantQuantity', ns).text} βž•")
120
+ st.write(f"- Full Denials: {disp.find('foia:RequestDispositionFullExemptionDenialQuantity', ns).text} ❌")
121
+ denial = disp.find('foia:NonExemptionDenial', ns)
122
+ if denial is not None:
123
+ st.write(f"- Non-Exemption Denial ({denial.find('foia:NonExemptionDenialReasonCode', ns).text}): {denial.find('foia:NonExemptionDenialQuantity', ns).text} πŸ“­")
124
+
125
+ # Applied Exemptions
126
+ exemptions = root.findall(".//foia:RequestDispositionAppliedExemptionsSection/foia:ComponentAppliedExemptions/foia:AppliedExemption", ns)
127
+ if exemptions:
128
+ st.write("🚫 **Applied Exemptions**")
129
+ for ex in exemptions:
130
+ code = ex.find('foia:AppliedExemptionCode', ns).text
131
+ qty = ex.find('foia:AppliedExemptionQuantity', ns).text
132
+ st.write(f"- {code}: {qty} times")
133
+
134
+ # Response Times
135
+ resp_time = root.find(".//foia:ProcessedResponseTimeSection/foia:ProcessedResponseTime", ns)
136
+ if resp_time is not None:
137
+ st.write("⏰ **Response Times**")
138
+ simple = resp_time.find('foia:SimpleResponseTime', ns)
139
+ if simple is not None:
140
+ st.write(f"- Simple Requests:")
141
+ st.write(f" - Median: {simple.find('foia:ResponseTimeMedianDaysValue', ns).text} days ⏱️")
142
+ st.write(f" - Average: {simple.find('foia:ResponseTimeAverageDaysValue', ns).text} days πŸ“ˆ")
143
+
144
+ except ET.ParseError:
145
+ st.error(f"❌ Error parsing XML file: {filename}")
146
+
147
+ def list_xml_files():
148
+ xml_files = [f[:-4] for f in os.listdir('.') if f.endswith('.xml')]
149
  if not xml_files:
150
+ st.markdown("No XML files found in the directory. πŸ“‚β“")
151
+ return []
152
+ return xml_files
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
 
154
  def search_foia_content(query: str, agency: str = None) -> Dict:
155
  results = {
 
165
  def main():
166
  st.title("Freedom of Information Act (FOIA) Explorer πŸŒπŸ“Š")
167
 
 
168
  tab1, tab2 = st.tabs(["Agency Browser", "FOIA Datasets & XML Scanner"])
169
 
170
  with tab1:
 
219
  st.header("FOIA Datasets & XML Scanner")
220
  st.write("""
221
  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. πŸŽ‰βœ¨
222
+ Below is a list of datasets available under FOIA, alongside guessed Wikipedia URLs for more information. πŸ“šπŸ”
223
  """)
224
 
225
  st.markdown("""
 
242
  for dataset in datasets:
243
  st.markdown(f"- **{dataset}**: [Wikipedia]({create_search_url_wikipedia(dataset)})")
244
 
245
+ st.markdown("### Available FOIA XML Reports")
246
+ xml_files = list_xml_files()
247
+ for xml_file in xml_files:
248
+ col1, col2 = st.columns([3, 1])
249
+ with col1:
250
+ st.markdown(f"- [{xml_file}]({xml_file}.xml)")
251
+ with col2:
252
+ if st.button(f"πŸ“Š Process {xml_file}", key=f"process_{xml_file}"):
253
+ process_foia_xml_file(f"{xml_file}.xml")
254
 
255
  if __name__ == "__main__":
256
  main()