当前位置: 首页>>代码示例>>Python>>正文


Python GoogleEventsProvider.sync_calendars方法代码示例

本文整理汇总了Python中inbox.events.google.GoogleEventsProvider.sync_calendars方法的典型用法代码示例。如果您正苦于以下问题:Python GoogleEventsProvider.sync_calendars方法的具体用法?Python GoogleEventsProvider.sync_calendars怎么用?Python GoogleEventsProvider.sync_calendars使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在inbox.events.google.GoogleEventsProvider的用法示例。


在下文中一共展示了GoogleEventsProvider.sync_calendars方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: EventSync

# 需要导入模块: from inbox.events.google import GoogleEventsProvider [as 别名]
# 或者: from inbox.events.google.GoogleEventsProvider import sync_calendars [as 别名]
class EventSync(BaseSyncMonitor):
    """Per-account event sync engine."""
    def __init__(self, email_address, provider_name, account_id, namespace_id,
                 poll_frequency=300):
        bind_context(self, 'eventsync', account_id)
        # Only Google for now, can easily parametrize by provider later.
        self.provider = GoogleEventsProvider(account_id, namespace_id)

        BaseSyncMonitor.__init__(self,
                                 account_id,
                                 namespace_id,
                                 email_address,
                                 EVENT_SYNC_FOLDER_ID,
                                 EVENT_SYNC_FOLDER_NAME,
                                 provider_name,
                                 poll_frequency=poll_frequency)

    def sync(self):
        """Query a remote provider for updates and persist them to the
        database. This function runs every `self.poll_frequency`.
        """
        self.log.info('syncing events')
        # Get a timestamp before polling, so that we don't subsequently miss
        # remote updates that happen while the poll loop is executing.
        sync_timestamp = datetime.utcnow()

        with session_scope() as db_session:
            account = db_session.query(Account).get(self.account_id)

            last_sync = account.last_synced_events

        try:
            deleted_uids, calendar_changes = self.provider.sync_calendars()
        except AccessNotEnabledError:
            self.log.warning(
                'Access to provider calendar API not enabled; bypassing sync')
            return
        with session_scope() as db_session:
            handle_calendar_deletes(self.namespace_id, deleted_uids,
                                    self.log, db_session)
            calendar_uids_and_ids = handle_calendar_updates(self.namespace_id,
                                                            calendar_changes,
                                                            self.log,
                                                            db_session)
            db_session.commit()

        for (uid, id_) in calendar_uids_and_ids:
            deleted_uids, event_changes = self.provider.sync_events(
                uid, sync_from_time=last_sync)
            with session_scope() as db_session:
                handle_event_deletes(self.namespace_id, id_, deleted_uids,
                                     self.log, db_session)
                handle_event_updates(self.namespace_id, id_, event_changes,
                                     self.log, db_session)
                db_session.commit()

        with session_scope() as db_session:
            account = db_session.query(Account).get(self.account_id)
            account.last_synced_events = sync_timestamp
            db_session.commit()
开发者ID:Analect,项目名称:sync-engine,代码行数:62,代码来源:remote_sync.py

示例2: test_calendar_parsing

# 需要导入模块: from inbox.events.google import GoogleEventsProvider [as 别名]
# 或者: from inbox.events.google.GoogleEventsProvider import sync_calendars [as 别名]
def test_calendar_parsing():
    raw_response = [
        {
            'accessRole': 'owner',
            'backgroundColor': '#9a9cff',
            'colorId': '17',
            'defaultReminders': [{'method': 'popup', 'minutes': 30}],
            'etag': '"1425508164135000"',
            'foregroundColor': '#000000',
            'id': '[email protected]',
            'kind': 'calendar#calendarListEntry',
            'notificationSettings': {
                'notifications': [
                    {'method': 'email', 'type': 'eventCreation'},
                    {'method': 'email', 'type': 'eventChange'},
                    {'method': 'email', 'type': 'eventCancellation'},
                    {'method': 'email', 'type': 'eventResponse'}
                ]
            },
            'primary': True,
            'selected': True,
            'summary': '[email protected]',
            'timeZone': 'America/Los_Angeles'
        },
        {
            'accessRole': 'reader',
            'backgroundColor': '#f83a22',
            'colorId': '3',
            'defaultReminders': [],
            'description': 'Holidays and Observances in United States',
            'etag': '"1399416119263000"',
            'foregroundColor': '#000000',
            'id': 'en.usa#[email protected]',
            'kind': 'calendar#calendarListEntry',
            'selected': True,
            'summary': 'Holidays in United States',
            'timeZone': 'America/Los_Angeles'
        },
        {
            'defaultReminders': [],
            'deleted': True,
            'etag': '"1425952878772000"',
            'id': '[email protected]',
            'kind': 'calendar#calendarListEntry'
        }
    ]
    expected_deletes = ['[email protected]']
    expected_updates = [
        Calendar(uid='[email protected]',
                 name='[email protected]',
                 description=None,
                 read_only=False),
        Calendar(uid='en.usa#[email protected]',
                 name='Holidays in United States',
                 description='Holidays and Observances in United States',
                 read_only=True)
    ]

    provider = GoogleEventsProvider(1, 1)
    provider._get_raw_calendars = mock.MagicMock(
        return_value=raw_response)
    deletes, updates = provider.sync_calendars()
    assert deletes == expected_deletes
    for obtained, expected in zip(updates, expected_updates):
        assert cmp_cal_attrs(obtained, expected)
开发者ID:nohobby,项目名称:sync-engine,代码行数:67,代码来源:test_google_events.py


注:本文中的inbox.events.google.GoogleEventsProvider.sync_calendars方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。