import psycopg2
CONNECTION = "postgres://postgres:zcDsj2021@49.232.14.174:5432/ehs_develop"
with psycopg2.connect(CONNECTION) as conn:
    cursor = conn.cursor()
    query = """
SELECT generate_series(now() - interval '24 hour', now(), interval '5 minute') AS time,
                            '3491356310052896768' as equipment_id,
                            random()*100 AS temperature,
                            random() AS pressure;
    """
    cursor.execute(query)
    values = cursor.fetchall()
    for i in values:
        query_insert = """
INSERT INTO enp_envdata (time, equipment_id, is_online, is_runing, temperature, pressure) values (%s, %s, true, true, %s, %s)
        """
        try:
            cursor.execute(query_insert, (i[0], i[1], i[2], i[3]))
        except (Exception, psycopg2.Error) as error:
            print(error.pgerror)
    conn.commit()
