#!/usr/bin/env python # -*- coding:Utf-8 -*- # thuban # # add this line to menu.xml # # # be careful not to use the id 2 in another menu to avoid conflicts ####################################################################### # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. ######################################################################## import os from xml.etree import ElementTree as ET browser = 'midori' bookmarks = os.path.expanduser('~/.config/midori/bookmarks.xbel') def print_label(title, url): print(''.format(title.encode('utf-8'))) print( '') print( '{0} {1}'.format(browser, url)) print( '') print( '') def print_submenu(title,titleList, urlList): print(''.format(str(title.encode('utf-8'))+'6666',str(title).encode('utf-8'))) if len(titleList) > 0: for i in range(len(titleList)): print_label(titleList[i], urlList[i]) print('') def print_bookmarks(elem): '''print les bookmarks avec leur url''' t = elem.getiterator('title') u = elem.getiterator('bookmark') for i in range(len(u)): print_label(t[i].text, u[i].get('href')) def print_folder_menu(folder): folderTitle = folder[0].getiterator('title')[0].text urls, titles = [], [] if len(folder[1:]) > 0: for i in folder[1:]: u = i.getiterator('bookmark') t = i.getiterator('title') for i in t: titles.append(i.text) for i in u: urls.append(i.get('href')) print_submenu(folderTitle, titles, urls) def rbuild_tree(id, bookmarks): '''Crée le menu openbox à partir d'une liste d'éléments''' tree = ET.parse(bookmarks).getroot() folderList = tree.getiterator('folder') print('') for folder in folderList: tree.remove(folder) print_folder_menu(folder) print_bookmarks(tree) print('') def main(): rbuild_tree(2, bookmarks) if __name__ == '__main__': main()