Skip to content

Instantly share code, notes, and snippets.

@shurru
Last active August 29, 2015 14:03
Show Gist options
  • Save shurru/baf93a333bfaba91185b to your computer and use it in GitHub Desktop.
Save shurru/baf93a333bfaba91185b to your computer and use it in GitHub Desktop.
@app.route('/retrieve', methods= ['GET'])
def retriever():
# can be made even more condensed (sure of it)
a= []
b=[]
run=[]
tim=[]
a2= []
b2=[]
run2=[]
tim2=[]
a3= []
b3=[]
run3=[]
tim3=[]
#appending to arrays
for i in xrange(1,4):
for post in posts.find({"run":i}, {"_id":0}):
if i== 1:
a.append(post["O1"])
b.append(post["O2"])
tim.append(post["date"])
run.append(post["run"])
if i==2:
a2.append(post["O1"])
b2.append(post["O2"])
tim2.append(post["date"])
run2.append(post["run"])
if i==3:
a3.append(post["O1"])
b3.append(post["O2"])
tim3.append(post["date"])
run3.append(post["run"])
# # saving as csv..
# #how to make this more smart
for r in xrange(1,4):
filename= "dat"+str(r)+ "O1.csv"
filename2= "dat"+str(r)+ "O2.csv"
with open(filename,'wb') as f:
writer= csv.writer(f)
if r==1:
rows= zip(tim, a)
if r==2:
rows= zip(tim2, a2)
if r==3:
rows= zip(tim3, a3)
for row in rows:
writer.writerow(row)
with open(filename2,'wb') as f2:
writer= csv.writer(f2)
if r==1:
rows= zip(tim, b)
if r==2:
rows= zip(tim2, b2)
if r==3:
rows= zip(tim3, b3)
for row in rows:
writer.writerow(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment