├── README.md └── ffbbe.py /README.md: -------------------------------------------------------------------------------- 1 | The reason i made this little script can be found in [this post](http://www.ovalerio.net/content/node/45) 2 | 3 | How to use it 4 | ============= 5 | 6 | in the folder of the script type: 7 | 8 | python ffbbe.py input.json output.adr 9 | 10 | where 'input.json' is your firefox's bookmark file and 'output.adr' is the new file to be created. 11 | 12 | Now you just have to open your Opera browser and import the bookmarks using the new file you have just created. 13 | 14 | 15 | Improvements 16 | ============ 17 | 18 | Other browsers and formats would be a nice feature to add (may be in the near future). 19 | 20 | 21 | Licence 22 | ======= 23 | 24 | You are free to do whatever you want with it. -------------------------------------------------------------------------------- /ffbbe.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import sys 4 | import simplejson 5 | import codecs 6 | 7 | # 8 | # GET the data from the source file 9 | # 10 | 11 | 12 | def getsource(string): 13 | f = codecs.open(string, 'r', 'utf-8') 14 | source = '[' + f.readline() + ']' # make the string look like a list 15 | f.close() 16 | return source 17 | 18 | 19 | # 20 | # Filter with the wanted fields 21 | # 22 | 23 | def filtersource(source): 24 | try: 25 | raw_data = simplejson.loads(source) # Parse the data like a json list 26 | except: 27 | print "- Invalid input (backup) file" 28 | exit(0) 29 | final = [] 30 | for item in raw_data: 31 | final.append(getElements(item)) # build temporary data representation 32 | return final 33 | 34 | 35 | def getElements(item): # with recursion gets children and base info 36 | childs = [] 37 | if 'children' in item: 38 | for child in item['children']: 39 | childs.append(getElements(child)) 40 | 41 | if 'uri' in item: 42 | return {'title': item['title'], 'uri': item['uri']} 43 | else: 44 | return {'title': item['title'], 'children': childs} 45 | 46 | 47 | # 48 | # PRINT THE OUTPUT 49 | # 50 | def outputdata(data, location): 51 | toprint = [] 52 | for element in data: 53 | printElement(element, toprint) 54 | 55 | f = codecs.open(location, 'w', 'utf-8') 56 | f.write("Opera Hotlist version 2.0\nOptions: encoding = utf8, version=3\n") 57 | for line in toprint: 58 | f.write(line) 59 | f.close() 60 | 61 | 62 | def printElement(element, toprint): # with recursion add to print list the items 63 | if 'uri' in element: 64 | item = '#URL\n\tNAME=' + element['title'] + '\n\tURL=' + element['uri'] + '\n' 65 | toprint.append(item) 66 | else: 67 | item = '#FOLDER\n\tNAME=' + element['title'] + '\n' 68 | toprint.append(item) 69 | for child in element['children']: 70 | printElement(child, toprint) 71 | toprint.append('-\n') 72 | 73 | 74 | # 75 | # Main function 76 | # 77 | def extract(argv): 78 | if len(argv) >= 3: 79 | try: 80 | s = getsource(argv[1]) 81 | except: 82 | print "- The source file doesn't exist" 83 | exit(0) 84 | info = filtersource(s) 85 | outputdata(info, argv[2]) 86 | else: 87 | print "Not enough arguments" 88 | print "Usage:" 89 | print "\t python ffbbe BACKUP.json DESTINY.adr" 90 | 91 | 92 | if __name__ == '__main__': 93 | extract(sys.argv) 94 | --------------------------------------------------------------------------------