-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreadDB.py
executable file
·44 lines (40 loc) · 1.44 KB
/
readDB.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from pymongo import MongoClient
import scipy.io.wavfile as wav
import numpy as nd
from bson import BSON
from bson.binary import Binary
import pickle
class ReadAudio:
def __init__(self,db,collection,querylist): #Constructor to initialize info requied for write operation
self.con = MongoClient('localhost',27017)
self.db = eval ('self.con.' + db)
self.collection = collection
self.querylist = querylist
def read_data(self):
if self.querylist[0] == 0: # For individual queries
query = 'db' + '.' + self.collection + '.' + self.querylist[1]
db = self.db
print query
return eval(query)
# if self.querylist[0] == 1: # For multiple queries to be executed by a single object
# def update_tags(self, ref, newUser):
# db = self.db
# db.UserNames.update_one({'_id':1}, {'$push': {'UserName':newUser}})
# print "done"
if __name__ == '__main__':
prepared_query = [0,'find()']
# update_tags('not_imp','TestUser5')
obj = ReadAudio('sbSVB','UserNames',prepared_query)
Name = "TestUser1"
# obj.update_tags('not_imp','TestUser6')
cursor = obj.read_data()
for temp in cursor:
print temp
data = temp['UserName']
if Name in data:
print "found"
else:
print "not found"
# temp = pickle.loads(data)
# wav.write("test.wav",44100,temp)
#