-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.py
More file actions
37 lines (27 loc) · 783 Bytes
/
search.py
File metadata and controls
37 lines (27 loc) · 783 Bytes
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
import pymongo
import sys
def search(query):
obj={}
connection = pymongo.Connection("localhost", 27017)
db = connection['newdata']
collection = db['collection']
query = db.collection.find({"$and":[{"Title": {"$regex": query}},{ 'PostTypeId' : '1'}, { 'AnswerCount' : '0'}] })
ctr = 0
counter=0
for data in query:
post_id = data['PostTypeId']
answer_count = data['AnswerCount']
if ( ctr > 15):
break
ctr+=1
title = data['Title']
Id = data['Id']
obj = {}
obj['Id'] = Id
obj['Title'] = title
print obj
def main(argv):
query = sys.argv[1]
search(query);
if __name__ == '__main__':
main(sys.argv[1:])