2016-05-17 12:46:57 -05:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import threading
|
2018-12-09 07:25:30 -06:00
|
|
|
from vk_api.longpoll import VkLongPoll, VkEventType
|
2016-05-17 12:46:57 -05:00
|
|
|
from pubsub import pub
|
2016-08-14 02:12:49 -05:00
|
|
|
from logging import getLogger
|
|
|
|
log = getLogger("controller.longpolThread")
|
2016-05-17 12:46:57 -05:00
|
|
|
|
|
|
|
class worker(threading.Thread):
|
|
|
|
def __init__(self, session):
|
|
|
|
super(worker, self).__init__()
|
2018-12-09 07:25:30 -06:00
|
|
|
log.debug("Instantiating longPoll server")
|
2016-05-17 12:46:57 -05:00
|
|
|
self.session = session
|
2018-12-09 07:25:30 -06:00
|
|
|
self.longpoll = VkLongPoll(self.session.vk.session_object)
|
2016-05-17 12:46:57 -05:00
|
|
|
|
|
|
|
def run(self):
|
2018-12-09 07:25:30 -06:00
|
|
|
for event in self.longpoll.listen():
|
|
|
|
if event.type == VkEventType.MESSAGE_NEW:
|
|
|
|
pub.sendMessage("order-sent-message", obj=event)
|
|
|
|
elif event.type == VkEventType.USER_ONLINE:
|
|
|
|
print "User online"
|
|
|
|
print event.user_id
|
|
|
|
elif event.type == VkEventType.USER_OFFLINE:
|
|
|
|
print "User offline"
|
|
|
|
print event.user_id
|