-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathbasic-write-errorhandling.py
More file actions
73 lines (64 loc) · 2.08 KB
/
Copy pathbasic-write-errorhandling.py
File metadata and controls
73 lines (64 loc) · 2.08 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
73
import datetime
from influxdb_client_3 import InfluxDBClient3, Point, SYNCHRONOUS, write_client_options
wco = write_client_options(write_options=SYNCHRONOUS)
with InfluxDBClient3(
token="",
host="eu-central-1-1.aws.cloud2.influxdata.com",
database="pokemon-codex", write_client_options=wco) as client:
now = datetime.datetime.now(datetime.timezone.utc)
data = Point("caught").tag("trainer", "ash").tag("id", "0006").tag("num", "1") \
.field("caught", "charizard") \
.field("level", 10).field("attack", 30) \
.field("defense", 40).field("hp", 200) \
.field("speed", 10) \
.field("type1", "fire").field("type2", "flying") \
.time(now)
data = []
# Adding first point
data.append(
Point("caught")
.tag("trainer", "ash")
.tag("id", "0006")
.tag("num", "1")
.field("caught", "charizard")
.field("level", 10)
.field("attack", 30)
.field("defense", 40)
.field("hp", 200)
.field("speed", 10)
.field("type1", "fire")
.field("type2", "flying")
.time(now)
)
# Bad point
data.append(
Point("caught")
.tag("trainer", "ash")
.tag("id", "0008")
.tag("num", "3")
.field("caught", "squirtle")
.field("level", 13)
.field("attack", 29)
.field("defense", 40)
.field("hp", 180)
.field("speed", 13)
.field("type1", "water")
.field("type2", None)
.time(now)
)
try:
client.write(data)
except Exception as e:
print(f"Error writing point: {e}")
# Good Query
try:
table = client.query(query='''SELECT * FROM "caught" WHERE time > now() - 5m''', language='influxql')
print(table)
except Exception as e:
print(f"Error querying data: {e}")
# Bad Query - not a sql query
try:
table = client.query(query='''SELECT * FROM "caught" WHERE time > now() - 5m''', language='sql')
print(table)
except Exception as e:
print(f"Error querying data: {e}")