awacke1 commited on
Commit
209ff0f
·
verified ·
1 Parent(s): 7297646

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from bs4 import BeautifulSoup
3
+
4
+ def clean_bookmarks(html_content):
5
+ soup = BeautifulSoup(html_content, 'html.parser')
6
+ links = soup.find_all('a')
7
+
8
+ cleaned_html = '<html><body>\n'
9
+ for link in links:
10
+ href = link.get('href')
11
+ anchor_name = link.text.strip()
12
+ cleaned_html += f'<a href="{href}">{anchor_name}</a><br>\n'
13
+ cleaned_html += '</body></html>'
14
+
15
+ return cleaned_html
16
+
17
+ def main():
18
+ st.title('Bookmark File Cleaner')
19
+
20
+ uploaded_file = st.file_uploader('Choose an HTML bookmark file', type=['html'])
21
+
22
+ if uploaded_file is not None:
23
+ html_content = uploaded_file.read().decode('utf-8')
24
+ cleaned_html = clean_bookmarks(html_content)
25
+
26
+ st.subheader('Cleaned Bookmarks')
27
+ st.text_area('Output HTML', value=cleaned_html, height=400)
28
+
29
+ output_file = 'cleaned_bookmarks.html'
30
+ with open(output_file, 'w') as f:
31
+ f.write(cleaned_html)
32
+
33
+
34
+
35
+ st.download_button('Download Cleaned Bookmarks', cleaned_html, file_name=output_file)
36
+
37
+ if __name__ == '__main__':
38
+ main()