Beispiel #1
0
def add_place(name, phone, lat, lon, address, fs_id=None, yelp_id=None, wifi=None, plugs=None, exp=None):
    # ensure it has a fs_id or a yelp_id
    if not (fs_id or yelp_id):
        return ErrorResponse.POST_INVALID_ARGS_FS_ID_YELP_ID
    
    # Create a review dict
    review = make_review_dict(wifi, plugs, exp)  
    
    # Check if place already exists in the database
    if fs_id:
        spec = {Place.A_FS_ID: fs_id}
        place_dict = Place.mdbc().find_one(spec)
        
        # If place exists add a review to it
        if place_dict:
            place_id = place_dict.get(Place.A_FS_ID)
            return Place.review_place(place_id=place_id, review=review)
        
    # If place doesn't already exist in the database add it
    place_data = {
          Place.A_NAME: name,
          Place.A_FS_ID: fs_id,
          Place.A_YELP_ID: yelp_id,
          Place.A_ADDRESS: address,
          Place.A_LOCATION: [float(lat), float(lon)]
    }
    
    # Only add phone if it's not null
    if phone:
        place_data[Place.A_PHONE] = phone
    
    return Place.add_place(place_data=place_data, review=review)
Beispiel #2
0
def test_post():
    if not Place.mdbc().count() == 0:
        Place.mdbc().remove()

    # Add new place
    url = "http://localhost/places"
    payload = {
        "fs_id": "aslfkj13409182491k1we1-12e801",
        "name": "Ninth Street Espresso",
        "phone": "2129201880",
        "lat": "42.881111",
        "lon": "78.191111",
        "address": "180 Crosby Street",
        "wifi": "2",
        "plugs": "1",
    }
    r = requests.post(url=url, data=payload)
    spec = r.content
    spec_js = json.loads(spec)
    place_id = spec_js.get("place_id")

    # Add another review to previous place
    payload = {"place_id": place_id, "wifi": "0", "plugs": "0"}
    r = requests.post(url=url, data=payload)

    # Add another review to previous place
    payload = {"place_id": place_id, "wifi": "0", "plugs": "0"}
    r = requests.post(url=url, data=payload)

    # Add new place
    payload = {
        "fs_id": "12e801",
        "name": "The Bean",
        "phone": "2129201881",
        "lat": "42.881111",
        "lon": "78.191111",
        "address": "180 Crosby Street",
        "wifi": "2",
        "plugs": "1",
    }
    r = requests.post(url=url, data=payload)
    r.content

    # Add new place
    payload = {
        "fs_id": "12801",
        "name": "The Native Bean",
        "phone": "2129202880",
        "lat": "42.881111",
        "lon": "78.191111",
        "address": "180 Crosby Street",
        "wifi": "1",
        "plugs": "1",
    }
    r = requests.post(url=url, data=payload)
    r.content

    # Add new place
    payload = {
        "fs_id": "12801",
        "name": "Gimme Coffee",
        "phone": "2129201980",
        "lat": "42.881111",
        "lon": "78.191111",
        "address": "180 Crosby Street",
        "wifi": "0",
        "plugs": "1",
    }
    r = requests.post(url=url, data=payload)
    r.content

    # Add new place
    payload = {
        "fs_id": "12801",
        "name": "Gimme Coffee Now",
        "phone": "3129201980",
        "lat": "43.881111",
        "lon": "79.191111",
        "address": "180 Crosby Street",
        "wifi": "0",
        "plugs": "1",
    }
    r = requests.post(url=url, data=payload)
    r.content
    print "Database_count = " + str(Place.mdbc().count())