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


Python pyfcm.FCMNotification方法代码示例

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


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

示例1: __init__

# 需要导入模块: import pyfcm [as 别名]
# 或者: from pyfcm import FCMNotification [as 别名]
def __init__(self, conf, router_conf, metrics):
        """Create a new FCM router and connect to FCM"""
        self.conf = conf
        self.router_conf = router_conf
        self.metrics = metrics
        self.min_ttl = router_conf.get("ttl", 60)
        self.dryRun = router_conf.get("dryrun", False)
        self.collapseKey = router_conf.get("collapseKey", "webpush")
        self.clients = {}
        try:
            for (sid, creds) in router_conf["creds"].items():
                self.clients[sid] = pyfcm.FCMNotification(
                    api_key=creds["auth"])
        except Exception as e:
            self.log.error("Could not instantiate FCM {ex}", ex=e)
            raise IOError("FCM Bridge not initiated in main")
        self._base_tags = ["platform:fcm"]
        self.log.debug("Starting FCM router...") 
开发者ID:mozilla-services,项目名称:autopush,代码行数:20,代码来源:fcm.py

示例2: _get_push_service

# 需要导入模块: import pyfcm [as 别名]
# 或者: from pyfcm import FCMNotification [as 别名]
def _get_push_service():
    return FCMNotification(api_key=_get_fcm_key()) 
开发者ID:cyanfish,项目名称:heltour,代码行数:4,代码来源:android_app.py

示例3: push_service

# 需要导入模块: import pyfcm [as 别名]
# 或者: from pyfcm import FCMNotification [as 别名]
def push_service():
    api_key = os.getenv("FCM_TEST_API_KEY", None)
    assert api_key, "Please set the environment variables for testing according to CONTRIBUTING.rst"

    return FCMNotification(api_key=api_key) 
开发者ID:olucurious,项目名称:PyFCM,代码行数:7,代码来源:test_fcm.py

示例4: test_push_service_without_credentials

# 需要导入模块: import pyfcm [as 别名]
# 或者: from pyfcm import FCMNotification [as 别名]
def test_push_service_without_credentials():
    try:
        FCMNotification()
        assert False, "Should raise AuthenticationError without credentials"
    except errors.AuthenticationError:
        pass 
开发者ID:olucurious,项目名称:PyFCM,代码行数:8,代码来源:test_fcm.py

示例5: __init__

# 需要导入模块: import pyfcm [as 别名]
# 或者: from pyfcm import FCMNotification [as 别名]
def __init__(self, config):
        self.config = config
        self.api_key = self.config.get('api_key')
        # FCM guarantees best-effort delivery with TTL 0
        self.ttl = self.config.get('ttl', 0)
        self.timeout = self.config.get('timeout', 10)
        self.default_notification = self.config.get('notification_title')
        self.proxy = None
        if 'proxy' in self.config:
            host = self.config['proxy']['host']
            port = self.config['proxy']['port']
            self.proxy = {'http': 'http://%s:%s' % (host, port),
                          'https': 'https://%s:%s' % (host, port)}
        self.client = FCMNotification(api_key=self.api_key, proxy_dict=self.proxy) 
开发者ID:linkedin,项目名称:iris,代码行数:16,代码来源:fcm.py

示例6: handle

# 需要导入模块: import pyfcm [as 别名]
# 或者: from pyfcm import FCMNotification [as 别名]
def handle(self, *args, **options):
        # Initiate connection
        push_service = FCMNotification(api_key=settings.FCM_SERVER_KEY)

        # Refresh all
        for device in Device.objects.all():
            print(device.user.name + ' - ', end='', flush=True)
            if fill_device_firebase(push_service, device):
                print('OK')
            else:
                device.delete()
                print('FAIL') 
开发者ID:wncc,项目名称:instiapp-api,代码行数:14,代码来源:refresh-devices.py

示例7: handle

# 需要导入模块: import pyfcm [as 别名]
# 或者: from pyfcm import FCMNotification [as 别名]
def handle(self, *args, **options):
        # Initiate connection
        push_service = FCMNotification(api_key=settings.FCM_SERVER_KEY)

        # Maintain a count
        count = 0

        # Iterate all upcoming events
        for event in Event.objects.filter(
                start_time__range=(timezone.now(), timezone.now() + timedelta(minutes=30)),
                starting_notified=False):

            # Stop the spam!
            event.starting_notified = True
            event.notify = False
            event.save()

            # Event About to Start
            print('EATS -', event.name)

            # Construct object
            data_message = {
                "type": "event",
                "id": str(event.id),
                "title": event.name,
                "verb": "Event is about to start",
                "large_icon": event.bodies.first().image_url,
                "image_url": event.image_url
            }

            # Notify all followers
            for profile in event.followers.all():
                # Send FCM push notification
                for device in profile.devices.all():
                    count += send_notification_fcm(push_service, device, data_message)

        print('Sent', count, 'rich notifications')
        self.stdout.write(self.style.SUCCESS('Event starting chore completed successfully')) 
开发者ID:wncc,项目名称:instiapp-api,代码行数:40,代码来源:notify-event-starting.py

示例8: push_notify

# 需要导入模块: import pyfcm [as 别名]
# 或者: from pyfcm import FCMNotification [as 别名]
def push_notify(pk):
    """Push notify a notification."""
    setUp()
    notification = Notification.objects.filter(id=pk).first()

    # Check invalid subscriptions
    if not notification or notification.emailed or not notification.actor:
        return

    # Get the user's profile
    profile = notification.recipient.profile

    # Check bad users
    if not profile:
        return

    # Stop the spam!
    notification.emailed = True
    notification.save()

    # Get rich notification
    data_message = get_rich_notification(notification)

    # Get the API endpoint
    if not hasattr(settings, 'FCM_SERVER_KEY'):
        return

    push_service = FCMNotification(api_key=settings.FCM_SERVER_KEY)

    # Send FCM push notification
    for device in profile.devices.all():
        send_notification_fcm(push_service, device, data_message)

    # For each web push subscription
    for subscription in profile.web_push_subscriptions.all():
        send_notification_webpush(subscription, data_message) 
开发者ID:wncc,项目名称:instiapp-api,代码行数:38,代码来源:tasks.py

示例9: handle

# 需要导入模块: import pyfcm [as 别名]
# 或者: from pyfcm import FCMNotification [as 别名]
def handle(self, *args, **options):  # noqa: C901
        """Send Push notifications."""

        webpush_sent = 0
        webpush_total = 0
        fcm_sent = 0

        push_service = FCMNotification(api_key=settings.FCM_SERVER_KEY)

        # Iterate all unsent notifications
        for notification in Notification.objects.filter(emailed=False)[:1000]:

            # Check invalid subscriptions
            if not notification or not notification.actor:
                continue

            # Get the user's profile
            profile = notification.recipient.profile

            # Check bad users
            if not profile:
                continue

            # Stop the spam!
            notification.emailed = True
            notification.save()

            # Get rich notification
            data_message = get_rich_notification(notification)

            # Retro method for transition
            if profile.fcm_id and profile.fcm_id != '':
                send_fcm_notification_message(push_service, profile.fcm_id, data_message)

            # Send FCM push notification
            for device in profile.devices.all():
                fcm_sent += send_notification_fcm(push_service, device, data_message)

            # For each web push subscription
            for subscription in profile.web_push_subscriptions.all():
                webpush_total += 1
                webpush_sent += send_notification_webpush(subscription, data_message)

        print(
            "WebPush:", webpush_sent,
            "WebPush FAIL:", webpush_total - webpush_sent,
            "FCM:", fcm_sent
        )
        self.stdout.write(self.style.SUCCESS('Push notification chore completed successfully')) 
开发者ID:wncc,项目名称:instiapp-api,代码行数:51,代码来源:push-notify.py

示例10: fcm_send_topic_message

# 需要导入模块: import pyfcm [as 别名]
# 或者: from pyfcm import FCMNotification [as 别名]
def fcm_send_topic_message(
        api_key=None,
        json_encoder=None,
        topic_name=None,
        message_body=None,
        message_title=None,
        message_icon=None,
        sound=None,
        condition=None,
        collapse_key=None,
        delay_while_idle=False,
        time_to_live=None,
        restricted_package_name=None,
        low_priority=False,
        dry_run=False,
        data_message=None,
        click_action=None,
        badge=None,
        color=None,
        tag=None,
        body_loc_key=None,
        body_loc_args=None,
        title_loc_key=None,
        title_loc_args=None,
        content_available=None,
        timeout=5,
        extra_notification_kwargs=None,
        extra_kwargs={}):

    if api_key is None:
        api_key = SETTINGS.get("FCM_SERVER_KEY")
    push_service = FCMNotification(api_key=api_key, json_encoder=json_encoder)
    result = push_service.notify_topic_subscribers(
        topic_name=topic_name,
        message_body=message_body,
        message_title=message_title,
        message_icon=message_icon,
        sound=sound,
        condition=condition,
        collapse_key=collapse_key,
        delay_while_idle=delay_while_idle,
        time_to_live=time_to_live,
        restricted_package_name=restricted_package_name,
        low_priority=low_priority,
        dry_run=dry_run,
        data_message=data_message,
        click_action=click_action,
        badge=badge,
        color=color,
        tag=tag,
        body_loc_key=body_loc_key,
        body_loc_args=body_loc_args,
        title_loc_key=title_loc_key,
        title_loc_args=title_loc_args,
        content_available=content_available,
        timeout=timeout,
        extra_kwargs=extra_kwargs,
        extra_notification_kwargs=extra_notification_kwargs,
    )

    return result 
开发者ID:xtrinch,项目名称:fcm-django,代码行数:63,代码来源:fcm.py


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