2016-05-17 12:46:57 -05:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import threading
|
|
|
|
from vk import longpool
|
|
|
|
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__()
|
2016-08-14 02:12:49 -05:00
|
|
|
log.debug("Instanciating longPoll server")
|
2016-05-17 12:46:57 -05:00
|
|
|
self.session = session
|
|
|
|
self.l = longpool.LongPoll(self.session.vk.client)
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
while self.session.is_logged == True:
|
2016-08-14 02:12:49 -05:00
|
|
|
log.debug("Calling to check...")
|
2016-05-17 12:46:57 -05:00
|
|
|
p = self.l.check()
|
2016-08-14 02:12:49 -05:00
|
|
|
# log.debug("check has returned " + p)
|
2016-05-17 12:46:57 -05:00
|
|
|
for i in p:
|
|
|
|
if i.text != None and i.from_id != None and i.flags != None and i.message_flags != None:
|
|
|
|
pub.sendMessage("order-sent-message", obj=i)
|