Ejemplo n.º 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
Ejemplo n.º 2
0
def save_fb_event(event, page_id):
    event_obj = FBEvent()
    event_obj.event_id = event["id"]
    event_obj.page_id = page_id
    event_obj.owner = event["owner"]
    event_obj.fields = event

    dupe_obj = FBEvent.collection().find_one({"event_id": event["id"]})

    if dupe_obj is None:
        event_obj._id = FBEvent.collection().save(event_obj.serialize())
    else:
        FBEvent.collection().update({"event_id": event["id"]}, event_obj.serialize())
        event_obj = FBEvent.unserialize(FBEvent.collection().find_one({"event_id": event["id"]}))

    return event_obj