socializer/src/controller/longpollthread.py

24 lines
763 B
Python
Raw Normal View History

# -*- coding: utf-8 -*-
import threading
from vk_api.longpoll import VkLongPoll, VkEventType
from pubsub import pub
from logging import getLogger
log = getLogger("controller.longpolThread")
class worker(threading.Thread):
def __init__(self, session):
super(worker, self).__init__()
log.debug("Instantiating longPoll server")
self.session = session
self.longpoll = VkLongPoll(self.session.vk.session_object)
def run(self):
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