本文整理汇总了Python中pusher.Pusher.trigger方法的典型用法代码示例。如果您正苦于以下问题:Python Pusher.trigger方法的具体用法?Python Pusher.trigger怎么用?Python Pusher.trigger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pusher.Pusher
的用法示例。
在下文中一共展示了Pusher.trigger方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pusher_info
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import trigger [as 别名]
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})
示例2: receive_votes
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import trigger [as 别名]
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"
)
示例3: socketio_view
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import trigger [as 别名]
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'})
示例4: handle
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import trigger [as 别名]
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})
示例5: _publish
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import trigger [as 别名]
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)
示例6: save_read
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import trigger [as 别名]
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)
示例7: on_data
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import trigger [as 别名]
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
})
示例8: put
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import trigger [as 别名]
def put(self, request, filename="image.png", format=None):
pusher = Pusher(app_id=u'160687', key=u'0eb2780d9a8a875c0727', secret=u'b45f1f052cd3359c9ceb')
username = request.data['username']
names_file = request.data['names_file']
prices_file = request.data['prices_file']
user = User.objects.get(username=username)
new_receipt = user.receipt_set.create(
names_image = names_file,
prices_image = prices_file
)
p1 = subprocess.Popen(['tesseract', new_receipt.names_image.path, 'stdout', '-psm', '6'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
names_file_ocr = p1.communicate()[0]
p2 = subprocess.Popen(['tesseract', new_receipt.prices_image.path, 'stdout', '-psm', '6'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
prices_file_ocr = p2.communicate()[0]
names_split = names_file_ocr.decode().split('\n')
prices_split = prices_file_ocr.decode().split('\n')
print(names_split)
print(prices_split)
names_split = [x for x in names_split if x != '']
prices_split = [x for x in prices_split if x != '']
print(names_split)
print(prices_split)
for i in range(0, len(names_split)):
name = names_split[i]
price = prices_split[i]
strippedPrice = ''.join([c for c in price if c in '1234567890.'])
new_receipt.receiptitem_set.create(
name = name,
price = Decimal(strippedPrice),
)
pusher.trigger(u'receipt_channel', u'new_receipt', { "username": username })
return Response(status=204)
示例9: pushNotification
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import trigger [as 别名]
def pushNotification(request,email,data,time,img,event):
channel = u"customuser_{pk}".format(
pk=email
)
pusher = Pusher(app_id=settings.PUSHER_APP_ID,
key=settings.PUSHER_KEY,
secret=settings.PUSHER_SECRET)
event_data = {
'object' : data,
'user': request.user.email
}
if time != None:
event_data.update({'time' : time,'img' : img})
pusher.trigger(
[channel,],
event,
event_data
)
示例10: PusherService
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import trigger [as 别名]
class PusherService(object):
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),)
def send(self, channel, event, **kwargs):
return self.client.trigger(unicode(channel), unicode(event), kwargs)
示例11: Trigger
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import trigger [as 别名]
class Trigger():
def __init__(self, bot, event, query, message):
self.bot = bot
self.event = event
self.query = query
self.message = message
self.pusher = Pusher(
app_id=u'144525',
key=u'f87e45c335b6d8004e51',
secret=u'37f03e68c7e0900fb045'
)
def push(self):
self.pusher.trigger(
self.bot,
self.event,
{
u'query' : self.query,
u'message' : self.message
}
)
示例12: render_to_response
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import trigger [as 别名]
def render_to_response(self, context, **response_kwargs):
channel = u"{model}_{pk}".format(
model=self.object._meta.model_name,
pk=self.object.pk
)
data = self.__object_to_json_serializable(self.object)
pusher = Pusher(app_id=settings.PUSHER_APP_ID,
key=settings.PUSHER_KEY,
secret=settings.PUSHER_SECRET)
pusher.trigger(
[channel, ],
self.pusher_event_name,
{
'object': data,
'user': self.request.user.username
}
)
return super(PusherMixin, self).render_to_response(context, **response_kwargs)
示例13: main
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import trigger [as 别名]
def main():
if any(not value for value in (APP_KEY, APP_ID, APP_SECRET)):
print('Please, configure the credentials for your PushJS app.')
return
pusher = Pusher(
app_id=APP_ID,
key=APP_KEY,
secret=APP_SECRET,
cluster=APP_CLUSTER,
)
while True:
delay_secs = random.randint(DELAY_SECS_MIN, DELAY_SECS_MAX)
time.sleep(delay_secs)
user_message = {
'message': random.choice(SENTENCES),
'username': names.get_first_name(),
}
logger.info('Sending message: {}'.format(user_message))
pusher.trigger(CHANNEL_NAME, 'user_message', user_message)
示例14: sns_handler
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import trigger [as 别名]
def sns_handler(request):
messageType = request.META['HTTP_X_AMZ_SNS_MESSAGE_TYPE']
parsed_body = json.loads(request.body)
if messageType == "SubscriptionConfirmation":
url = parsed_body["SubscribeURL"]
serialized_data = urllib2.urlopen(url).read()
elif messageType == "Notification":
message = parsed_body["Message"]
j_msg = json.loads(message)
print (type(j_msg['coordinates']))
print (j_msg['coordinates'])
j_msg['coordinates'] = j_msg['coordinates']['coordinates']
print(j_msg)
message = str(json.dumps(j_msg))
print(message)
pusher_client = Pusher(
app_id='xxx',
key='xxx',
secret='xxx',
ssl=True
)
pusher_client.trigger('test_channel', 'my_event', {'message': message})
es = Elasticsearch(
[
'xxx'
],
use_ssl=True,
verify_certs=True,
connection_class = RequestsHttpConnection
)
es.create(index="tweets", doc_type="tweet", body=j_msg)
return HttpResponse('', status=200)
示例15: Pusher
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import trigger [as 别名]
import serial, time, io
import redis
from pusher import Pusher
ser = serial.Serial('/dev/ttyUSB0', 9600)
# r = redis.StrictRedis(host='localhost', port=6379, db=0)
# p = r.pubsub()
pusher = Pusher(
app_id=u'4',
key=u'765ec374ae0a69f4ce44',
secret=u'your-pusher-secret',
host=u'localhost',
port=4567,
ssl=False,
)
while 1:
serial_line = ser.readline()
movement = serial_line.decode().strip('\r\n')
print(movement)
if movement:
# r.publish('movement', '1')
try:
pusher.trigger(u'movement', u'movement-detected', {})
except:
pass
ser.close()