Created
July 4, 2013 13:12
-
-
Save danielrichman/5927611 to your computer and use it in GitHub Desktop.
miscellaneous habitat convenience shell scripts
This file contains hidden or 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
#!/home/daniel/venv/bin/python | |
import sys | |
import os | |
import couchdbkit | |
password_filename = os.path.join(os.path.dirname(sys.argv[0]), 'couch') | |
with open(password_filename) as f: | |
couch_uri = f.readline().strip() | |
server = couchdbkit.Server(couch_uri) | |
db = server["habitat"] | |
if len(sys.argv) != 2: | |
print "Usage: {0} doc_id\n".format(sys.argv[0]) | |
sys.exit(1) | |
doc = db[sys.argv[1]] | |
assert not doc["approved"] | |
doc["approved"] = True | |
db.save_doc(doc) |
This file contains hidden or 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
#!/home/daniel/venv/bin/python | |
import sys | |
import os | |
import json | |
import couchdbkit | |
password_filename = os.path.join(os.path.dirname(sys.argv[0]), 'couch') | |
with open(password_filename) as f: | |
couch_uri = f.readline().strip() | |
server = couchdbkit.Server(couch_uri) | |
db = server["habitat"] | |
if len(sys.argv) != 2: | |
print "Usage: {0} doc_id\n".format(sys.argv[0]) | |
sys.exit(1) | |
doc = db[sys.argv[1]] | |
relevant_docs_view = db.all_docs(keys=doc["payloads"], include_docs=True) | |
relevant_docs = [doc] + [r["doc"] for r in relevant_docs_view] | |
for d in relevant_docs: | |
json.dump(d, sys.stdout, indent=4) | |
sys.stdout.write("\n") |
This file contains hidden or 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
#!/home/daniel/venv/bin/python | |
import sys | |
import os | |
import time | |
import couchdbkit | |
password_filename = os.path.join(os.path.dirname(sys.argv[0]), 'couch') | |
with open(password_filename) as f: | |
couch_uri = f.readline().strip() | |
server = couchdbkit.Server(couch_uri) | |
db = server["habitat"] | |
if len(sys.argv) not in (2, 3): | |
print "Usage: {0} [flight_id] payload_configuration_id\n" \ | |
.format(sys.argv[0]) | |
sys.exit(1) | |
view = db.view("payload_telemetry/{0}payload_time" | |
.format("flight_" if len(sys.argv) == 3 else ""), | |
startkey=sys.argv[1:], endkey=sys.argv[1:] + [{}], | |
include_docs=True) | |
print "Reparsing", len(view), "docs; sleeping 0.5s inbetween" | |
for row in view: | |
doc = row["doc"] | |
data = {} | |
for key in ("_raw", "_fallbacks"): | |
if key in doc["data"]: | |
data[key] = doc["data"][key] | |
doc["data"] = data | |
print "Reparsing", doc["_id"] | |
db.save_doc(doc) | |
time.sleep(0.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment