razzmataz avatar 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.

Comments (0)

Files changed (2)

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
+
+

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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.