table = """
CREATE TABLE IF NOT EXISTS pi_data (
  hour INT,
  time INT,
  temp INT,
  PRIMARY KEY (hour, time)
)
"""
session.execute(table)

# Make a Loop to simulate times
time_delay = 0
stmt = session.prepare("INSERT INTO pi_data (hour, time, temp) VALUES (?, ?, ?)")
stmt.consistency_level = ConsistencyLevel.LOCAL_ONE
while 1:  # just keep going
    time.sleep(0.4)
    rand = randint(1, 12)
    temp = randint(1, 120)
    time_delay += 1
    # Put data into table

    future = session.execute_async(stmt, (rand, time_delay, temp))
    sys.stdout.write("{} :".format(future._current_host))
    sys.stdout.write(" WROTE : Hour {:<5d} | Time {:<5d} | Temp {:<5d}".format(rand, time_delay, temp))
    try:
        future.result(0.5)
    except OperationTimedOut:
        sys.stdout.write(" TIMED OUT: Reconnecting...")
        cluster.remove_host(future._current_host)
    print " "