Created
November 6, 2011 13:17
-
-
Save danielrichman/1342864 to your computer and use it in GitHub Desktop.
CouchDB tail: follow couchdb changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Copyright Daniel Richman 2011. License: GNU GPL 3 | |
import sys | |
import couchdbkit | |
import json | |
import pygments | |
import pygments.lexers.web | |
import pygments.formatters | |
lexer = pygments.lexers.web.JavascriptLexer() | |
formatter = pygments.formatters.TerminalFormatter(bg="dark") | |
def change_callback(change): | |
doc = change["doc"] | |
pretty = json.dumps(doc, sort_keys=True, indent=4) | |
print "Change", change["seq"] | |
print pygments.highlight(pretty, lexer, formatter) | |
def main(): | |
if len(sys.argv) != 3: | |
print "Usage: {0} server database".format(sys.argv[0]) | |
sys.exit(1) | |
server = couchdbkit.Server(sys.argv[1]) | |
db = server[sys.argv[2]] | |
consumer = couchdbkit.Consumer(db) | |
info = db.info() | |
seq = info["update_seq"] - 10 | |
consumer.wait(change_callback, since=seq, include_docs=True, | |
heartbeat=30000) | |
sys.exit(0) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment