import influxdb_client
from influxdb_client.client.write_api import SYNCHRONOUS
import numpy as np
bucket = "AIEnergy"
org = "bbs2wob"
token = "rjjvTLl4j1Y70Pqmeky7SsYn7D_h9bR4LMP9HFwKIZGBkfiF2Xx2vJAfn1UV0QwhO6ELVW8GCjZ4P2LU3pmhzg=="
# Store the URL of your InfluxDB instance
url="https://influx.xplore-dna.de"

client = influxdb_client.InfluxDBClient(
    url=url,
    token=token,
    org=org
)


def getData(bucket, measurement, field, time):
    # Query script
    query_api = client.query_api()
    query = 'from(bucket:"phoenix")\
            |> range(start: -10m)\
            |> filter(fn:(r) => r._measurement == "measurement")\
            |> filter(fn:(r) => r._field == "P")'
    result = query_api.query(org=org, query=query)
    results = []
    for table in result:
        for record in table.records:
            results.append(record.get_value())
    result = 0
    
    return results