awacke1 commited on
Commit
9bd0f62
·
verified ·
1 Parent(s): 81972f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -15
app.py CHANGED
@@ -20,22 +20,28 @@ def clean_bookmarks(html_content):
20
  url = link.get('href')
21
  domain = urlparse(url).netloc
22
  if domain in domain_url_dict:
23
- domain_url_dict[domain].add(url)
24
  else:
25
- domain_url_dict[domain] = {url}
26
 
27
  # Sort domains by count in descending order
28
  sorted_domains = sorted(domain_url_dict.items(), key=lambda item: domain_counts[item[0]], reverse=True)
29
 
30
  # Build cleaned HTML
31
  cleaned_html = '<html><body>\n'
32
- for domain, urls in sorted_domains:
33
- for url in urls:
34
- anchor_name = soup.find('a', href=url).text.strip()
 
 
 
35
  cleaned_html += f'<a href="{url}">{anchor_name}</a><br>\n'
 
 
 
36
  cleaned_html += '</body></html>'
37
 
38
- return cleaned_html
39
 
40
  def main():
41
  st.title('Bookmark File Cleaner')
@@ -44,10 +50,11 @@ def main():
44
 
45
  if uploaded_file is not None:
46
  html_content = uploaded_file.read().decode('utf-8')
47
- cleaned_html = clean_bookmarks(html_content)
48
 
49
  st.subheader('Cleaned Bookmarks')
50
  st.text_area('Output HTML', value=cleaned_html, height=400)
 
51
 
52
  output_file = 'cleaned_bookmarks.html'
53
  with open(output_file, 'w') as f:
@@ -57,33 +64,26 @@ def main():
57
 
58
  instructions = '''
59
  To export your Google Chrome bookmarks, including those on the bookmark bar, and curate the list, follow these steps:
60
-
61
  **Export bookmarks:**
62
-
63
  1. Open Google Chrome and click on the three-dot menu icon in the top-right corner.
64
  2. Go to "Bookmarks" > "Bookmark manager" or press Ctrl+Shift+O (Windows) or Cmd+Option+B (Mac).
65
  3. In the Bookmark Manager, click on the three-dot menu icon and select "Export bookmarks."
66
  4. Choose a location to save the HTML file containing your bookmarks and click "Save."
67
-
68
  **Curate the bookmarks:**
69
-
70
  1. Open the exported HTML file in a text editor like Notepad++ (Windows) or TextEdit (Mac).
71
  2. Locate the section containing your bookmarks. It will be enclosed within `<DL><p>` tags.
72
  3. Find the bookmark bar section, which is usually labeled with `<DT><H3 ADD_DATE="..." LAST_MODIFIED="...">Bookmarks bar</H3>`.
73
  4. Delete any unwanted bookmarks by removing the entire `<DT><A HREF="...">...</A>` line corresponding to that bookmark.
74
  5. Organize the remaining bookmarks by moving the `<DT><A HREF="...">...</A>` lines within the bookmark bar section.
75
  6. Save the edited HTML file.
76
-
77
  **Import the curated bookmarks:**
78
-
79
  1. In Google Chrome, open the Bookmark Manager again.
80
  2. Click on the three-dot menu icon and select "Import bookmarks."
81
  3. Choose the edited HTML file you saved in step 2 and click "Open."
82
  4. Your curated bookmarks will now be imported into Chrome, replacing the previous set of bookmarks.
83
-
84
  By following these steps, you can export your Google Chrome bookmarks, curate the list by removing unwanted bookmarks and organizing the remaining ones, and then import the curated list back into Chrome. This process allows you to keep your bookmark bar clean and organized with the bookmarks you use daily.
85
  '''
86
  st.markdown(instructions)
87
 
88
  if __name__ == '__main__':
89
- main()
 
20
  url = link.get('href')
21
  domain = urlparse(url).netloc
22
  if domain in domain_url_dict:
23
+ domain_url_dict[domain].append((url, link.text.strip()))
24
  else:
25
+ domain_url_dict[domain] = [(url, link.text.strip())]
26
 
27
  # Sort domains by count in descending order
28
  sorted_domains = sorted(domain_url_dict.items(), key=lambda item: domain_counts[item[0]], reverse=True)
29
 
30
  # Build cleaned HTML
31
  cleaned_html = '<html><body>\n'
32
+ cleaned_markdown = ''
33
+ for domain, url_anchors in sorted_domains:
34
+ cleaned_html += f'<h2>{domain}</h2>\n'
35
+ cleaned_markdown += f'## {domain}\n'
36
+ url_anchors.sort(key=lambda x: x[1]) # Sort URLs by anchor text
37
+ for url, anchor_name in url_anchors:
38
  cleaned_html += f'<a href="{url}">{anchor_name}</a><br>\n'
39
+ cleaned_markdown += f'[{anchor_name}]({url})\n'
40
+ cleaned_html += '<br>\n'
41
+ cleaned_markdown += '\n'
42
  cleaned_html += '</body></html>'
43
 
44
+ return cleaned_html, cleaned_markdown
45
 
46
  def main():
47
  st.title('Bookmark File Cleaner')
 
50
 
51
  if uploaded_file is not None:
52
  html_content = uploaded_file.read().decode('utf-8')
53
+ cleaned_html, cleaned_markdown = clean_bookmarks(html_content)
54
 
55
  st.subheader('Cleaned Bookmarks')
56
  st.text_area('Output HTML', value=cleaned_html, height=400)
57
+ st.text_area('Output Markdown', value=cleaned_markdown, height=400)
58
 
59
  output_file = 'cleaned_bookmarks.html'
60
  with open(output_file, 'w') as f:
 
64
 
65
  instructions = '''
66
  To export your Google Chrome bookmarks, including those on the bookmark bar, and curate the list, follow these steps:
 
67
  **Export bookmarks:**
 
68
  1. Open Google Chrome and click on the three-dot menu icon in the top-right corner.
69
  2. Go to "Bookmarks" > "Bookmark manager" or press Ctrl+Shift+O (Windows) or Cmd+Option+B (Mac).
70
  3. In the Bookmark Manager, click on the three-dot menu icon and select "Export bookmarks."
71
  4. Choose a location to save the HTML file containing your bookmarks and click "Save."
 
72
  **Curate the bookmarks:**
 
73
  1. Open the exported HTML file in a text editor like Notepad++ (Windows) or TextEdit (Mac).
74
  2. Locate the section containing your bookmarks. It will be enclosed within `<DL><p>` tags.
75
  3. Find the bookmark bar section, which is usually labeled with `<DT><H3 ADD_DATE="..." LAST_MODIFIED="...">Bookmarks bar</H3>`.
76
  4. Delete any unwanted bookmarks by removing the entire `<DT><A HREF="...">...</A>` line corresponding to that bookmark.
77
  5. Organize the remaining bookmarks by moving the `<DT><A HREF="...">...</A>` lines within the bookmark bar section.
78
  6. Save the edited HTML file.
 
79
  **Import the curated bookmarks:**
 
80
  1. In Google Chrome, open the Bookmark Manager again.
81
  2. Click on the three-dot menu icon and select "Import bookmarks."
82
  3. Choose the edited HTML file you saved in step 2 and click "Open."
83
  4. Your curated bookmarks will now be imported into Chrome, replacing the previous set of bookmarks.
 
84
  By following these steps, you can export your Google Chrome bookmarks, curate the list by removing unwanted bookmarks and organizing the remaining ones, and then import the curated list back into Chrome. This process allows you to keep your bookmark bar clean and organized with the bookmarks you use daily.
85
  '''
86
  st.markdown(instructions)
87
 
88
  if __name__ == '__main__':
89
+ main()