Commits

razzmataz  committed 76c05ed

added in small scripts for importing delicious xml dumps into couchdb.
scripts were scrubbed of local info, options added for specifying
the url of the couchdb server and so on.

  • Participants
  • Parent commits 1b23d3e

Comments (0)

Files changed (2)

File utils/couch-scripts/delp.py

+#!/usr/bin/env python
+
+# for loading delicious xml dump into couchdb
+
+import xml.etree.ElementTree as etree
+import sys
+import couchdb
+from uuid import uuid4
+from optparse import OptionParser
+
+parser = OptionParser()
+parser.add_option("-u","--url", dest="url", help="couchdb server url", metavar="URL")
+parser.add_option("-d","--db-name", dest="dbname", help="couchdb name",
+                  metavar="DBNAME", default='bookmarks')
+
+(options, args) = parser.parse_args()
+
+dfile = args[0]
+e = etree.ElementTree(file=dfile)
+serverUrl = options.url
+dbName = options.dbname
+
+server = couchdb.client.Server(serverUrl)
+db = server[dbName]
+
+for item in e.getroot().getchildren():
+    print item
+    doc_id = uuid4().hex
+    bookmark = dict()
+    for k,v in item.items():
+        print "key %s : %s" % (k, v)
+        bookmark[k] = v
+    db[doc_id] =  bookmark
+
+

File utils/couch-scripts/query-tags.py

+#!/usr/bin/env python
+
+import sys
+import couchdb
+import re
+from optparse import OptionParser
+
+parser = OptionParser()
+parser.add_option("-u","--url", dest="url", help="couchdb server url", metavar="URL")
+parser.add_option("-d","--db-name", dest="dbname", help="couchdb name",
+                  metavar="DBNAME", default='bookmarks')
+
+(options, args) = parser.parse_args()
+
+
+serverUrl = options.url
+dbName = options.dbname
+
+server = couchdb.client.Server(serverUrl)
+db = server[dbName]
+
+map_query =''' function(doc) {
+    emit(doc.tags,null);
+}
+'''
+
+tagDict = dict()
+
+for row in db.view('_all_docs'):
+    #print row.tags
+    doc = db[row.id]
+    tags = None
+    if 'tag' in doc:
+        tags = re.split(r'( )+',doc['tag'])
+        #print len(tags) 
+        for t in tags:
+            if t in tagDict:
+                tagDict[t] += 1
+            else:
+                tagDict[t] = 1
+
+
+tagCount = 0
+for t in tagDict:
+    print "%s : %s" % (t, tagDict[t])
+    tagCount += 1
+
+print "%s tags" % tagCount