-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.py
More file actions
66 lines (53 loc) · 2.68 KB
/
Copy pathexample.py
File metadata and controls
66 lines (53 loc) · 2.68 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import os
import json
import re
import operator
from pymongo import MongoClient
from bson import Binary, Code
from bson.son import SON
DATABASENAME = 'kiranreddy92'
client = MongoClient('localhost', 27017)
db = client[DATABASENAME]
X = 89122
Y = 89117
if raw_input("Run find 5 star reviews?: ") == 'y':
search_zip_codes = {'full_address':{'$regex': "89122" + "|" + "89117"}}
result = db.yelp.business.find(search_zip_codes).count()
print(result)
if raw_input("find all the restaurents in city X?: ") == 'y':
X = str(raw_input("Enter name of the city: "))
search_city = {'city':{'$regex':X,'$options':'-i'}}
result=db.yelp.business.find(search_city).count()
print(result)
if raw_input("Find the restaurants within 5 miles of lat , lon:") == 'y':
restuarants = {"loc":{ "$geoWithin":{ "$center":[ [ -80.839186,35.226504] , .004 ] } }}
result=db.yelp.business.find(restuarants).count()
print(result)
if raw_input("Find all the reviews for restaurant X:") == 'y':
review = raw_input("Enter business id for the review: ")
review_count={'business_id':review}
result=db.yelp.review.find(review_count).count()
print(result)
if raw_input("Find all the reviews for restaurant X that are 5 stars :") == 'y':
review = raw_input("Enter business id for the review: ")
result=db.yelp.review.find({"business_id":review ,"stars":5}).count()
print(result)
if raw_input("Find all the users that have been 'yelping' for over 5 years :") == 'y':
yelp={"yelping_since" : { "$lt" : "2011-07"}}
result = db.yelp.user.find(yelp).count()
print(result)
if raw_input("Find the business that has the tip with the most likes :") == 'y':
result = dict(db.yelp.tip.find().sort('likes',-1).limit(1))
print(result)
if raw_input("Find the average review_count for users :") == 'y':
result = db.yelp.user.aggregate([{"$group": {"_id":"null", "avgReviewCountForUsers": {"$avg":"review_count"} } }])
print(result)
if raw_input("Find all the users that are considered elite :") == 'y':
result = db.yelp.user.find({"elite":{"$ne":[]}},{"_id":0,"user_id":1,"name":1,"elite":1})
print(result)
if raw_input("Find the longest elite user :") == 'y':
result = db.yelp.user.aggregate( [{"$unwind" : "$elite" },{ "$group" : { "_id" : "_id", "maxElite" : { "$sum" : 1 }} },{ "$sort" : { "maxElite" : -1 } },{ "$limit" : 13 }] )
print(result)
if raw_input("Find Of elite users, whats the average number of years someone is elite :") == 'y':
result = db.yelp.user.aggregate( [{ "$unwind" : "$elite" },{ "$group" : { _id : "$_id", maxElite : { "$sum" : 1 }} },{ "$avg" : { "maxElite" : -1 } },{ "$limit" : 13 }] )
print(result)