def handler(event, context=None):
    # Get args from event
    dryrun = event.get('dryrun') or False
    page_id = event.get('pageId') or FACEBOOK_PAGE_ID
    cal_id = event.get('calendarId') or GOOGLE_CALENDAR_ID

    # Initialize facebook page & Google Calendar
    page = fest.FacebookPage(GRAPHAPI, page_id)
    gcal = fest.GoogleCalendar(CALENDARAPI, cal_id)
    page.logger = gcal.logger = logger

    # Sync
    sync = gcal.sync(page, time_filter='upcoming').execute(dryrun=dryrun)

    # Helper to get event time
    def event_time(time):
        try:
            return time['dateTime']
        except KeyError:
            return time['date']

    # Return referces to modified objects
    resp = {
        k: [{
            'google_id': x.get('id'),
            'location': x.get('location'),
            'summary': x.get('summary'),
            'htmlLink': x.get('htmlLink'),
            'start': event_time(x.get('start')),
            'end': event_time(x.get('end')),
        } for facebook_id, x in v.items()]
        for k, v in sync.responses.items()
    }
    return resp
Exemple #2
0
def main(page_id=None, cal_id=None, dryrun=False):
    page_id = page_id or FACEBOOK_PAGE_ID
    cal_id = cal_id or GOOGLE_CALENDAR_ID

    # Initialize facebook page & Google Calendar
    page = fest.FacebookPage(GRAPHAPI, page_id)
    gcal = fest.GoogleCalendar(CALENDARAPI, cal_id)
    page.logger.setLevel('INFO')
    gcal.logger.setLevel('INFO')

    # Sync
    sync = gcal.sync(page, time_filter='upcoming').execute(dryrun=dryrun)

    # Return referces to modified objects
    resp = {
        k: [{
            'google_id': x.get('id'),
            'location': x.get('location'),
            'summary': x.get('summary'),
            'htmlLink': x.get('htmlLink'),
            'start': event_time(x.get('start')),
            'end': event_time(x.get('end')),
        } for facebook_id, x in v.items()]
        for k, v in sync.responses.items()
    }
    return resp
Exemple #3
0
def main(page_id=None, cal_id=None, dryrun=False):
    """ Heroku entrypoint. """
    page_id = page_id or FACEBOOK_PAGE_ID
    cal_id = cal_id or GOOGLE_CALENDAR_ID

    # Initialize facebook page & Google Calendar
    page = fest.FacebookPage(GRAPHAPI, page_id)
    gcal = fest.GoogleCalendar(CALENDARAPI, cal_id)
    page.logger.setLevel('INFO')
    gcal.logger.setLevel('INFO')

    # Sync
    sync = gcal.sync(page, time_filter='upcoming').execute(dryrun=dryrun)

    # Return created/updated/deleted objects
    return sync.responses
Exemple #4
0
def handler(event, *_):
    # Log Event
    print(f'EVENT {json.dumps(event)}')

    # Get args from event
    event = event or {}
    cal_id = event.get('calendarId') or GOOGLE_CALENDAR_ID
    channel = event.get('channel') or SLACK_CHANNEL
    dryrun = event.get('dryrun') or False
    page_id = event.get('pageId') or FACEBOOK_PAGE_ID
    user = event.get('user')

    # Initialize facebook page & Google Calendar
    page = fest.FacebookPage(GRAPHAPI, page_id)
    gcal = fest.GoogleCalendar(CALENDARAPI, cal_id)
    page.logger.setLevel('INFO')
    gcal.logger.setLevel('INFO')

    # Sync
    sync = gcal.sync(page, time_filter='upcoming').execute(dryrun=dryrun)

    # Get Slack message
    message = slack_message(sync.responses, channel, user)

    # Post and return
    print(f'MESSAGE {json.dumps(message)}')
    if not dryrun and message['attachments']:
        SNS.publish(TopicArn=SLACK_TOPIC_ARN,
                    Message=json.dumps(message),
                    MessageAttributes={
                        'id': {
                            'DataType': 'String',
                            'StringValue': 'postMessage'
                        },
                        'type': {
                            'DataType': 'String',
                            'StringValue': 'chat'
                        }
                    })
    return message