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


Python Frame.add_item方法代码示例

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


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

示例1: apns_notification

# 需要导入模块: from apns import Frame [as 别名]
# 或者: from apns.Frame import add_item [as 别名]
def apns_notification(tokens_hex, message):

    apns = APNs(use_sandbox=True, cert_file='cert.pem', key_file='key.pem')

    """
    # Send a notification
    token_hex = 'b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b87'
    payload = Payload(alert="Hello World!", sound="default", badge=1)
    apns.gateway_server.send_notification(token_hex, payload)
    """

    # Send multiple notifications in a single transmission
    # tokens_hex = []
    payload = Payload(alert=message, sound="default", badge=1)

    frame = Frame()
    identifier = 1
    expiry = time.time()+3600
    priority = 10

    for token in tokens_hex:
        frame.add_item(token, payload, identifier,
                       expiry, priority)

    apns.gateway_server.send_notification_multiple(frame)
开发者ID:xrrg,项目名称:Bazzzar_API,代码行数:27,代码来源:notifications.py

示例2: handle

# 需要导入模块: from apns import Frame [as 别名]
# 或者: from apns.Frame import add_item [as 别名]
    def handle(self, *args, **options):

        while True:
            ApplePushNotification.objects.filter(state=ApplePushNotification.NEW).update(state=ApplePushNotification.PENDING)

            frame = Frame()
            identifier = 1
            expiry = time.time() + 3600
            priority = 10
            # retry_cnt = 10
            apns = APNs(use_sandbox=False, cert_file="onoo-production.pem", key_file="onoo-production-key.pem")
            # while retry_cnt > 0:
            try:
                cnt = 0
                for noti in ApplePushNotification.objects.filter(state=ApplePushNotification.PENDING):
                    cnt += 1
                    # apns.gateway_server.send_notification(noti.device_token, Payload(alert=noti.message, badge=noti.badge_count))
                    frame.add_item(noti.device_token, Payload(alert=noti.message, sound="default", badge=noti.badge_count), identifier, expiry, priority)
                if cnt > 0:
                    apns.gateway_server.send_notification_multiple(frame)
            except:
                import traceback
                traceback.print_exc()
                ApplePushNotification.objects.filter(state=ApplePushNotification.PENDING).update(state=ApplePushNotification.NEW)
                    # retry_cnt -= 1
                    # time.sleep(1)
            # for (token_hex, fail_time) in apns.feedback_server.items():
            #         # logging 하기 ...
            #         pass

            # ApplePushNotification.objects.filter(state=ApplePushNotification.PENDING).delete()
            ApplePushNotification.objects.filter(state=ApplePushNotification.PENDING).update(state=ApplePushNotification.DONE)

            time.sleep(1)
开发者ID:uptown,项目名称:django-town,代码行数:36,代码来源:push_job.py

示例3: post

# 需要导入模块: from apns import Frame [as 别名]
# 或者: from apns.Frame import add_item [as 别名]
    def post(self):
        """
        post HTTP method

        Send apns notification for all data in the QuestionTimeNotification
        table.

        Returns:
            A 201 Created HTTP status code.
        """
        query = QuestionTimeNotification.query.all()
        print query
        if len(query) < 1:
            return "", 500
        else:
            payload = Payload(
                alert="Question time is currently live.",
                sound="default",
                category="QUESTION_TIME_CATEGORY",
                custom={
                    'link':
                    'http:/a-vide-link/playlist.m3u8'
                },
                badge=0)
            frame = Frame()
            identifer = 1
            expiry = time.time() + 3600
            priority = 10
            for item in query:
                token_hex = ''.join(item.tokenid)
                frame.add_item(token_hex, payload, identifer, expiry, priority)
            apns.gateway_server.send_notification_multiple(frame)
            return "", 204
开发者ID:iceskel,项目名称:flask-restful-api,代码行数:35,代码来源:api.py

示例4: send

# 需要导入模块: from apns import Frame [as 别名]
# 或者: from apns.Frame import add_item [as 别名]
def send(tokens, payload):
	frame = Frame()
	expiry = time.time() + config.expiry
	for token in tokens:
		identifier = random.getrandbits(32)
		frame.add_item(token, payload, identifier, expiry, config.priority)

	apns.gateway_server.register_response_listener(error_handler)
	apns.gateway_server.send_notification_multiple(frame)
开发者ID:HeraldStudio,项目名称:APN_py,代码行数:11,代码来源:apn.py

示例5: sendNotification

# 需要导入模块: from apns import Frame [as 别名]
# 或者: from apns.Frame import add_item [as 别名]
def sendNotification(token, message, timeout):
    apns = APNs(use_sandbox=False, cert_file="cert.pem", key_file="key.pem")
    frame = Frame()
    identifier = random.getrandbits(32)
    priority = 10
    payload = {"aps": {"alert": message, "sound": "default", "identifier": identifier}}
    # Payload(alert=message, sound="default", custom = {"identifier":identifier})
    frame.add_item(token, payload, identifier, timeout, priority)
    apns.gateway_server.send_notification_multiple(frame)
    return identifier
开发者ID:IVegner,项目名称:Touch-Login-Server,代码行数:12,代码来源:notifications.py

示例6: send_notification_with_payload

# 需要导入模块: from apns import Frame [as 别名]
# 或者: from apns.Frame import add_item [as 别名]
 def send_notification_with_payload(self, message, payload_dict):
     if self.device_token_list:
         apns = APNs(use_sandbox=True, cert_file=self.cert_path, key_file=self.key_path)
         frame = Frame()
         identifier = 1
         expiry = time.time() + 3600
         priority = 10
         payload = Payload(alert=message, sound="default", badge=1, custom=payload_dict)
         for device_token in self.device_token_list:
             frame.add_item(device_token, payload, identifier, expiry, priority)
         apns.gateway_server.send_notification_multiple(frame)
开发者ID:naitianliu,项目名称:pigeon,代码行数:13,代码来源:notification_helper.py

示例7: send_notification

# 需要导入模块: from apns import Frame [as 别名]
# 或者: from apns.Frame import add_item [as 别名]
def send_notification(state):
    device_tokens = DeviceToken.objects.values_list('token', flat=True)
    payload = get_payload(state)

    apns = APNs(cert_file=config('CERT_PEM'), key_file=config('KEY_PEM'), enhanced=True)
    frame = Frame()

    for index, token in enumerate(device_tokens):
        identifier = index + 1
        expiry = time.time() + 3600
        priority = 10
        frame.add_item(token, payload, identifier, expiry, priority)

    apns.gateway_server.send_notification_multiple(frame)
开发者ID:jacksonsierra,项目名称:chef-curry-backend,代码行数:16,代码来源:utils.py

示例8: send_push_background

# 需要导入模块: from apns import Frame [as 别名]
# 或者: from apns.Frame import add_item [as 别名]
def send_push_background(tokens, text, badge, data, content_available):
  apns = APNs(use_sandbox=False, cert_file='static/JukeboxBetaPush.pem', key_file='static/JukeboxBetaPush.pem')
  frame = Frame()
  identifier = 1
  expiry = time.time()+3600
  priority = 10
  for device_token in tokens:
    sound = None
    if text:
      sound = "default"
    if not data:
      data = {}
    payload = Payload(alert=text, sound=sound, badge=badge, custom=data, content_available=content_available)
    frame.add_item(device_token, payload, identifier, expiry, priority)
  apns.gateway_server.send_notification_multiple(frame)
开发者ID:HunterLarco,项目名称:jukebox-backend,代码行数:17,代码来源:app.py

示例9: get_frame

# 需要导入模块: from apns import Frame [as 别名]
# 或者: from apns.Frame import add_item [as 别名]
    def get_frame(self, message, device_tokens):
        frame = Frame()
        identifier = random.getrandbits(32)
        payload = Payload(alert=message)

        for token in device_tokens:
            frame.add_item(
                token,
                payload,
                identifier,
                self.IOS_EXPIRY_SECONDS,
                self.IOS_PRIORITY
            )

        return frame
开发者ID:javaguirre,项目名称:event-driven-chat-tornado-example,代码行数:17,代码来源:notifications.py

示例10: send_notifications_apns

# 需要导入模块: from apns import Frame [as 别名]
# 或者: from apns.Frame import add_item [as 别名]
    def send_notifications_apns(self, device_tokens, payload, priority=10, 
        identifier=None, expiry=None):

        if not device_tokens:
            raise ValueError("No device tokens specified, should be a list")
        
        apns = APNs(use_sandbox=self.use_sandbox, cert_file=self.current_cert_file)

        # Send multiple notifications in a single transmission
        frame = Frame()
        
        for device_token in device_tokens:
            frame.add_item(device_token, payload, identifier, expiry, priority)
        
        return apns.gateway_server.send_notification_multiple(frame)
开发者ID:inmagik,项目名称:pollicino,代码行数:17,代码来源:models.py

示例11: push_notification_multi_raw_apple

# 需要导入模块: from apns import Frame [as 别名]
# 或者: from apns.Frame import add_item [as 别名]
def push_notification_multi_raw_apple(apns, tokens_hex, payload=None, payloads=None):
    frame = Frame()
    identifier = 1
    expiry = time.time() + 3600
    priority = 10
    if payload:
        for token in tokens_hex:
            frame.add_item(token, Payload(**payload), identifier, expiry, priority)
    else:
        for token, payload in tokens_hex, payloads:
            frame.add_item(token, Payload(**payload), identifier, expiry, priority)
    apns.gateway_server.send_notification_multiple(frame)
    # Get feedback messages
    for (token_hex, fail_time) in apns.feedback_server.items():
        # do stuff with token_hex and fail_time
        pass
开发者ID:uptown,项目名称:django-town,代码行数:18,代码来源:update_push.py

示例12: test_add_frame_item

# 需要导入模块: from apns import Frame [as 别名]
# 或者: from apns.Frame import add_item [as 别名]
def test_add_frame_item():
    global has_called_check_method
    has_called_check_method = False

    # assert_called_once_with of Mock Class failes to compare Payload object.
    # So here created custom check method for parameter checking
    def check_add_item_args(token, payload, identifier, expiry, priority):
        default_expiry = int(time.time()) + (60 * 60)

        eq_(token, dummy_token)
        eq_(payload.alert, 'Hey')
        eq_(payload.badge, None)
        eq_(payload.sound, None)
        eq_(payload.custom, {})
        eq_(payload.content_available, False)
        eq_(identifier, 123)
        eq_(priority, 10, 'priority should set default value when skipped')
        eq_(expiry, default_expiry, 'expiry should set default value when skipped')

        global has_called_check_method
        has_called_check_method = True

    worker = SendWorkerThread(**dummy_setting)
    worker.count = 123
    frame = Frame()
    frame.add_item = check_add_item_args

    worker.add_frame_item(frame, 'myapp', dummy_token, {'alert': 'Hey'})
    ok_(has_called_check_method)
开发者ID:co3k,项目名称:apns-proxy-server,代码行数:31,代码来源:test_worker.py

示例13: test_add_frame_item_with_full_args

# 需要导入模块: from apns import Frame [as 别名]
# 或者: from apns.Frame import add_item [as 别名]
def test_add_frame_item_with_full_args():
    global has_called_check_method
    has_called_check_method = False

    # assert_called_once_with of Mock Class failes to compare Payload object.
    # So here created custom check method for parameter checking
    def check_add_item_args(token, payload, identifier, expiry, priority):
        eq_(token, dummy_token)
        eq_(payload.alert, 'Wow')
        eq_(payload.badge, 50)
        eq_(payload.sound, 'bell')
        eq_(payload.custom, {'foo': 'bar'})
        eq_(payload.content_available, True)
        eq_(identifier, 1)
        eq_(priority, 5)
        eq_(expiry, 0)

        global has_called_check_method
        has_called_check_method = True

    worker = SendWorkerThread(**dummy_setting)
    worker.count = 1
    frame = Frame()
    frame.add_item = check_add_item_args

    worker.add_frame_item(frame, 'myapp', dummy_token, {
        'alert': 'Wow',
        'badge': 50,
        'sound': 'bell',
        'custom': {'foo': 'bar'},
        'content_available': True,
    }, expiry=0, priority=5)
    ok_(has_called_check_method)
开发者ID:co3k,项目名称:apns-proxy-server,代码行数:35,代码来源:test_worker.py

示例14: send_multi_apn

# 需要导入模块: from apns import Frame [as 别名]
# 或者: from apns.Frame import add_item [as 别名]
def send_multi_apn(message, devs, pub=None):
    frame = Frame()
    identifier = 1
    expiry = time.time()+(60*60*24) # 1 day expire time
    priority = 10
    send = []
    unsend = []
    
    for dev in devs:
        payload = craft_apn_payload(message, dev, pub=pub)
        if payload:
            frame.add_item(dev.apns_token, payload, identifier, expiry, priority)
            send.append(dev.name)
        else:
            unsend.append(dev.name)

    apns.gateway_server.send_notification_multiple(frame)
    return (send, unsend)
开发者ID:jonashoechst,项目名称:SimpleReaderServer,代码行数:20,代码来源:app.py

示例15: testFrame

# 需要导入模块: from apns import Frame [as 别名]
# 或者: from apns.Frame import add_item [as 别名]
    def testFrame(self):

        identifier = 1
        expiry = 3600
        token_hex = 'b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c'
        payload = Payload(alert="Hello World!",
                          sound="default",
                          badge=4)
        priority = 10

        frame = Frame()
        frame.add_item(token_hex, payload, identifier, expiry, priority)

        f = ('\x02\x00\x00\x00t\x01\x00 \xb5\xbb\x9d\x80\x14\xa0\xf9\xb1\xd6\x1e!'
             '\xe7\x96\xd7\x8d\xcc\xdf\x13R\xf2<\xd3(\x12\xf4\x85\x0b\x87\x8a\xe4\x94L'
             '\x02\x00<{"aps":{"sound":"default","badge":4,"alert":"Hello World!"}}'
             '\x03\x00\x04\x00\x00\x00\x01\x04\x00\x04\x00\x00\x0e\x10\x05\x00\x01\n')
        self.assertEqual(f, str(frame))
开发者ID:kernel1983,项目名称:tornado_apns,代码行数:20,代码来源:tests.py


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