Skip to content

Instantly share code, notes, and snippets.

@segphault
Created December 5, 2009 02:27
Show Gist options
  • Select an option

  • Save segphault/249518 to your computer and use it in GitHub Desktop.

Select an option

Save segphault/249518 to your computer and use it in GitHub Desktop.
Monitor changes in Desktop CouchDB
#!/usr/bin/env python
import desktopcouch, pycurl, urllib, oauth
OAUTH_DATA = desktopcouch.local_files.get_oauth_tokens()
def build_request(path, params, odata=OAUTH_DATA):
url = "http://localhost:%s/%s?%s" % (desktopcouch.find_port(), path, urllib.urlencode(params))
oconsumer = oauth.oauth.OAuthConsumer(odata["consumer_key"], odata["consumer_secret"])
otoken = oauth.oauth.OAuthToken(odata["token"], odata["token_secret"])
oreq = oauth.oauth.OAuthRequest.from_consumer_and_token(oconsumer, otoken, None, None, "GET", url, params)
oreq.sign_request(oauth.oauth.OAuthSignatureMethod_HMAC_SHA1(), oconsumer, otoken)
return oreq.to_url()
url = build_request("gwibber3_test/_changes", {"feed": "continuous", "heartbeat": "10000"})
def on_receive_data(*args):
print "Received:", args
curl = pycurl.Curl()
curl.setopt(pycurl.URL, url)
curl.setopt(pycurl.WRITEFUNCTION, on_receive_data)
curl.perform()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment