Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import mysql.connector
  4. import getpass
  5. import cgi
  6. import sys
  7.  
  8. mysqlpass = getpass.getpass("password for mysql: ", sys.stderr)
  9.  
  10. cnx = mysql.connector.connect(user='root',
  11. password=mysqlpass,
  12. host='127.0.0.1',
  13. database='scuttle')
  14.  
  15.  
  16. class Bookmark(object):
  17. def __init__(self, title, description, address):
  18. self.tags = []
  19. self.title = title
  20. self.description = description
  21. self.address = address
  22.  
  23. cursor = cnx.cursor()
  24. cursor.execute("SELECT bTitle,bDescription,bAddress,bId FROM sc_bookmarks;")
  25. bookmarks = dict((bId, Bookmark(bTitle,bDescription,bAddress))
  26. for (bTitle,bDescription,bAddress,bId) in cursor)
  27. cursor.close()
  28.  
  29.  
  30. cursor = cnx.cursor()
  31. cursor.execute("SELECT bId,tag FROM sc_tags;")
  32. for (bId,tag) in cursor:
  33. if not tag.startswith('system:'):
  34. bookmarks[bId].tags.append(tag)
  35. cursor.close()
  36.  
  37.  
  38. for bookmark in bookmarks.values():
  39.  
  40. print u'<A DESCRIPTION="{description}" TAGS="{tags}" HREF="{url}">{title}</A>'.format(
  41. tags=cgi.escape(','.join(bookmark.tags)),
  42. url=bookmark.address,
  43. title=cgi.escape(bookmark.title),
  44. description=cgi.escape(bookmark.description)).encode('utf-8')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement