def post(self): """ This gives only the limited eatery list like the top on the basis of the reviews count """ lat = float(self.get_argument("lat")) long = float(self.get_argument("long")) print self.get_argument("range") range = self.get_argument("range") if not range: range = 5 else: range = int(range) projection = { "eatery_id": True, "eatery_name": True, "eatery_address": True, "eatery_coordinates": True, "eatery_total_reviews": True, "_id": False } #result = eateries.find({"eatery_coordinates": {"$near": [lat, long]}}, projection).sort("eatery_total_reviews", -1).limit(10) result = eateries.find({"eatery_coordinates" : SON([("$near", { "$geometry" : SON([("type", "Point"), ("coordinates", [lat, long]), \ ("$maxDistance", range)])})])}, projection).limit(10) __result = list(result) print __result self.write({ "success": True, "error": False, "result": __result, }) self.finish()
def get(self): time.sleep(20) result = list(eateries.find(fields= {"eatery_id": True, "_id": False, "eatery_name": True, \ "area_or_city": True}).limit(14).sort("eatery_total_reviews", -1)) for element in result: eatery_id = element.get("eatery_id") element.update( {"reviews": reviews.find({ "eatery_id": eatery_id }).count()}) yelp_result = list( yelp_eateries.find( fields={ "eatery_id": True, "_id": False, "eatery_name": True, "area_or_city": True }).limit(5).sort("eatery_total_reviews", -1)) for element in yelp_result: eatery_id = element.get("eatery_id") element.update({ "reviews": yelp_reviews.find({ "eatery_id": eatery_id }).count() }) self.write({ "success": True, "error": False, "result": result + yelp_result, })
def get(self): """ This gives only the limited eatery list like the top on the basis of the reviews count """ projection = { "eatery_id": True, "eatery_name": True, "eatery_address": True, "eatery_coordinates": True, "eatery_total_reviews": True, "_id": False } result = [ eatery for eatery in list( eateries.find({ "eatery_area_or_city": "ncr" }, projection).limit(100).sort("eatery_total_reviews", -1)) if eatery.get("eatery_coordinates") ] self.write({ "success": True, "error": False, "result": result, }) self.finish()
def post(self): """ Returns eateries on the basis of the character starting the name of the eatery """ page_num = int(self.get_argument("page_num")) skip = page_num * 10 projection = { "eatery_id": True, "eatery_name": True, "eatery_address": True, "eatery_coordinates": True, "_id": False, "trending_factor": True } result = [eatery for eatery in list(eateries.find({"eatery_area_or_city": "ncr"}, projection).skip(skip).limit(10).sort("eatery_total_reviews", -1)) \ if eatery.get("eatery_coordinates")] def highest_trending(eatery_data, category): result = sorted( [[eatery_data[category][key].get("trending_factor"), key] for key in eatery_data[category].keys()], reverse=True, key=lambda x: x[0]) if not "null" in result[0][1].split("-"): return result[0][1] return result[1][1] for eatery in result: eatery_data = eateries_results_collection.find_one( {"eatery_id": eatery.get("eatery_id")}) sorted_by_trending = sorted(eatery_data["food"]["dishes"], reverse=True, key=lambda x: x.get("trending_factor")) if eatery_data: try: eatery.update( {"trending1": sorted_by_trending[0].get("name")}) eatery.update( {"trending2": sorted_by_trending[1].get("name")}) except Exception as e: print e eatery.update({"trending1": "Not enough data"}) eatery.update({"trending2": "Not enough data"}) eatery.update({"cost": highest_trending(eatery_data, "cost")}) eatery.update( {"service": highest_trending(eatery_data, "service")}) eatery.update( {"ambience": highest_trending(eatery_data, "ambience")}) else: eatery.update({"trending1": "abc"}) eatery.update({"trending2": "def"}) print result self.write({ "success": True, "error": False, "result": result, }) self.finish()
#!/usr/bin/env python from pymongo import GEO2D from GlobalConfigs import eateries eateries.create_index([("eatery_coordinates", GEO2D)]) eateries.ensure_index([("eatery_coordinates", pymongo.GEOSPHERE)]) for e in eateries.find({"eatery_coordinates": {"$near": [latitude, longitude]}}).limit(5): print e.get("eatery_coordinates"), e.get("eatery_name")