Skip to content

Commit

Permalink
fix date
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-f committed Sep 23, 2024
1 parent 782d12f commit 9427ecb
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion services/telit/generate_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
import argparse
import datetime
import os
import time

def epoch_to_elasticsearch_date(epoch):
"""
strict_date_optional_time in elastic search format is
yyyy-MM-dd'T'HH:mm:ss.SSSZ
@rtype: string
"""
return datetime.datetime.fromtimestamp(epoch, tz=datetime.UTC).strftime(
"%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z"

def open_file_for_write(filename):
return gzip.open(filename, 'at')
Expand Down Expand Up @@ -41,7 +51,8 @@ def main():
type=str)
args = parser.parse_args()
time_part = datetime.datetime.now().strftime(args.time_format)
document = {"date": time_part,"TPV": {"lat": args.latitude,"lon": args.longitude,"alt": args.altitude},"hwa": args.hwa}
document = {"date": epoch_to_elasticsearch_date(
time.time()),"TPV": {"lat": args.latitude,"lon": args.longitude,"alt": args.altitude},"hwa": args.hwa}
# create special entry specifically for elastic search
document["location"] = {"lat": document["TPV"]["lat"],
"lon": document["TPV"]["lon"],
Expand Down

0 comments on commit 9427ecb

Please sign in to comment.