Example #1
0
 def push_extra(self,
                extra,
                msg='test',
                platform='all',
                audience=jpush.all_):
     p = {
         'all': jpush.all_,
         'android': jpush.platform('android'),
         'ios': jpush.platform('ios')
     }
     if audience != jpush.all_:
         audience = jpush.audience(jpush.alias(str(audience)))
     try:
         msg = msg.encode('utf-8')
     except:
         pass
     a_msg = jpush.android(alert=msg, extras=extra)
     i_msg = jpush.ios(alert=msg, extras=extra)
     self.push = self._jpush.create_push()
     self.push.audience = audience
     self.push.platform = p.get(platform)
     self.push.notification = jpush.notification(alert=msg,
                                                 android=a_msg,
                                                 ios=i_msg)
     return self.push.send()
Example #2
0
 def push_extra(self,
                extra,
                msg='test',
                platform='all',
                audience=jpush.all_):
     p = {
         'all': jpush.all_,
         'android': jpush.platform('android'),
         'ios': jpush.platform('ios')
     }
     if audience != jpush.all_:
         audience = jpush.audience(jpush.alias(str(audience)))
     try:
         msg = msg.encode('utf-8')
     except:
         pass
     a_msg = jpush.android(alert=msg, extras=extra)
     i_msg = jpush.ios(alert=msg, extras=extra)
     self.push = self._jpush.create_push()
     self.push.audience = audience
     self.push.platform = p.get(platform)
     self.push.notification = jpush.notification(alert=msg,
                                                 android=a_msg,
                                                 ios=i_msg)
     self.push.options = {
         "time_to_live": 86400,
         "sendno": 12345,
         "apns_production": False
     }
     for i in range(5):
         try:
             self.push.send()
             return True
         except Exception, e:
             print e.__repr__()
Example #3
0
 def push_notification(self,msg,platform='all',audience = 'all'):
     p = {
         'all':jpush.all_ ,
         'android':jpush.platform('android'),
         'ios':jpush.platform('ios')
     }
     a = {
         'all':jpush.all_ ,
     }
     self.push = self._jpush.create_push()
     self.push.audience = a.get(audience)
     self.push.platform = p.get(platform)
     self.push.notification = jpush.notification(alert=msg)
     return self.push.send()
Example #4
0
        def _push_msg(message, device_id):
            app_key = 'app_key'
            master_secret = 'master_key'

            _jpush = jpush.JPush(app_key, master_secret)
            push = _jpush.create_push()
            # push.audience = jpush.audience([{"registration_id":device_id}])
            push.audience = {'registration_id': [device_id]}
            # push.audience = device_id
            android_msg = jpush.android(
                message,
                None,
                None,
                {
                    "msg": message,  # 强行套用app中notification的相关格式
                    "status": 0
                }
            )
            ios_msg = jpush.ios(
                message,
                None,
                None,
                {
                    "msg": message,  # 强行套用app中notification的相关格式
                    "status": 0
                }
            )
            push.notification = jpush.notification("hello jpush", ios_msg, android_msg, None)
            # push.options = {"time_to_live": 86400, "sendno": 12345, "apns_production":True}
            push.options = {"time_to_live": 86400, "apns_production": True}
            push.platform = jpush.platform("all")

            push.send()
Example #5
0
def jpushios(obj):
    _jpush = jpush.JPush(app_key, master_secret)
    push = _jpush.create_push()
    push.audience = jpush.all_

    name = Name(obj)
    project = Project(obj)
    content = obj.content
    version = Version(obj)
    urgency = Urgency(obj)
    module = Module(obj)
    distribter = Distribter(obj)

    msgdict = [
        name, u'在', project, version, u'版本', module, u'中', u'发现一个', urgency,
        u'问题', u':', content
    ]
    msg = ''.join(msgdict)

    push.audience = jpush.audience(jpush.alias(distribter))
    ios_msg = jpush.ios(alert=msg,
                        badge="+1",
                        sound="a.caf",
                        extras={'k': 'v'})
    push.options = {
        "time_to_live": 86400,
        "sendno": 12345,
        "apns_production": False
    }
    push.notification = jpush.notification(alert="", ios=ios_msg)
    push.platform = jpush.platform("ios")
    push.send()
Example #6
0
 def test_basic_push(self):
     self.push.platform = platform("ios", "android")
     self.push.audience = audience()
     with self.assertRaises(ValidateError):
         self.push.send_validate()
     self.push.notification = notification(alert="alert")
     self.push.send_validate()
Example #7
0
 def push_extra(self,extra,msg='test',platform='all',audience = 'all'):
     p = {
         'all':jpush.all_ ,
         'android':jpush.platform('android'),
         'ios':jpush.platform('ios')
     }
     a = {
         'all':jpush.all_ ,
     }
     a_msg = jpush.android(alert=msg,extras=extra)
     i_msg = jpush.ios(alert=msg,extras=extra)
     self.push = self._jpush.create_push()
     self.push.audience = a.get(audience)
     self.push.platform = p.get(platform)
     self.push.notification = jpush.notification(alert =msg,android=a_msg,ios=i_msg)
     return self.push.send()
Example #8
0
    def send_message(self, message, alias=None, **kwargs):

        if alias is not None:
            self.push.audience = jpush.audience(jpush.alias(*alias))

        self.push.message = jpush.message(msg_content=message, extras=kwargs)
        self.push.platform = jpush.platform('android', 'ios')
        self.push.send()
Example #9
0
 def push_notification(self, msg, platform='all', audience=jpush.all_):
     p = {
         'all': jpush.all_,
         'android': jpush.platform('android'),
         'ios': jpush.platform('ios')
     }
     if audience != jpush.all_:
         audience = jpush.audience(jpush.alias(str(audience)))
     try:
         msg = msg.encode('utf-8')
     except:
         pass
     #print audience
     self.push = self._jpush.create_push()
     self.push.audience = audience
     self.push.platform = p.get(platform)
     self.push.notification = jpush.notification(alert=msg)
     return self.push.send()
Example #10
0
def send_new_photo_notification(regids, data):
	_jpush = jpush.JPush(settings.JPUSH_APP_KEY, settings.JPUSH_APP_MASTER)

	push = _jpush.create_push()
	push.audience = jpush.registration_id(*regids)
	push.notification = jpush.notification(ios=jpush.ios(alert='', content_available=True, extras={"d": data, "action": "photo"}))
	push.options = dict(apns_production=False)

	push.platform = jpush.platform('ios')
	return push.send()
Example #11
0
 def test_message(self):
     msg = message("hello world")
     sms_msg = sms_message("content", 20)
     noti = notification(alert="hello,jpush")
     self.push.notification = noti
     self.push.platform = platform("all")
     self.push.audience = audience(**{"tag": tag("tcc", "all")})
     self.push.message = msg
     self.push.sms_message = sms_msg
     self.push.send_validate()
Example #12
0
    def send_notification(self, title, alert, alias=None, **kwargs):
        android = jpush.android(alert=alert, title=title, extras=kwargs)

        if alias is not None:
            self.push.audience = jpush.audience(jpush.alias(*alias))

        # ios = None
        self.push.notification = jpush.notification(alert=alert, android=android)
        self.push.platform = jpush.platform('android', 'ios')
        self.push.send()
Example #13
0
def send_friend_notification(regid, data):
	_jpush = jpush.JPush(settings.JPUSH_APP_KEY, settings.JPUSH_APP_MASTER)

	push = _jpush.create_push()
	push.audience = jpush.registration_id(regid)
	push.notification = jpush.notification(ios=jpush.ios(alert='sb has make friend with you!', extras={"d": data, "action": "friend"}))
	push.options = dict(apns_production=False)

	push.platform = jpush.platform('ios')
	return push.send()
Example #14
0
def push_news(artical_id, header):
    server = jpush.JPush(app_key, master_secret)
    push = server.create_push()
    push.audience = jpush.all_
    android_msg = jpush.android(alert=header,
                                title="ArsenalNews",
                                extras={"Header": header,
                                        "ArticalId": artical_id})
    push.notification = jpush.notification(alert="Hello, Arsenal",
                                           android=android_msg)
    push.platform = jpush.platform("android")
    push.send()
Example #15
0
def send_like_notification(regid, like_num):
	if not regid or len(regid) <> 11:
		return 'invalid reg_id'

	_jpush = jpush.JPush(settings.JPUSH_APP_KEY, settings.JPUSH_APP_MASTER)

	push = _jpush.create_push()
	push.audience = jpush.registration_id(regid)
	push.notification = jpush.notification(ios=jpush.ios(alert='', content_available=True, extras={"like_num": like_num, "action": "like"}))
	push.options = dict(apns_production=False)

	push.platform = jpush.platform('ios')
	return push.send()
Example #16
0
def push_message_to_alias(content, msg_type, alias, platform='android'):
    msg = {
        'msg_type': msg_type,
        'content': content
    }

    _jpush = jpush.JPush(app.config['JPUSH_APP_KEY'], app.config['JPUSH_MASTER_SECRET'])
    push = _jpush.create_push()
    push.message = jpush.message(json.dumps(msg))
    push.audience = jpush.audience(jpush.alias(alias))
    push.platform = jpush.platform(platform)
    ret = push.send()
    return ret.payload['sendno'].encode('utf-8')
Example #17
0
def pushMessage(messages=None, extra=None, *args, **kwargs):
    template = Template(messages)
    messages = template.render(dict(*args, **kwargs))

    push = jpush.JPush(settings.JPUSH_APPKEY, settings.JPUSH_SECRET)
    push = push.create_push()

    push.notification = jpush.notification(alert=messages,
                                           ios=messages,
                                           android=messages)
    push.options = {
        "time_to_live": 86400,
        "sendno": 12345,
        "apns_production": False
    }
    push.platform = jpush.platform("ios", "android")
    push.send()
Example #18
0
    def test_notification(self):
        noti = notification(alert="hello,jpush")
        self.assertIsInstance(noti, dict)
        self.assertEqual(noti['alert'], 'hello,jpush')

        noti = notification(alert="alert",
                            android=android("alert android!"),
                            ios=ios("alert ios!"),
                            winphone=winphone("alert winphone!"))
        self.assertEqual(noti['alert'], 'alert')
        self.assertEqual(noti['android']['alert'], 'alert android!')
        self.assertEqual(noti['ios']['alert'], 'alert ios!')
        self.assertEqual(noti['winphone']['alert'], 'alert winphone!')

        self.push.platform = platform("all")
        self.push.notification = noti
        self.push.audience = audience(**{"tag": tag("tcc", "all")})
        self.push.send_validate()
Example #19
0
def push(app, title, content, type):

    msg_content = {'title': title, 'description': content, 'type': type}

    jpush = JPush.JPush(app['app_key'], app['master_key'])

    push = jpush.create_push()
    # push.audience = JPush.alias("1547")
    push.audience = JPush.all_
    ios_msg = JPush.ios(alert=content,
                        badge="+1",
                        sound="default",
                        extras=msg_content)

    push.message = JPush.message(msg_content=msg_content)
    push.notification = JPush.notification(ios=ios_msg)
    push.platform = JPush.platform('android', 'ios')
    push.options = {"time_to_live": 14400}
    push.send()
Example #20
0
def pushProduct(id, operId):
	try:
		db.execute("SELECT * FROM " + getTableName('push', operId)+ " WHERE id=%s LIMIT 1", (id,))
		msg = db.get_rows(size=1, is_dict=True)

		db.execute("SELECT * FROM %s WHERE `status`=1" %getTableName('pusher', operId))
		pusher = db.get_rows(is_dict=True)

		_jpush = jpush.JPush(app_key, master_secret)
		push = _jpush.create_push()
		total = 0

		for vo in pusher:
			if vo['categories'] and msg['category'] not in vo['categories']:
				continue

			if vo['keyword'] and msg['keyword'] not in vo['keyword']:
				continue

			push.audience = jpush.audience(
	        	jpush.registration_id(vo['registration'])
		        )

			push.notification = jpush.notification(
			   android=jpush.android(
			      alert=msg['title'],
			      builder_id=getBuidlerId(vo['sound'], vo['vibrate']),
			      extras={"id": msg['product'], 'target': 'product'}
			   )
			)
			push.platform = jpush.platform('android')
			push.send()

			total = total + 1
			db.update(getTableName('pusher', operId), {'date': time2stamp(datetime.date.today().strftime('%Y-%m-%d'))}, 
				{'id': vo['id']})
	except Exception:
		db.update(getTableName('push', operId), {'status': 2}, {'id': id})
		return False
	else:
		db.update(getTableName('push', operId), {'status': 1, 'total': total}, {'id': id})
		return True
Example #21
0
def PushMessage(alert,title,n_type,n_id):
	push = _jpush.create_push()
	push.audience = jpush.all_
	push.notification = jpush.notification(
		ios=jpush.ios(
			alert=alert,
			badge="+1",
			extras={"n_type":n_type,"n_id":n_id}
			),
		android=jpush.android(
			alert=alert,
			title=title,
			extras={"n_type":n_type,"n_id":n_id}
			)
		)
	push.platform = jpush.platform('ios', 'android')
	push.options = {"apns_production":True,"time_to_live":7200}
	try:
		push.send()
	except:
		traceback.print_exc()
Example #22
0
def pushMessage(registration, operId):
	db.execute("SELECT * FROM " + getTableName('pusher', operId)+ " WHERE registration=%s AND `status`=1 LIMIT 1", (registration,))
	if db.get_rows_num() == 0:
		return

	pusher = db.get_rows(size=1, is_dict=True)
	_jpush = jpush.JPush(app_key, master_secret)
	push = _jpush.create_push()	
	push.audience = jpush.audience(
	    jpush.registration_id(registration)
	)

	push.notification = jpush.notification(
	   android=jpush.android(
	      alert=u'你的吐槽信息有了新的回复~',
	      builder_id=getBuidlerId(pusher['sound'], pusher['vibrate']),
	      extras={'target': 'tucao'}
	   )
	)
	push.platform = jpush.platform('android')
	push.send()
Example #23
0
def push(app, title, content, type):

    msg_content = {
        'title': title,
        'description': content,
        'type': type
    }

    jpush = JPush.JPush(app['app_key'], app['master_key'])

    push = jpush.create_push()
    # push.audience = JPush.alias("1547")
    push.audience = JPush.all_
    ios_msg = JPush.ios(alert=content, badge="+1",
                        sound="default", extras=msg_content)

    push.message = JPush.message(msg_content=msg_content)
    push.notification = JPush.notification(ios=ios_msg)
    push.platform = JPush.platform('android', 'ios')
    push.options = {"time_to_live":14400}
    push.send()
Example #24
0
    def process_item(self, item, spider):
        for word in self.words_to_filter:
            #print unicode(item['name']).lower()
            if unicode(word) in unicode(item['name']).lower():
                if item['domain']:
                    item['url'][0] = item['domain'] +"/"+ item['url'][0]
                # line = json.dumps(OrderedDict(item), ensure_ascii=False, sort_keys=False) + "\n"
                # self.file.write(line)
                # insert = [null,item['name'][0],item['url'][0], time.time()];
                # self.cur.execute('insert into test values(%d,%s,%s,%d)',value)
                #pdb.set_trace()
                self.cu.execute("select * from fetch where  url=  '"+item['url'][0]+"'")
                #pdb.set_trace()
                r = self.cu.fetchone()

                if r == None:

                    #print  item['name'][0]
                    t = [item['name'][0],item['url'][0], int(time.time())];
                    self.cu.execute("insert into fetch (name,url,ctime) values (?,?,?)", t)
                    self.cx.commit()
                    _jpush = jpush.JPush('8a4d4ac5c14856cb59df9c84', '4be8bd02e575ee5d16d8b8cd')
                    push = _jpush.create_push()
                    push.audience = jpush.all_
                    # device = _jpush.create_device()
                    # device.get_aliasuser('30B414C0D1BE414C8DCEEDE3627B43A7','ios');

                    ios_msg = jpush.ios(alert="Fetch有新的数据!", badge="+1", sound="a.caf", extras={'k1':'v1'})
                    push.notification = jpush.notification(alert="fetch notify!", android= None, ios=ios_msg)
                    push.options = {"time_to_live":86400, "sendno":12345,"apns_production":False}
                    push.platform = jpush.platform("ios")
                    push.send()

                else :
                    print u'已存在';
                return item
            else:
                None
Example #25
0
    def test_audience(self):
        self.push.platform = platform("all")
        self.push.audience = audience(**{"tag": tag("tcc", "test", "深圳")})
        self.assertTupleEqual(self.push.payload['audience']["tag"],
                              ("tcc", "test", "深圳"))

        audiences = audience(
            **{
                "tag": tag("tcc", "test", "深圳"),
                "alias": alias(*["alias{}".format(i) for i in range(5)])
            })
        self.assertIsInstance(audiences, dict)
        self.assertDictEqual(
            audiences, {
                "tag": ("tcc", "test", "深圳"),
                "alias": tuple(["alias{}".format(i) for i in range(5)])
            })

        self.push.notification = notification(alert="alert")
        self.push.send_validate()

        with self.assertRaises(ValueError):
            audience(**{"tags": tag("tcc", "all")})
Example #26
0
def PushMessage(alert, title, n_type, n_id):
    push = _jpush.create_push()
    push.audience = jpush.all_
    push.notification = jpush.notification(ios=jpush.ios(alert=alert,
                                                         badge="+1",
                                                         extras={
                                                             "n_type": n_type,
                                                             "n_id": n_id
                                                         }),
                                           android=jpush.android(alert=alert,
                                                                 title=title,
                                                                 extras={
                                                                     "n_type":
                                                                     n_type,
                                                                     "n_id":
                                                                     n_id
                                                                 }))
    push.platform = jpush.platform('ios', 'android')
    push.options = {"apns_production": True, "time_to_live": 7200}
    try:
        push.send()
    except:
        traceback.print_exc()
Example #27
0
def jpushios(obj):
    _jpush = jpush.JPush(app_key, master_secret)
    push = _jpush.create_push()
    push.audience = jpush.all_

    name = Name(obj)
    project = Project(obj)
    content = obj.content
    version = Version(obj)
    urgency = Urgency(obj)
    module  = Module(obj)
    distribter = Distribter(obj)

    msgdict = [name, u'在', project,version,u'版本',module,u'中',u'发现一个',urgency,u'问题',u':',content]
    msg = ''.join(msgdict)

    push.audience = jpush.audience(
        jpush.alias(distribter)
    )
    ios_msg = jpush.ios(alert=msg, badge="+1", sound="a.caf", extras={'k':'v'})
    push.options = {"time_to_live": 86400, "sendno": 12345, "apns_production": False}
    push.notification = jpush.notification(alert="", ios=ios_msg)
    push.platform = jpush.platform("ios")
    push.send()
Example #28
0
def push_helper(alert=None, type=None, title=None, builder_id=1, badge="+1", audience=jpush.all_,
                platform=jpush.platform("ios", "android"), **kwargs):

    jpush_setting = current_app.config.get('JPUSH')
    push = jpush.JPush(jpush_setting['appkey'], jpush_setting['secret'])
    obj = push.create_push()
    obj.platform = platform
    obj.audience = audience
    if alert is not None:
        android_msg = dict(builder_id=builder_id, extras=kwargs)
        if title is not None:
            android_msg['title'] = title
        ios_msg = dict(extras=kwargs)
        if badge is not None:
            ios_msg['badge'] = badge
        obj.notification = jpush.notification(alert=alert, android=android_msg, ios=ios_msg)
    else:
        obj.message = jpush.message(alert, content_type=type, title=title, extras=kwargs)

    try:
        obj.send()
        return 0
    except jpush.JPushFailure, e:
        return e.error_code
Example #29
0
import jpush as jpush

_jpush = jpush.JPush('9370f4f126efb68cb51448d9', '5aa29e3617a58eca440a01a9')

push = _jpush.create_push()
aa = []
aa.append('0013e79cbfc')
aa.append('0416fadd27b')
taa = tuple(aa)
#push.audience = jpush.registration_id('0013e79cbfc', '0416fadd27b')
push.audience = jpush.registration_id(*taa)
push.notification = jpush.notification(ios=jpush.ios(alert='#####JPush power cnvnwnovs', badge=1, sound='default'))
push.message = jpush.message('abcdefg')
push.options = dict(apns_production=False)

push.platform = jpush.platform('ios')
push.send()

Example #30
0
import string
import jpush
import traceback


jpush_app_key = "8c5e6ca676b8c1a9910615b5"
jpush_master_secret = "c1464c6ac4502530f722c541"

_jpush = jpush.JPush(jpush_app_key, jpush_master_secret)
push = _jpush.create_push()

# if you set the logging level to "DEBUG",it will show the debug logging.
_jpush.set_logging("DEBUG")

#push.audience = jpush.all_
#push.platform = jpush.all_
push.audience = jpush.audience(jpush.registration_id('191e35f7e01344072f8'))

push.platform = jpush.platform('ios')

ios = jpush.ios(alert="Hello, 专辑推送测试",  extras={"type":"3","id":"16302530","ios":{"sound":"default","badge":1}})
android = jpush.android(alert="Hello, 专辑推送测试", priority=1, style=1, alert_type=1, extras={"type":"3","id":"16302530","ios":{"sound":"default","badge":1}})

#push.notification = jpush.notification(alert="Hello, JPush!", android=android, ios=ios)
push.notification = jpush.notification(alert="Hello, JPush!", ios=ios)

# pprint (push.payload)
result = push.send()