Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ############################################
- ######## GPS Trajectory / Presences ########
- ############################################
- #0. Import libraries
- #0. Declare links
- #1. Get current time
- #2. Authentificate for vehicle ID
- #3. Authentificate in Safefleet platform
- #3. Use vehicle ID to get presence
- #Get GPS data at specific time from truck
- #Currently it does 2 authentifications - only to get the vehicle_id - is it static and we should save it?
- #Trebuie să prelucrez rapoarte
- #0. Import libraries
- import subprocess
- import requests
- import json
- import os
- import time
- import concurrent.futures
- from datetime import datetime
- import glob
- import datetime
- #0. Declare links
- presences_messages = "https://delta.safefleet.eu/safefleet/api/vehicles/21835/presences"
- #1. Get current time
- print("----------------1----------------")
- print("#1. Get current time")
- a = datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%SZ')
- print(a)
- #2. Authentificate for vehicle ID
- #print("----------------2----------------")
- #print("#2. Authentificate for vehicle ID")
- '''
- #Authentificate vehicle of vehicle id
- api_safefleet_authenticate = 'https://delta.safefleet.eu/safefleet/api/authenticate_vehicle'
- authenticate = requests.post(api_safefleet_authenticate, headers = {'Content-Type': 'application/json'}, json = {
- 'license_plate': "TM-60-JYT",
- 'pin': "068318"
- })
- print("authenticate: ", authenticate.text, "\n")
- vehicle_id = json.loads(authenticate.text)['vehicle']['vehicle_id']
- print("vehicle_id: ", vehicle_id, "\n")
- '''
- vehicle_id = 21838
- car_license_plate = "TM-60-JYT"
- car_pin = "068318"
- #3. Authentificate in Safefleet platform
- print("----------------3----------------")
- print("#3. Authentificate in Safefleet platform")
- api_safefleet_authenticate_vehicle = "https://delta.safefleet.eu/safefleet/api/authenticate_vehicle"
- #Authentificate with license plate
- authenticate_vehicle = requests.post(api_safefleet_authenticate_vehicle, \
- headers = {'Content-Type': 'application/json'}, \
- json = {'license_plate': car_license_plate, 'pin': car_pin})
- print(f"authenticate_vehicle: {authenticate_vehicle}")
- print(f"authenticate_vehicle.text: {authenticate_vehicle.text}")
- print("")
- api_safefleet_authenticate_platform = 'https://delta.safefleet.eu/safefleet/api/authenticate'
- authenticate = requests.post(api_safefleet_authenticate_platform, \
- headers = {'Content-Type': 'application/json'}, \
- json = {'username': "polymore", 'password': "123456"})
- print(f"authenticate: {authenticate}")
- print(f"authenticate.text: {authenticate.text}")
- '''
- '''
- #4. Use vehicle ID to get presence
- print("----------------4----------------")
- print("#4. Use vehicle ID to get presence")
- api_safefleet_vehicle_info = 'https://delta.safefleet.eu/safefleet/api/vehicles/'
- vehicle_info = requests.get(api_safefleet_vehicle_info + str(vehicle_id), cookies=authenticate.cookies)
- print(vehicle_info.url)
- parsed_vehicle_info = json.loads(vehicle_info.text)
- print(f"parsed_vehicle_info: {parsed_vehicle_info}")
- lat = parsed_vehicle_info['current_info']['lat']
- lng = parsed_vehicle_info['current_info']['lng']
- print(f"lat: {lat}")
- print(f"lng: {lng}")
- print("----------------5----------------")
- #vehicle_info = requests.get(presences_messages, \
- # json={'start_moment': '2022-04-22T11:28:40Z', 'stop_moment': '2022-04-22T11:29:40Z'}, cookies = authenticate.cookies)
- api_safefleet_authenticate_platform = 'https://delta.safefleet.eu/safefleet/api/authenticate'
- authenticate = requests.post(api_safefleet_authenticate_platform, \
- headers = {'Content-Type': 'application/json'}, \
- json = {'username': "polymore", 'password': "123456"})
- print(authenticate)
- print(authenticate.text)
- print()
- api_safefleet_presences = f"https://delta.safefleet.eu/safefleet/api/vehicles/{vehicle_id}/presences/"
- print(api_safefleet_presences)
- #presences = requests.get(api_safefleet_presences, \
- # json = {'start_moment': '2022-05-03', 'stop_moment': '2022-05-03'}, cookies = authenticate.cookies)
- #print(authenticate.cookies)
- print("----------------6----------------")
- api_safefleet_presences = f"https://delta.safefleet.eu/safefleet/api/vehicles/{vehicle_id}/presences/"
- #json=json.loads('{'start_moment': '2022-03-26T03:14:15Z', 'stop_moment': '2022-03-26T03:14:55'}')
- json2=json.loads('{"start_moment": "2022-03-26T03:14:15Z", "stop_moment": "2022-03-26T03:14:25Z"}')
- vehicle_info = requests.get(api_safefleet_presences, json=json2, cookies = authenticate.cookies)
- print(vehicle_info)
- print(vehicle_info.text)
- #presences = requests.get(api_safefleet_presences, \
- # json={'start_moment': '2022-05-03T17:12:44Z', 'stop_moment': '2022-05-03T17:22:44Z'})
- print("----------------7----------------")
- #presences = requests.get(api_safefleet_presences, cookies = authenticate.cookies)
- #print(type(presences))
- #print("vehicle_info: ", presences.text, "\n")
- #parsed_vehicle_info = json.loads(presences.text)
- #print(type(parsed_vehicle_info))
- #print("parsed_vehicle_info: ", parsed_vehicle_info)
- #print()
- #print(parsed_vehicle_info)#['start'])#['moment'])
- #print("\n\n")
- try:
- vehicle_id2 = json.loads(authenticate.text)['vehicle']['vehicle_id']
- vehicle_info2 = requests.get(api_safefleet_vehicle_info + str(vehicle_id), cookies=authenticate.cookies)
- parsed_vehicle_info2 = json.loads(vehicle_info2.text)
- lat = parsed_vehicle_info2['current_info']['lat']
- lng = parsed_vehicle_info2['current_info']['lng']
- print(lat, lng)
- except KeyError as e:
- print(f"KeyError: {e}")
- #journey = json.loads(vehicle_info.text)[0]['start']['moment']
- #journey = parsed_vehicle_info[0]['start']['moment']
- #print("lat: ", journey)
- #lat = parsed_vehicle_info['current_info']['lat']
- #lng = parsed_vehicle_info['current_info']['lng']
- #print(lat, lng)
- '''
- authenticate = requests.post(api_safefleet_authenticate, headers = {'Content-Type': 'application/json'}, json = {
- 'username': "polymore",
- 'password': "123456"
- })
- '''
- '''
- print(authenticate.text)
- print()
- #/vehicles/{vehicle_id}/journeys
- vehicle_id = json.loads(authenticate.text)['vehicles']['vehicle_id']#['journeys']
- print(vehicle_id.text)
- print()
- #/vehicles/{vehicle_id}/journeys
- '''
- '''
- "journeys": [
- {
- "journey_id": String,
- "start": {
- "moment": String,
- "lat": Number,
- "lng": Number
- },
- [
- {
- "presence_id": String,
- "moment": String,
- "lat": Number,
- "lng": Number,
- "speed": Number,
- "azimuth": Number,
- "engine": Boolean
- },
- ...
- ]
- -----------------------------------
- [
- {
- "driver_id": null,
- "start": {
- "lat": 46.204275,
- "moment": "2022-04-11T09:49:28Z",
- "lng": 21.3176666
- },
- "max_speed": 0,
- "purpose": null,
- "consumption": {
- "measured": true,
- "value": 0
- },
- "distance": 0.006,
- "idle_duration": 0.0,
- "journey_code": null,
- "stop": {
- "lat": 46.2042,
- "moment": "2022-04-11T09:49:46Z",
- "lng": 21.3176583
- },
- "journey_id": "6253f9bd62768638e1c980b6"
- }
- ]
- [
- {
- "journey_id": String,
- "start": {
- "moment": String,
- "lat": Number,
- "lng": Number
- },
- "stop": {
- "moment": String,
- "lat": Number,
- "lng": Number
- },
- "distance": Number,
- "idle_duration": Number,
- "consumption": {
- "value": Number,
- "measured": Boolean
- },
- "max_speed": Number,
- "driver_id": Number,
- "purpose": String,
- "journey_code": String
- },
- ...
- ]
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement