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 '48 hour', now(), interval '20 second') AS time,
                        '3491356310052896768' as equipment_id,
                        random()*100 AS temperature,
                        random() AS pressure,
                        random()*10 AS dust_rtd,
                        random()*10 AS pm25,
                        random()*10 AS pm10
    """
    cursor.execute(query)
    values = cursor.fetchall()
    try:
        insert_values = [(str(row[0]), row[1], 1, 10, row[2],
                          row[3], row[4], row[5], row[6]) for row in values]
        query_insert = """
INSERT INTO enp_envdata (time, equipment_id, is_online, running_state, temperature, pressure, dust_rtd, pm25, pm10) values (%s, %s, %s, %s, %s, %s, %s, %s, %s)
        """
        cursor.executemany(query_insert, insert_values)
    except (Exception, psycopg2.Error) as error:
        print(error)
    conn.commit()
