-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRasberryPiEmulatorInfluxDB.py
More file actions
72 lines (61 loc) · 1.56 KB
/
RasberryPiEmulatorInfluxDB.py
File metadata and controls
72 lines (61 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os
import time
from influxdb_client_3 import InfluxDBClient3, Point
token = os.environ.get("INFLUXDB_TOKEN")
org = "InfluxDB Stand Up Demo"
host = "https://us-east-1-1.aws.cloud2.influxdata.com"
client = InfluxDBClient3(host=host, token=token, org=org)
database = "PythonScriptBucket"
data = {
"point1": {
"location": "Klamath",
"species": "bees",
"count": 23,
},
"point2": {
"location": "Portland",
"species": "ants",
"count": 30,
},
"point3": {
"location": "Klamath",
"species": "bees",
"count": 28,
},
"point4": {
"location": "Portland",
"species": "ants",
"count": 32,
},
"point5": {
"location": "Klamath",
"species": "bees",
"count": 29,
},
"point6": {
"location": "Portland",
"species": "ants",
"count": 40,
},
}
for key in data:
point = (
Point("census")
.tag("location", data[key]["location"])
.field(data[key]["species"], data[key]["count"])
)
client.write(database=database, record=point)
time.sleep(1) # separate points by 1 second
print("Complete")
# This is a basic SQL query you can test, which displays the data in a terminal
'''
query = """SELECT *
FROM 'census'
WHERE time >= now() - interval '24 hours'
AND ('bees' IS NOT NULL OR 'ants' IS NOT NULL)"""
# Execute the query
table = client.query(query=query, database="my-bucket", language='sql') )
# Convert to dataframe
df = table.to_pandas().sort_values(by="time")
print(df)
'''