def save_record(account):
    print(request.content_type)
    if not request.json or not 'size' in request.json:
        raise InvalidUsage('Invalid usage of this web-service detected',
                           status_code=400)

    size = int(request.json['size'])
    decoded_compressed_record = request.json.get('data', "")
    symmetricKeyEncrypted = request.json.get('key', "")

    compressed_record = base64.b64decode(decoded_compressed_record)
    encrypted_json_record_str = zlib.decompress(compressed_record)

    pks1OAEPForDecryption = PKS1_OAEPCipher()
    pks1OAEPForDecryption.readDecryptionKey('decryption.key')
    symmetricKeyDecrypted = pks1OAEPForDecryption.decrypt(
        base64.b64decode(symmetricKeyEncrypted))

    aesCipherForDecryption = AESCipher()
    aesCipherForDecryption.setKey(symmetricKeyDecrypted)

    json_record_str = aesCipherForDecryption.decrypt(encrypted_json_record_str)

    record_as_dict = json.loads(json_record_str)

    # Add the account ID to the reading here
    record_as_dict["account"] = account

    #print record_as_dict
    post_id = mongo_collection.insert_one(record_as_dict).inserted_id
    print('Saved as Id: %s' % post_id)

    producer = KafkaProducer(
        bootstrap_servers=['your.kafka.server.com:9092'],
        value_serializer=lambda m: json.dumps(m).encode('ascii'),
        retries=5)
    # send the individual records to the Kafka queue for stream processing
    raw_readings = record_as_dict["data"]
    counter = 0
    for raw_reading in raw_readings:
        raw_reading["id"] = str(post_id) + str(counter)
        raw_reading["account"] = account
        producer.send("car_readings", raw_reading)
        counter += 1

    producer.flush()
    # send the summary to the Kafka queue in case there is some stream processing required for that as well
    raw_summary = record_as_dict["summary"]
    raw_summary["id"] = str(post_id)
    raw_summary["account"] = account
    raw_summary["eventTime"] = record_as_dict["timestamp"]
    producer.send("car_summaries", raw_summary)

    producer.flush()
    return jsonify({'title': str(size) + ' bytes received'}), 201
        if message == "BYE":
            print("MAIN TCP: BYE")
            UDPSender.microphoneActivated = False
            UDPListener.speakersActivated = False
            LedBlinker.blink("RED")
            KeypadManager.clearQueue()
            phoneStatus = "FREE"

        if message == "LETIN":
            print("MAIN TCP: LETIN")
            UDPSender.microphoneActivated = False
            UDPListener.speakersActivated = False
            LedBlinker.blink("GREEN")
            KeypadManager.clearQueue()
            phoneStatus = "FREE"

        if message == "HI":
            print("MAIN TCP: HI")
            Diffie_Hellman.negotiateDHKeys()

        if message[:2] == "DH":

            print("MAIN TCP: " + message)
            sharedSecret = Diffie_Hellman.calculateSharedSecret(message[3:])
            print("sharedSecret is: " + str(sharedSecret))
            aesCipher.setKey(str(sharedSecret))
            clientConnected = True

print('koniec programu')