Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 25th, 2012  |  syntax: None  |  size: 1.36 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # Modify this configs with your credentials. See requirements.txt for required packages
  2. DB_PATH = '/path/to/memonic.db'
  3. ZT_USER = 'user'
  4. ZT_PASS = 'pass'
  5.  
  6. ZT_API_KEY = '8e3f989331c3d687a75b96d9e5505008'
  7.  
  8. from pyzootool import controller
  9. import sqlite3
  10.  
  11. zoocontrol = controller.ZooControl(apikey=ZT_API_KEY, username=ZT_USER, password=ZT_PASS)
  12.  
  13. try:
  14.     conn = sqlite3.connect(DB_PATH)
  15. except Exception:
  16.     print 'Can\'t open sqlite DB (%s)' % DB_PATH
  17.     exit(1)
  18. ci = conn.cursor()
  19. cu = conn.cursor()
  20. ct = conn.cursor()
  21.  
  22. ci.execute('select * from item')
  23. count = 0
  24. for item in ci:
  25.     title = item[2].encode('ascii', 'ignore')
  26.    
  27.     # get the link
  28.     cu.execute('select * from itemdata where item = "%s"' % item[0])
  29.     for data in cu:
  30.         if data[1] == 'source':
  31.             url = data[2].encode('ascii', 'ignore')
  32.    
  33.     # get the tags
  34.     ct.execute('select tag.title from tag inner join tag_item on tag.id = tag_item.tag where tag_item.item = "%s"' % item[0])
  35.     tags = ['memonic_import']
  36.     for tag in ct:
  37.         tags.append(tag[0].encode('ascii', 'ignore'))
  38.  
  39.     print '%u: %s - %s, %s' % (count, title, url, ', '.join(tags))
  40.    
  41.     try:
  42.         i = zoocontrol.item.add_item(url=url, title=title, tags=', '.join(tags))
  43.     except Exception:
  44.         print 'Wrong username/password, probably. :)'
  45.         exit(1)
  46.     count += 1
  47.  
  48. print '%u items imported from Memonic' % count