Skip to content

Instantly share code, notes, and snippets.

@mgmarino
Created March 25, 2014 16:10
Show Gist options
  • Save mgmarino/9765207 to your computer and use it in GitHub Desktop.
Save mgmarino/9765207 to your computer and use it in GitHub Desktop.
General read with time range for all data, and only one variable.
import cloudant
# Authentication
acct = cloudant.Account(uri="http://raid.nedm1:5984")
res = acct.login("username", "password")
assert res.status_code == 200
# Grab the correct database
db = acct["nedm%2Factive_coil_compensation"]
# Reads all data from a certain time
des = db.design("slow_control_time_label")
the_view = des.view("slow_control_time_label")
results = the_view.get(params=dict(descending=True,
endkey=[2014, 2, 25, 12, 40],
startkey=[{}]
)
).json()
stripped_results = [(i["key"], i["value"]) for i in results["rows"]]
for i in stripped_results: print i
# Can read all data with a certain key from a certain time
des = db.design("slow_control_time")
the_view = des.view("slow_control_time")
results = the_view.get(params=dict(descending=True,
endkey=['FieldMap_63', 2014, 2, 25, 12, 40],
startkey=['FieldMap_63', {}],
reduce=False
)
).json()
stripped_results = [(i["key"], i["value"]) for i in results["rows"]]
for i in stripped_results: print i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment