Пример #1
0
def main():
    global p
    p(send)
    conv_auth = requests.AuthObject(config.username, config.password)

    def req(params={}):
        return requests.get('https://convore.com/api/live.json',
                            params=params,
                            auth=conv_auth)

    cursor = None
    while 1:
        try:
            p('requesting')
            r = req({'cursor': cursor}) if cursor else req()

            if r.status_code != 200:
                p("Got invalid status code %s on response body %s" %
                  (r.status_code, r.content))
                continue

            response = json.loads(r.content)
            for message in response['messages']:
                cursor = message['_id']

                #ignore messages sent by ourselves to (try and) avoid infinite loops
                if message['user']['username'] == config.username:
                    continue

                if message['kind'] == 'message':
                    topic_id = message['topic']['id']
                    if topic_id in games:
                        p("forwarding message to topic_id %s" % topic_id)
                        games[topic_id][1].put(message)

                #if a new topic is created, launch a serving proces
                if message['kind'] == 'topic':
                    topic_id = message["id"]

                    queue = Queue()
                    proc = Process(target=Gogame(topic_id, queue).serve)
                    proc.start()

                    games[topic_id] = (proc, queue)

                    p("created a process to serve topic_id %s" % topic_id)

                #don't print login, logout, or read messages. Eventually TODO: DELETEME
                if message['kind'] not in ['login', 'logout', 'read']:
                    p(message)

        except KeyboardInterrupt:
            sys.exit(0)
Пример #2
0
def send(topic_id, message, **params):
    #does this make a request?
    conv_auth = requests.AuthObject(config.username, config.password)

    data = {"message": message.encode('utf-8')}
    data.update(params)

    r = requests.post(
        "https://convore.com/api/topics/%s/messages/create.json" % topic_id,
        data=data,
        auth=conv_auth)

    assert r.status_code == 200
    p("successful send %s %s" % (message, data))
Пример #3
0
def main():
    init_plugins()

    conv_auth = requests.AuthObject(config.username, config.password)

    def req(params={}):
        return requests.get('https://convore.com/api/live.json',
                            params=params,
                            auth=conv_auth)

    cursor = None
    while 1:
        try:
            p('requesting')
            r = req({'cursor': cursor}) if cursor else req()

            if not r.status_code == 200:
                p("Got invalid status code %s on response body %s. Sleeping for 60."
                  % (r.status_code, r.content))
                sleep(60)
                continue

            response = json.loads(r.content)
            for message in response['messages']:
                cursor = message['_id']

                #ignore messages sent by ourselves to (try and) avoid infinite loops
                if message['user']['username'] == config.username:
                    continue

                if message['kind'] == 'message':
                    help(message)

                #if we have any hooks for this kind of message, run the function
                if message['kind'] in hooks:
                    for hook in hooks[message['kind']]:
                        p("calling %s" % hook)
                        hook(message)

                #don't print login, logout, or read messages. Eventually TODO: DELETEME
                if message['kind'] not in ['login', 'logout', 'read']:
                    p(message)
        #see NOTES, line 107
        except requests.HTTPError:
            p("HTTPError received:")
            p("%s" % sys.exc_info()[0])
            p("%s" % traceback.format_exc())
        except KeyboardInterrupt:
            sys.exit(0)
Пример #4
0
def send(topic_id, message, **params):
    """Send a message in a thread-safe manner"""
    p("trying to send: %s to %s" % (message, topic_id))

    conv_auth = requests.AuthObject(config.username, config.password)

    data = {"message": message.encode('utf-8')}
    data.update(params)

    r = requests.post(
        "https://convore.com/api/topics/%s/messages/create.json" % topic_id,
        data=data,
        auth=conv_auth)

    assert r.status_code == 200
    p("successful send")
Пример #5
0
    def test_AUTH_HTTPS_200_OK_GET(self):
        auth = requests.AuthObject('requeststest', 'requeststest')
        url = 'https://convore.com/api/account/verify.json'
        r = requests.get(url, auth=auth)

        self.assertEqual(r.status_code, 200)