Exemple #1
0
def update_fb_event(event_id, page, state, title, description, start_time, end_time):
    datetime_now = datetime.datetime.utcnow().isoformat("T")
    event = FBEvent.collection().find_one({"event_id": event_id})
    event["fields"]["name"] = title
    event["fields"]["description"] = description
    event["updated_time"] = datetime_now

    if start_time is not None:
        event["fields"]["start_time"] = isoformat(start_time)
    if end_time is not None:
        event["fields"]["end_time"] = isoformat(end_time)

    if state == CampaignState.PUBLISHED:
        api = GraphAPI(page["access_token"])
        url = event_id

        dict = {
            "name": title,
            "start_time": isoformat(start_time) + "Z",
            "description": strip_tags(replace_newline(description)),
        }

        if end_time is not None:
            dict["end_time"] = isoformat(end_time) + "Z"

        api.request(url, post_args=dict)
        event_data = api.request(event_id)
        event = save_fb_event(event_data, page["id"])
    else:
        FBEvent.collection().update({"event_id": event_id}, {"$set": {event}})
        event = FBEvent.unserialize(FBEvent.collection().find_one({"event_id": event_id}))

    return event
Exemple #2
0
def put_fb_event(page, fb_id, state, title, description, start_time, end_time, media_file=None):
    datetime_now = datetime.datetime.utcnow().isoformat("T")
    event = FBEvent()
    event.page_id = page["id"]
    event.owner = {"id": fb_id}
    event.fields = {"name": title, "description": description}
    event.created_time = datetime_now
    event.updated_time = datetime_now

    if start_time is not None:
        event.fields["start_time"] = isoformat(start_time)
    if end_time is not None:
        event.fields["end_time"] = isoformat(end_time)

    if state == CampaignState.PUBLISHED:
        api = GraphAPI(page["access_token"])
        url = "%s/%s" % (page["id"], "events")

        # todo : note the start and end UTC time formats, currently hard-coded +0000
        dict = {
            "name": title,
            "start_time": isoformat(start_time) + "Z",
            "description": strip_tags(replace_newline(description)),
        }

        if end_time is not None:
            dict["end_time"] = isoformat(end_time) + "Z"

        if media_file:
            dict["source"] = media_file
            dict["access_token"] = page["access_token"]
            event.event_id = api.put_event(dict)["id"]
        else:
            event.event_id = api.request(url, post_args=dict)["id"]

        event_data = api.request(event.event_id)
        print "event data"
        print event_data
        event = save_fb_event(event_data, page["id"])
    else:
        event._id = FBEvent.collection().insert(event.serialize())

    return event