Пример #1
0
def u2a(data):
    return str(codecs.decode(codecs.encode(data, "ascii", "ignore"), "ascii", "ignore"))


if __name__ == "__main__":
    doExit = False
    client = XivelyClient()
    client.on_connect_finished = on_connect_finished
    client.on_disconnect_finished = on_disconnect_finished
    client.on_subscribe_finished = on_subscribe_finished
    client.on_message_received = on_message_received

    params = XivelyConnectionParameters()
    params.use_websocket = False
    params.publish_count_send_time_period = 5

    try:
        with codecs.open(credentialsfilepath, "r", encoding="utf8") as credsfile:
            password = u2a(credsfile.readline().rstrip("\n"))
            username = u2a(credsfile.readline().rstrip("\n"))
    except (IOError, OSError) as e:
        print(e)
        sys.exit(0)

    print("Read username and password from the file %s" % (credentialsfilepath))
    print("Username = %s" % (username))
    print("Password = %s" % (password))

    try:
        with codecs.open(topicfilepath, "r", encoding="UTF-8") as topicfile:
    return str(
        codecs.decode(codecs.encode(data, 'ascii', 'ignore'), 'ascii',
                      'ignore'))


if __name__ == '__main__':
    doExit = False
    client = XivelyClient()
    client.on_connect_finished = on_connect_finished
    client.on_disconnect_finished = on_disconnect_finished
    client.on_subscribe_finished = on_subscribe_finished
    client.on_message_received = on_message_received

    params = XivelyConnectionParameters()
    params.use_websocket = False
    params.publish_count_send_time_period = 5

    try:
        with codecs.open(credentialsfilepath, 'r',
                         encoding='utf8') as credsfile:
            password = u2a(credsfile.readline().rstrip('\n'))
            username = u2a(credsfile.readline().rstrip('\n'))
    except (IOError, OSError) as e:
        print(e)
        sys.exit(0)

    print("Read username and password from the file %s" %
          (credentialsfilepath))
    print("Username = %s" % (username))
    print("Password = %s" % (password))