示例#1
0
def doPrint():

  

    #faye client *********************
    client = BayeuxClient('http://localhost:8000/faye')
    client.register('/messages', cb)

    client.start()
    #faye client end *****************

    
  

    
    for line in range(0,10):
        #pause
        while (state == 'pause'):
            print 'pause'
            pass
            #belki buraya siyeh ekran yaip dururum

        #cancel or stop
        if  (state == 'stop'):   
            print 'print canceled'
            return

        showSlide(line)
        processDelay(2)
def main():
	logging.basicConfig(level=logging.INFO)
	client = BayeuxClient('http://localhost:8080/cometd')
	client.register('/members/demo', cb)
	client.register('/chat/demo', cb)
	client.start()
	time.sleep(500)
示例#3
0
    def runJob(self, query):
        if(query == None) :
            return False

        version = str(36.0)

        name = 'LoanStatusPrediction'   #'Regex'
        # sdata = {'Name':  name,
        #          'Query': query,
        #          'ApiVersion': version,
        #          'NotifyForOperationCreate': 'true',
        #          'NotifyForFields': 'Referenced'
        #          }
        # topicId = self.create_record('PushTopic', sdata, self.sf)['id']
        # print topicId
        url = 'https://' + self.sf.sf_instance.encode()
        # print 'base url : ' + url
        client = BayeuxClient(url + '/cometd/' + version, 'OAuth ' + self.sf.session_id)
        # print "737373"
        client.register('/topic/' + name, self.record_analysis)
        # client.register('/chat/demo', cb)
        try:
            client.start()

            while True:
                pass
            # self.delete_record('PushTopic', topicId)

        except Exception as e:
            print str(e)
示例#4
0
def doPrint(baseFileName):

    pub.sendMessage('Log', arg1='debug', arg2='faye client started')

    #faye client *********************
    client = BayeuxClient('http://localhost:8000/faye')
    client.register('/messages', cb)

    client.start()
    #faye client end *****************

    fp=open(baseFileName,'r')
    pub.sendMessage('Log', arg1='debug', arg2='gcode file opened')

    lines=fp.readlines()
    for line in lines:
        #pause
        while (state == 'pause'):
            pass
            #belki buraya siyeh ekran yaip dururum

        #cancel or stop
        if  (state == 'stop'):   
            print 'print canceled'
            return

        if ';<Slice>' in line :
            processSliceParam(line.split(' ')[1])
        if ';<Delay>' in line :
            processDelay(line.split(' ')[1])
        if not';' in line :
            processGCode(line)
            
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit ()

    pygame.quit ()
示例#5
0
    def __init__(self,access_token,instance,version,**kwargs):

        def default_cb(data):
            pass

        server_url = self._build_server_url(instance=instance,
                                            version=version)

        self.access_token = access_token
        self.instance = instance
        self.version = version

        self.error_cb = kwargs.get('error_cb',default_cb)
        self._listeners = []

        self.client = BayeuxClient(server=server_url,
                                   access_token=access_token,
                                   error_cb=self.error_cb)
示例#6
0
def doPrint(baseFileName):

    pub.sendMessage('Log', arg1='debug', arg2='faye client started')

    #faye client *********************
    client = BayeuxClient('http://localhost:8000/faye')
    client.register('/messages', cb)

    client.start()
    #faye client end *****************

    fp = open(baseFileName, 'r')
    pub.sendMessage('Log', arg1='debug', arg2='gcode file opened')

    lines = fp.readlines()
    for line in lines:
        #pause
        while (state == 'pause'):
            pass
            #belki buraya siyeh ekran yaip dururum

        #cancel or stop
        if (state == 'stop'):
            print 'print canceled'
            return

        if ';<Slice>' in line:
            processSliceParam(line.split(' ')[1])
        if ';<Delay>' in line:
            processDelay(line.split(' ')[1])
        if not ';' in line:
            processGCode(line)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()

    pygame.quit()
示例#7
0
def doPrint():

    #faye client *********************
    client = BayeuxClient('http://localhost:8000/faye')
    client.register('/messages', cb)

    client.start()
    #faye client end *****************

    for line in range(0, 10):
        #pause
        while (state == 'pause'):
            print 'pause'
            pass
            #belki buraya siyeh ekran yaip dururum

        #cancel or stop
        if (state == 'stop'):
            print 'print canceled'
            return

        showSlide(line)
        processDelay(2)
示例#8
0
class SFMonitor(object):

    QUERIES = {
                'Account':ACCOUNT_QUERY,
                'Opportunity':OPPORTUNITY_QUERY,
                'Lead':LEAD_QUERY,
                'Task':TASK_QUERY,
                'Event':EVENT_QUERY,
                'Attachment':ATTACHMENT_QUERY
            }

    TOPICS = {
            'Account':'AllAccounts',
            'Opportunity':'AllOpportunities',
            'Lead':'AllLeads',
            'Task':'AllTasks',
            'Event':'AllEvents',
            'Attachment':'AllAttachments'
            }

    def __init__(self,access_token,instance,version,**kwargs):

        def default_cb(data):
            pass

        server_url = self._build_server_url(instance=instance,
                                            version=version)

        self.access_token = access_token
        self.instance = instance
        self.version = version

        self.error_cb = kwargs.get('error_cb',default_cb)
        self._listeners = []

        self.client = BayeuxClient(server=server_url,
                                   access_token=access_token,
                                   error_cb=self.error_cb)

    def _build_server_url(self,instance,version):
        if instance.startswith('http://'):
           url = '{i}/cometd/{v}'.format(i=instance.replace('http://','https://'),
                                         v=version)
        elif instance.startswith('https://'):
           url = '{i}/cometd/{v}'.format(i=instance,
                                         v=version)
        else:
           url = 'https://{i}/cometd/{v}'.format(i=instance,
                                                 v=version)
        return url

    def _register_callback(self,cb):
        pass

    def _has_duplicate_push_topic(self,data):
        errors = [error['errorCode'] for error in data if 'errorCode' in error]
        return 'DUPLICATE_VALUE' in errors

    def notify(self,raw_message):
        print 'raw message:{r}'.format(r=raw_message)

    def listen(self,object_name,callback):

        query = self.QUERIES.get(object_name,None)
        if query is None:
            raise Exception('Could not find query for object ' \
                            ' name:{n}'.format(n=object_name))

        topic = self.TOPICS.get(object_name,None)
        if topic is None:
            raise Exception('Cannot find appropriate callback for ' \
                            'topic:{t}')

        params = {
                    'Name':topic,
                    'Query':query,
                    'ApiVersion':self.version
                  }

        try:
            PushTopic.register(push_topic=params,
                               access_token=self.access_token,
                               instance=self.instance)
        except SalesforceMalformedRequest as exc:

            is_duplicate = self._has_duplicate_push_topic(data=exc.content)
            if not is_duplicate:
                raise Exception('Failed creating push topic for ' \
                                'object name:{o}'.format(o=object_name))

        else:
            self.client.register('/topic/{topic}'.format(topic=topic))
    def start(self):

        self.client.start()

    def stop(self):
        self.client.stop()
from bayeux.bayeux_client import BayeuxClient
from bayeux.bayeux_constants import HANDSHAKE_RETRY_INTERVAL

HANDSHAKE_RETRY_INTERVAL = 100

def cb(data):
    print data

def error(data):
    print data
access_token = "00D610000006S9H!AREAQCAJwEns12CQg2evcjBW1DBSz3SunnojQGu__naslc_SDWooL7B91gdfX9OX2sFOT8ZvwJ9y8BPSpWWhvxnKwFf43SYI"
refresh_token = "5Aep861tbt360sO1.tXt.T3B3W1MGHvpIPCUhMkFwukTUHR4XQHrM1i6kcdUYyutmWuAkIBQoR.vL_gUDi"
server = 'https://na34.salesforce.com/cometd/31.0'

stream_client = BayeuxClient(server,access_token,error_cb=error)
stream_client.register('/topic/AllTasks',cb)
stream_client.register('/topic/AllFeeds',cb)
stream_client.start()