本文整理汇总了Python中pusher.Pusher类的典型用法代码示例。如果您正苦于以下问题:Python Pusher类的具体用法?Python Pusher怎么用?Python Pusher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Pusher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pusher_auth
def pusher_auth(request):
profile = ModelFactory.profile_from_request(request)
log.debug('Pusher Auth called.')
if request.method != 'POST':
raise Http404('Unexpected method type for Pusher access.')
p = Pusher(
app_id=os.environ['PUSHER_APP_ID'],
key=os.environ['PUSHER_APP_KEY'],
secret=os.environ['PUSHER_APP_SECRET'],
ssl=True,
port=443
)
channel_name = request.POST.get('channel_name')
socket_id = request.POST.get('socket_id')
log.debug('Pusher Auth Channel_Name: {}'.format(channel_name))
log.debug('Pusher Auth Socket ID: {}'.format(socket_id))
data = {
'user_id': str(profile.uuid),
'user_info': {
'name': profile.get_full_name(),
'avatar_cropped_url': profile.avatar_cropped.url
}
}
auth = p.authenticate(channel=channel_name, socket_id=socket_id, custom_data=data)
return JsonResponse(auth)
示例2: pusher_info
def pusher_info(sender, instance=None, created=False, **kwargs):
pusher = Pusher(app_id=PUSHER_ID, key=PUSHER_KEY, secret=PUSHER_SECRET,
ssl=True)
if created:
if instance.group.channel:
pusher.trigger(instance.group.channel, instance.group.event, {'message': instance.message})
else:
pusher.trigger(instance.group.channel, instance.group.event, {'message': instance.message})
示例3: receive_votes
def receive_votes(request):
pusher = Pusher(
app_id=os.environ.get('PUSHER_APP', ''),
key="ca2bcf928a3d000ae5e4",
secret=os.environ.get('PUSHER_SECRET', '')
)
json_response = {"success": False}
row = Voting.objects.get(pk=1)
try:
if request.method == "GET":
data = request.GET
if data["vote"] == "up":
row.score = row.score + 1
row.total_votes = row.total_votes + 1
row.save()
pusher.trigger(
"voting_channel",
"new_vote",
{"score": row.score}
)
# success
json_response = {"success": True}
return HttpResponse(
json.dumps(json_response),
content_type="application/json"
)
elif data["vote"] == "down":
row.score = row.score - 1
row.total_votes = row.total_votes + 1
row.save()
pusher.trigger(
"voting_channel",
"new_vote",
{"score": row.score}
)
# success
json_response = {"success": True}
return HttpResponse(
json.dumps(json_response),
content_type="application/json"
)
else:
return HttpResponse(
json.dumps(json_response),
content_type="application/json"
)
else:
return HttpResponse(
json.dumps(json_response),
content_type="application/json"
)
except Exception as e:
json_response = {"success": False, "error": str(e)}
return HttpResponse(
json.dumps(json_response),
content_type="application/json"
)
示例4: stopService
def stopService(self):
self.stopped = True
for k in self.connects:
c = self.connects[k]
if c.pushclient is not None:
c.pushclient.stop()
c.pushclient = None
Pusher.stopService(self)
示例5: socketio_view
def socketio_view(request):
print "called"
p = Pusher(
app_id='135314',
key='92e6deea4ee5542dc495',
secret='712204ca7293ef75bd11',
ssl=True,
port=443
)
p.trigger('test_channel', 'my_event', {'message': 'hello world'})
示例6: startService
def startService(self):
Pusher.startService(self)
self.stopped = False
self.connects = {}
self.dbpool.runInteraction(self.recache)
## current statistics
self.stats = {}
self.stats[None] = self._createPushStat(None)
self.publishPusherStats()
示例7: handle
def handle(self, *args, **options):
message = ' '.join(options['message'])
print(message)
pusher = Pusher(
app_id='121933',
key='f1ebb516981a3315e492',
secret='d9f31be884b8be02bcbc'
)
pusher.trigger('test_channel', 'my_event', {'message': message})
示例8: _publish
def _publish(self, action):
serializer = self.serializer_class(instance=self)
data = serializer.serialize()
pusher = Pusher(
app_id=settings.PUSHER_APP_ID,
key=settings.PUSHER_KEY,
secret=settings.PUSHER_SECRET
)
pusher.trigger(self.channel_name, action, data)
示例9: save_read
def save_read(sender, instance, created, raw, **kwargs):
if not raw:
if created:
instance.user.num_unread_notis += 1
instance.user.save()
user = instance.user
channel = "notification_" + user.user.username
pusher = Pusher("216867", "df818e2c5c3828256440",
"5ff000997a9df3464eb5")
serializer = A2AUserSerializer(user)
event_data = serializer.data
pusher.trigger(channel, 'new_noti', event_data)
示例10: on_data
def on_data(self, data):
pusher = Pusher(
app_id=u'',
key=u'',
secret=u''
)
temp_tokens = []
if self.collection.count() == max_tweets:
self.disconnect()
data_dict = json.loads(data)
self.collection.insert(json.loads(data))
if 'retweeted_status' not in data_dict:
text = data_dict['text']
tweets = self.collection.count()
encoded_text = text.encode('ascii', 'ignore').lower()
temp_tokens.extend(regexp_tokenize(encoded_text, self.regex, gaps=False))
filtered_tokens = [term for term in temp_tokens if not term in self.stop_words]
num_tokens = len(filtered_tokens)
print 'Tweet num: ' + str(self.collection.count()) + '\n' + encoded_text
print 'Parsed and filtered: ' + str(filtered_tokens) + ' words'
self.num_words += num_tokens
print 'Total tokens: ' + str(self.num_words)
self.tokens.extend(filtered_tokens)
self.top_monograms = get_monograms_freqdist(self.tokens)
self.top_bigrams = get_bigrams_freqdist(self.tokens)
self.top_trigrams = get_trigrams_freqdist(self.tokens)
colldata = get_dataframe_dict(self.top_monograms, 5, {}, tweets, self.collection)
dataframe = colldata[0]
labels = list(colldata[0].columns.values)
# print str(time)
print os.getcwd()
# with open(os.getcwd() + '\wordstream\static\js\keywords.json', 'w') as outfile:
# json.dump(labels, outfile)
pusher.trigger('my-channel', 'my-event', {
'message': labels
})
示例11: test_initialize_from_env
def test_initialize_from_env(self):
with mock.patch.object(os, 'environ', new={'PUSHER_URL':'https://plah:[email protected]/apps/42'}):
pusher = Pusher.from_env()
self.assertEqual(pusher.ssl, True)
self.assertEqual(pusher.key, u'plah')
self.assertEqual(pusher.secret, u'bob')
self.assertEqual(pusher.host, u'somehost')
self.assertEqual(pusher.app_id, u'42')
with mock.patch.object(os, 'environ', new={'PUSHER_DSN':'https://plah:[email protected]/apps/42'}):
pusher = Pusher.from_env('PUSHER_DSN')
self.assertEqual(pusher.ssl, True)
self.assertEqual(pusher.key, u'plah')
self.assertEqual(pusher.secret, u'bob')
self.assertEqual(pusher.host, u'somehost')
self.assertEqual(pusher.app_id, u'42')
示例12: __init__
def __init__(self, **kwargs):
self.client = Pusher(app_id=getattr(settings, 'PUSHER_APP_ID'),
key=getattr(settings, 'PUSHER_KEY'),
secret=getattr(settings, 'PUSHER_SECRET'),
host=getattr(settings, 'PUSHER_HOST', u'127.0.0.1'),
port=getattr(settings, 'PUSHER_SEND_PORT', 4567),
ssl=getattr(settings, 'PUSHER_SEND_USE_SSL', False),)
示例13: test_validate_webhook_bad_time
def test_validate_webhook_bad_time(self):
pusher = Pusher.from_url(u'http://foo:[email protected]/apps/4')
body = u'{"time_ms": 1000000}'
signature = six.text_type(hmac.new(pusher.secret.encode('utf8'), body.encode('utf8'), hashlib.sha256).hexdigest())
with mock.patch('time.time', return_value=1301):
self.assertEqual(pusher.validate_webhook(pusher.key, signature, body), None)
示例14: test_initialize_from_url
def test_initialize_from_url(self):
self.assertRaises(TypeError, lambda: Pusher.from_url(4))
self.assertRaises(Exception, lambda: Pusher.from_url(u"httpsahsutaeh"))
conf = Pusher.from_url(u"http://foo:[email protected]/apps/4")
self.assertEqual(conf.ssl, False)
self.assertEqual(conf.key, u"foo")
self.assertEqual(conf.secret, u"bar")
self.assertEqual(conf.host, u"host")
self.assertEqual(conf.app_id, u"4")
conf = Pusher.from_url(u"https://foo:[email protected]/apps/4")
self.assertEqual(conf.ssl, True)
self.assertEqual(conf.key, u"foo")
self.assertEqual(conf.secret, u"bar")
self.assertEqual(conf.host, u"host")
self.assertEqual(conf.app_id, u"4")
示例15: test_authenticate_for_private_channels
def test_authenticate_for_private_channels(self):
pusher = Pusher.from_url(u'http://foo:[email protected]/apps/4')
expected = {
u'auth': u"foo:89955e77e1b40e33df6d515a5ecbba86a01dc816a5b720da18a06fd26f7d92ff"
}
self.assertEqual(pusher.authenticate(u'private-channel', u'345.23'), expected)