diff --git a/qbqmb/qbtoff-en.py b/qbqmb/qbtoff-en.py new file mode 100644 index 0000000..bd59741 --- /dev/null +++ b/qbqmb/qbtoff-en.py @@ -0,0 +1,65 @@ +from urllib.parse import urlparse + +# Function to generate a bookmark line in HTML format +def generate_bookmark(title, url): + return f'
{title}\n' + +# Dictionary to store folders and their bookmarks +folders = {} + +# Path to your source file +file_path = 'bookmarks.txt' + +# Read the file and process each line +with open(file_path, 'r', encoding='utf-8') as file: + lines = file.readlines() + +default_folder = "Others" # Default folder for lines without a folder prefix + +urls_seen = set() + +for line in lines: + line = line.strip() # Remove leading/trailing whitespace + parts = line.rsplit(" ", 1) # Split URL from the rest of the line + if len(parts) == 2: + url = parts[-1] + if url not in urls_seen: + urls_seen.add(url) + title = parts[0] + if " - " in title: + folder_name = title.split(" - ", 1)[0] # Extract folder name + title = title.split(" - ", 1)[1] # Extract title without folder prefix + else: + folder_name = default_folder + if folder_name not in folders: + folders[folder_name] = [] + folders[folder_name].append(generate_bookmark(title, url)) + else: + print(f"Ignored duplicate: {line}") + else: + # Handle malformed or improperly formatted lines + print(f"Ignored line: {line}") + +# Generate HTML content +html_content = """ + +Imported Bookmarks +

Imported Bookmarks

+

\n""" + +# Add folders and their bookmarks to the HTML content +for folder, bookmarks in folders.items(): + html_content += f'

{folder}

\n

\n' + for bookmark in bookmarks: + html_content += bookmark + html_content += "

\n" + +html_content += "

\n" + +# Write content to an HTML file +output_file = "bookmarks.html" +with open(output_file, "w", encoding="utf-8") as file: + file.write(html_content) + +print(f"Conversion completed. HTML file generated successfully: {output_file}") + diff --git a/qbqmb/qbtoff-fr.py b/qbqmb/qbtoff-fr.py new file mode 100644 index 0000000..a5885d4 --- /dev/null +++ b/qbqmb/qbtoff-fr.py @@ -0,0 +1,65 @@ +from urllib.parse import urlparse + +# Fonction pour générer une ligne de marque-page au format HTML +def generate_bookmark(title, url): + return f'

{title}\n' + +# Dictionnaire pour stocker les dossiers et leurs marque-pages +folders = {} + +# Chemin vers votre fichier source +file_path = '/home/t0mux/Sync/Conf/qb/quickmarks' + +# Lecture du fichier et traitement des lignes +with open(file_path, 'r', encoding='utf-8') as file: + lines = file.readlines() + +default_folder = "Autres" # Dossier par défaut pour les lignes sans préfixe de dossier + +urls_seen = set() + +for line in lines: + line = line.strip() # Supprime les espaces inutiles autour de la ligne + parts = line.rsplit(" ", 1) # Sépare l'URL du reste de la ligne + if len(parts) == 2: + url = parts[-1] + if url not in urls_seen: + urls_seen.add(url) + title = parts[0] + if " - " in title: + folder_name = title.split(" - ", 1)[0] # Extrait le nom du dossier + title = title.split(" - ", 1)[1] # Extrait le titre sans le dossier + else: + folder_name = default_folder + if folder_name not in folders: + folders[folder_name] = [] + folders[folder_name].append(generate_bookmark(title, url)) + else: + print(f"Doublon ignoré : {line}") + else: + # Gérer les lignes mal formées ou non conformes au format attendu + print(f"Ligne ignorée : {line}") + +# Génère le contenu HTML +html_content = """ + +Marque-pages importés +

Marque-pages importés

+

\n""" + +# Ajoute les dossiers et leurs marque-pages au contenu HTML +for folder, bookmarks in folders.items(): + html_content += f'

{folder}

\n

\n' + for bookmark in bookmarks: + html_content += bookmark + html_content += "

\n" + +html_content += "

\n" + +# Écrit le contenu dans un fichier HTML +output_file = "marque_pages.html" +with open(output_file, "w", encoding="utf-8") as file: + file.write(html_content) + +print(f"Conversion terminée. Fichier HTML généré avec succès : {output_file}") +