Rework of GeoRide objects and add missing fields on Traker

This commit is contained in:
Matthieu DUVAL
2023-02-27 18:06:19 +01:00
parent edf209272d
commit 7e399cf982
14 changed files with 1309 additions and 1164 deletions

View File

@@ -1,9 +1,7 @@
""" Example georideapilib code """
import logging.config
import time
import datetime
logging.config.fileConfig('logging.conf')
from georideapilib.objects import GeoRideAccount
import georideapilib.api as GeoRideApi
@@ -13,11 +11,13 @@ from threading import Thread
_LOGGER = logging.getLogger('example')
DATE_START="2019-10-10"
DATE_END="2019-10-24"
def example():
""" simple example function """
# token = "<your_token>"# pylint: disable=C0301
# account = GeorideAccount(0, "<your_email>", False, token)
# account = GeoRideAccount(0, "<your_email>", False, token)
account = GeoRideApi.get_authorisation_token("<your_email>", "<your_password>")
@@ -40,7 +40,7 @@ def example():
time.sleep(10)
socket.disconnect()
thread = Thread(target=connect_socket, args=(account))
thread = Thread(target=connect_socket, args=[account])
thread.start()
"""
@@ -55,21 +55,26 @@ def example():
tracker = trackers[0]
_LOGGER.info("Tracker name: %s", tracker.tracker_name)
trips = GeoRideApi.get_trips(account.auth_token, tracker.tracker_id, "2019-10-10", "2019-10-24")
trip = trips[0]
trip_date = datetime.datetime.strptime("2019-10-10T06:45:34.000Z", '%Y-%m-%dT%H:%M:%S.%fZ')
_LOGGER.info("Trip date: %s, from: %s, to: %s", trip_date, trip.nice_start_address,
trip.nice_end_address)
trips = GeoRideApi.get_trips(account.auth_token, tracker.tracker_id, DATE_START, DATE_END)
if len(trips) < 1:
_LOGGER.info("No trip found for tracker name: %s between: %s and %s", tracker.tracker_name, DATE_START, DATE_END)
else:
trip = trips[0]
trip_date = datetime.datetime.strptime("2019-10-10T06:45:34.000Z", '%Y-%m-%dT%H:%M:%S.%fZ')
_LOGGER.info("Trip date: %s, from: %s, to: %s", trip_date, trip.nice_start_address,
trip.nice_end_address)
positions = GeoRideApi.get_positions(account.auth_token, tracker.tracker_id,
"2019-10-10", "2019-10-24")
position = positions[0]
_LOGGER.info("Position speed: %s, lon: %s, lat: %s", position.speed, position.longitude,
position.latitude)
DATE_START, DATE_END)
if len(positions) < 1:
_LOGGER.info("No positions found for tracker name: %s between: %s and %s", tracker.tracker_name, DATE_START, DATE_END)
else:
position = positions[0]
_LOGGER.info("Position speed: %s, lon: %s, lat: %s", position.speed, position.longitude,
position.latitude)
trip_shared = GeoRideApi.share_a_trip_by_date(account.auth_token, tracker.tracker_id,
"2019-10-10", "2019-10-24")
DATE_START, DATE_END)
_LOGGER.info("tripShared url: %s, id: %s", trip_shared.url, trip_shared.share_id)
time.sleep(10)