Update example and some tweak
This commit is contained in:
@@ -4,69 +4,81 @@
|
|||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
logging.config.fileConfig('logging.conf')
|
||||||
from georideapilib.objects import GeorideAccount
|
from georideapilib.objects import GeorideAccount
|
||||||
import georideapilib.api as GeorideApi
|
import georideapilib.api as GeorideApi
|
||||||
|
from georideapilib.socket import GeorideSocket
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger('example')
|
||||||
|
|
||||||
|
|
||||||
def example():
|
def example():
|
||||||
""" simple example function """
|
""" simple example function """
|
||||||
token = "<your_token>"# pylint: disable=C0301
|
# 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>")
|
account = GeorideApi.get_authorisation_token("<your_email>", "<your_password>")
|
||||||
print("token 1: ", account.auth_token)
|
print("token 1: ", account.auth_token)
|
||||||
|
_LOGGER.info("token 1: %s", account.auth_token)
|
||||||
# pylint: disable=W0105
|
# pylint: disable=W0105
|
||||||
|
|
||||||
|
# socket = GeorideSocket()
|
||||||
|
# socket.init()
|
||||||
|
# socket.connect(account.auth_token)
|
||||||
|
# time.sleep(10)
|
||||||
|
# socket.disconnect()
|
||||||
|
|
||||||
"""
|
"""
|
||||||
account.auth_token = GeorideApi.renew_token(account.auth_token)
|
account.auth_token = GeorideApi.renewToken(account.auth_token)
|
||||||
print("token 2: ", account.auth_token)
|
print("token 2: ", account.auth_token)
|
||||||
""" # pylint: disable=W0105
|
""" # pylint: disable=W0105
|
||||||
|
|
||||||
user = GeorideApi.get_user(account.auth_token)
|
user = GeorideApi.get_user(account.auth_token)
|
||||||
print("User: ", user.first_name)
|
_LOGGER.info("User: %s", user.first_name)
|
||||||
|
|
||||||
trackers = GeorideApi.get_trackers(account.auth_token)
|
trackers = GeorideApi.get_trackers(account.auth_token)
|
||||||
tracker = trackers[0]
|
tracker = trackers[0]
|
||||||
print("Tracker name: ", tracker.tracker_name)
|
_LOGGER.info("Tracker name: %s", tracker.tracker_name)
|
||||||
|
|
||||||
trips = GeorideApi.get_trips(account.auth_token, tracker.tracker_id, "2019-10-10", "2019-10-24")
|
trips = GeorideApi.get_trips(account.auth_token, tracker.tracker_id, "2019-10-10", "2019-10-24")
|
||||||
trip = trips[0]
|
trip = trips[0]
|
||||||
trip_date = datetime.datetime.strptime("2019-10-10T06:45:34.000Z", '%Y-%m-%dT%H:%M:%S.%fZ')
|
trip_date = datetime.datetime.strptime("2019-10-10T06:45:34.000Z", '%Y-%m-%dT%H:%M:%S.%fZ')
|
||||||
print("Trip date: {}, from: {}, to: {}".format(trip_date, trip.nice_start_address,
|
_LOGGER.info("Trip date: %s, from: %s, to: %s", trip_date, trip.nice_start_address,
|
||||||
trip.nice_end_address))
|
trip.nice_end_address)
|
||||||
|
|
||||||
positions = GeorideApi.get_positions(account.auth_token, tracker.tracker_id,
|
positions = GeorideApi.get_positions(account.auth_token, tracker.tracker_id,
|
||||||
"2019-10-10", "2019-10-24")
|
"2019-10-10", "2019-10-24")
|
||||||
position = positions[0]
|
position = positions[0]
|
||||||
print("Position speed: {}, lon: {}, lat: {}".format(position.speed, position.longitude,
|
_LOGGER.info("Position speed: %s, lon: %s, lat: %s", position.speed, position.longitude,
|
||||||
position.latitude))
|
position.latitude)
|
||||||
|
|
||||||
|
|
||||||
trip_shared = GeorideApi.share_a_trip_by_date(account.auth_token, tracker.tracker_id,
|
trip_shared = GeorideApi.share_a_trip_by_date(account.auth_token, tracker.tracker_id,
|
||||||
"2019-10-10", "2019-10-24")
|
"2019-10-10", "2019-10-24")
|
||||||
print("tripShared url: {}, id: {}".format(trip_shared.url, trip_shared.share_id))
|
_LOGGER.info("tripShared url: %s, id: %s", trip_shared.url, trip_shared.share_id)
|
||||||
|
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
have_been_locked = GeorideApi.lock_tracker(account.auth_token, tracker.tracker_id)
|
have_been_locked = GeorideApi.lock_tracker(account.auth_token, tracker.tracker_id)
|
||||||
print("Tracker have been locked: ", have_been_locked)
|
_LOGGER.info("Tracker have been locked: %s", have_been_locked)
|
||||||
|
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
have_been_unlocked = GeorideApi.unlock_tracker(account.auth_token, tracker.tracker_id)
|
have_been_unlocked = GeorideApi.unlock_tracker(account.auth_token, tracker.tracker_id)
|
||||||
print("Tracker have been unlocked: ", have_been_unlocked)
|
_LOGGER.info("Tracker have been unlocked: %s", have_been_unlocked)
|
||||||
|
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
is_locked = GeorideApi.toogle_lock_tracker(account.auth_token, tracker.tracker_id)
|
is_locked = GeorideApi.toogle_lock_tracker(account.auth_token, tracker.tracker_id)
|
||||||
print("Tracker is locked: ", is_locked)
|
_LOGGER.info("Tracker is locked: %s", is_locked)
|
||||||
|
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
trackers = GeorideApi.get_trackers(account.auth_token)
|
trackers = GeorideApi.get_trackers(account.auth_token)
|
||||||
tracker = trackers[0]
|
tracker = trackers[0]
|
||||||
print("Tracker name: ", tracker.tracker_name, " is locked: ", tracker.is_locked)
|
_LOGGER.info("Tracker name: %s is locked: %s", tracker.tracker_name, tracker.is_locked)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
GeorideApi.revokeToken(account.auth_token)
|
GeorideApi.revokeToken(account.auth_token)
|
||||||
""" # pylint: disable=W0105
|
""" # pylint: disable=W0105
|
||||||
|
|
||||||
example()
|
example()
|
||||||
|
|||||||
@@ -5,12 +5,8 @@ import socketio
|
|||||||
from georideapilib.api import GEORIDE_API_HOST
|
from georideapilib.api import GEORIDE_API_HOST
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
_LOGGER.setLevel(logging.DEBUG)
|
|
||||||
# create console handler and set level to debug
|
|
||||||
CH = logging.StreamHandler()
|
|
||||||
CH.setLevel(logging.DEBUG)
|
|
||||||
|
|
||||||
sio = socketio.Client(reconnection=True)
|
sio = socketio.Client(reconnection=True) # pylint: disable=C0103
|
||||||
|
|
||||||
@sio.on('connect')
|
@sio.on('connect')
|
||||||
def on_connect():
|
def on_connect():
|
||||||
@@ -65,42 +61,42 @@ class GeorideSocket():
|
|||||||
@sio.on('message')
|
@sio.on('message')
|
||||||
def on_message(data):
|
def on_message(data):
|
||||||
""" on_message """
|
""" on_message """
|
||||||
_LOGGER.debug('Message recieved: %s', data)
|
_LOGGER.debug('Message received: %s', data)
|
||||||
if self._on_message_callback is not None:
|
if self._on_message_callback is not None:
|
||||||
self._on_message_callback()
|
self._on_message_callback()
|
||||||
|
|
||||||
@sio.on('device')
|
@sio.on('device')
|
||||||
def on_device(data):
|
def on_device(data):
|
||||||
""" on_device """
|
""" on_device """
|
||||||
_LOGGER.debug('Device recieved: %s', data)
|
_LOGGER.debug('Device received: %s', data)
|
||||||
if self._on_device_callback is not None:
|
if self._on_device_callback is not None:
|
||||||
self._on_device_callback()
|
self._on_device_callback()
|
||||||
|
|
||||||
@sio.on('position')
|
@sio.on('position')
|
||||||
def on_position(data):
|
def on_position(data):
|
||||||
""" on_position """
|
""" on_position """
|
||||||
_LOGGER.debug('Position recieved:%s', data)
|
_LOGGER.debug('Position received:%s', data)
|
||||||
if self._on_position_callback is not None:
|
if self._on_position_callback is not None:
|
||||||
self._on_position_callback()
|
self._on_position_callback()
|
||||||
|
|
||||||
@sio.on('alarm')
|
@sio.on('alarm')
|
||||||
def on_alarm(data):
|
def on_alarm(data):
|
||||||
""" on_alarm """
|
""" on_alarm """
|
||||||
_LOGGER.debug('Alarm recieved: %s', data)
|
_LOGGER.debug('Alarm received: %s', data)
|
||||||
if self._on_alarm_callback is not None:
|
if self._on_alarm_callback is not None:
|
||||||
self._on_alarm_callback(data)
|
self._on_alarm_callback(data)
|
||||||
|
|
||||||
@sio.on('refreshTrackersInstruction')
|
@sio.on('refreshTrackersInstruction')
|
||||||
def on_refresh_tracker():
|
def on_refresh_tracker():
|
||||||
""" on_refresh_tracker """
|
""" on_refresh_tracker """
|
||||||
_LOGGER.debug('Refresh tracker recieved')
|
_LOGGER.debug('Refresh tracker received')
|
||||||
if self._on_refresh_tracker_callback is not None:
|
if self._on_refresh_tracker_callback is not None:
|
||||||
self._on_refresh_tracker_callback()
|
self._on_refresh_tracker_callback()
|
||||||
|
|
||||||
@sio.on('lockedPosition')
|
@sio.on('lockedPosition')
|
||||||
def on_locked(data):
|
def on_locked(data):
|
||||||
""" on_locked """
|
""" on_locked """
|
||||||
_LOGGER.debug('Locked recieved: %s', data)
|
_LOGGER.debug('Locked received: %s', data)
|
||||||
if self._on_locked_callback is not None:
|
if self._on_locked_callback is not None:
|
||||||
self._on_locked_callback()
|
self._on_locked_callback()
|
||||||
|
|
||||||
@@ -108,7 +104,6 @@ class GeorideSocket():
|
|||||||
|
|
||||||
def connect(self, auth_token):
|
def connect(self, auth_token):
|
||||||
""" connect to the georide socket"""
|
""" connect to the georide socket"""
|
||||||
_LOGGER.info("Start conection")
|
|
||||||
if self._initialised is not False:
|
if self._initialised is not False:
|
||||||
sio.connect(GEORIDE_API_HOST, headers={'token': auth_token})
|
sio.connect(GEORIDE_API_HOST, headers={'token': auth_token})
|
||||||
sio.wait()
|
sio.wait()
|
||||||
|
|||||||
29
logging.conf
Normal file
29
logging.conf
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
[loggers]
|
||||||
|
keys=root,example
|
||||||
|
|
||||||
|
[handlers]
|
||||||
|
keys=consoleHandler
|
||||||
|
|
||||||
|
[formatters]
|
||||||
|
keys=simpleFormatter
|
||||||
|
|
||||||
|
[logger_root]
|
||||||
|
level=DEBUG
|
||||||
|
handlers=consoleHandler
|
||||||
|
|
||||||
|
[logger_example]
|
||||||
|
level=DEBUG
|
||||||
|
handlers=consoleHandler
|
||||||
|
qualname=simpleExample
|
||||||
|
propagate=0
|
||||||
|
|
||||||
|
|
||||||
|
[handler_consoleHandler]
|
||||||
|
class=StreamHandler
|
||||||
|
level=DEBUG
|
||||||
|
formatter=simpleFormatter
|
||||||
|
args=(sys.stdout,)
|
||||||
|
|
||||||
|
[formatter_simpleFormatter]
|
||||||
|
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
|
||||||
|
datefmt=
|
||||||
Reference in New Issue
Block a user