#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright 2006 Alex Mufatti
# <alex.mufatti@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.

# To run this script you need simpy API library (http://simpytools.sourceforge.net). 
#
# Simply edit the two lines above. Then run the script and redirect 
# its output to bookmark.html. The file optained can be used with firefox.


# Begin of configuration lines

import simpy

# End od configuration lines

username = "your_simpy_user"
password = "your_simpy_pass"

class import_simpy:
	def __init__(self):
		client = simpy.SimpyClient(username, password)
		tags_get = client.getTags()
		print ("<!DOCTYPE NETSCAPE-Bookmark-file-1>\n<!-- This is an automatically generated file.\nIt will be read and overwritten.\nDO NOT EDIT! -->\n<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\">\n<TITLE>Bookmarks</TITLE>\n<H1>Bookmarks</H1>\n<DL>")
		for j, get_tag in enumerate(tags_get):
			links = client.getLinks( {'limit':20, 'q':'+tags:'+get_tag["tag"]} )
			print ("\t<DT><H3>"+get_tag["tag"]+"</H3>\n\t\t<DL>") 
			for i, link in enumerate(links):
				if link.title.encode("ascii","replace") == "":
					print("\t\t\t<DT><A HREF=\""+link.url+"\">"+link.url.encode("ascii","replace")+"</A>");
				else:
					print("\t\t\t<DT><A HREF=\""+link.url+"\">"+link.title.encode("ascii","replace")+"</A>");
			print ("\t\t</DL>")
		print("\t</DL>")



if __name__ == "__main__":
    import_book = import_simpy()
