Romeo David commited on
Commit
fd22ee2
·
1 Parent(s): 151a0e2

fixed gmt 8 timestamp in telemetry

Browse files
Files changed (1) hide show
  1. telemetry.py +10 -0
telemetry.py CHANGED
@@ -1,5 +1,6 @@
1
  import os
2
  import json
 
3
  from pymongo import MongoClient
4
  from dotenv import load_dotenv
5
 
@@ -18,6 +19,15 @@ def collect_telemetry(data):
18
  return
19
 
20
  try:
 
 
 
 
 
 
 
 
 
21
  client = MongoClient(mongodb_uri)
22
  db = client.get_database() # Use the default database specified in the URI
23
  collection = db["telemetry"] # Replace "telemetry" with your desired collection name
 
1
  import os
2
  import json
3
+ from datetime import datetime, timedelta, timezone
4
  from pymongo import MongoClient
5
  from dotenv import load_dotenv
6
 
 
19
  return
20
 
21
  try:
22
+ # Get the current UTC time
23
+ utc_now = datetime.now(timezone.utc)
24
+
25
+ # Define the GMT+8 timezone offset
26
+ gmt_plus_8 = timezone(timedelta(hours=8))
27
+
28
+ # Convert the UTC time to GMT+8
29
+ timestamp = utc_now.astimezone(gmt_plus_8).isoformat()
30
+ data['timestamp'] = timestamp
31
  client = MongoClient(mongodb_uri)
32
  db = client.get_database() # Use the default database specified in the URI
33
  collection = db["telemetry"] # Replace "telemetry" with your desired collection name