Exemplo n.º 1
0
def put_fsq_venue(user_id, brand_name, venue_id):
    url = "%s/%s" % ("venues", venue_id)
    brand_obj = get_brand_mapping(user_id, brand_name)
    api = FoursquareAPI(brand_obj.foursquare["access_token"])
    data = api.request(url)
    v = data["response"]

    venue = FSQVenue()
    venue.venue_id = v["venue"]["id"]
    venue.name = v["venue"]["name"]
    venue.fields = v

    dupe_obj = FSQVenue.collection().find_one({"venue_id": v["venue"]["id"]})
    if dupe_obj is None:
        FSQVenue.collection().insert(venue.serialize())
    else:
        FSQVenue.collection().update({"venue_id": v["venue"]["id"]}, venue.serialize())
        venue = FSQVenue.unserialize(FSQVenue.collection().find_one({"venue_id": v["venue"]["id"]}))

    BrandMapping.collection().update({"uid": user_id, "brand_name": brand_name}, {"$push": {"foursquare.venues": v["venue"]["id"]}})

    t = Thread(target=load_fsq_tips_to_db, args=(v["venue"]["id"], brand_obj.foursquare["access_token"]))
    t.setDaemon(False)
    t.start()

    return venue
Exemplo n.º 2
0
def get_fsq_venues_managed(user_id, brand_name):
    url = "venues/managed"
    brand_obj = get_brand_mapping(user_id, brand_name)
    api = FoursquareAPI(brand_obj.foursquare["access_token"])
    data = api.request(url)

    return data["response"]["venues"]["items"]
Exemplo n.º 3
0
def del_fsq_update(update_id, obj_id, access_token):
    if update_id is not None:
        url = "%s/%s/%s" % ('pageupdates', update_id, 'delete')
        api = FoursquareAPI(access_token)

        dict = {"update_id": update_id}

        data = api.request(url, post_args=dict)
        print data

    FSQPageUpdate.collection().update({"_id": coerce_bson_id(obj_id)}, {"$set": {"is_deleted": 1}})
Exemplo n.º 4
0
def update_venue(venue_id, access_token, name=None, address=None, phone=None, description=None, hours=None):
    url = "%s/%s/%s" % ('venues', venue_id, 'edit')
    api = FoursquareAPI(access_token)

    dict = {}

    if name is not None:
        dict["name"] = name
    if address is not None:
        dict["address"] = address
    if phone is not None:
        dict["phone"] = phone
    if description is not None:
        dict["description"] = description
    if hours is not None:
        pass

    print dict
    data = api.request(url, post_args=dict)
    print data
Exemplo n.º 5
0
def put_fsq_update(shout, venue_id, access_token, state):
    datetime_now = datetime.datetime.utcnow().isoformat('T')
    page_update = FSQPageUpdate()
    page_update.venue_id = venue_id
    page_update.shout = shout
    page_update.createdAt = datetime_now
    page_update.fields = {"shout": shout}

    if state == CampaignState.PUBLISHED:
        venue = FSQVenue.collection().find_one({"venue_id": venue_id})

        url = "%s/%s" % ("pageupdates", "add")
        api = FoursquareAPI(access_token)
        dict = {"pageId": venue["fields"]["venue"]["venuePage"]["id"],
                "venueId": venue_id,
                "shout": shout}
        data = api.request(url, post_args=dict)
        page_update.fields = data["response"]["pageUpdate"]
        page_update.update_id = data["response"]["pageUpdate"]["id"]

    page_update._id = FSQPageUpdate.collection().insert(page_update.serialize())
    return page_update