當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。