waze icon indicating copy to clipboard operation
waze copied to clipboard

Doesn't work anymore

Open Sigmun opened this issue 7 years ago • 6 comments

The SESSION_LIST_URL and SESSON_DATA_URL seems to have change. It looks like they now have to be set at

SESSION_LIST_URL = "https://www.waze.com/row-Descartes/app/Archive/List"
SESSON_DATA_URL = "https://www.waze.com/row-Descartes/app/Archive/SessionGPS"

but even with these changes, it is not able to generate the kml file.

It also looks like waze modified the structure of the json containing the data. I am not sure of what it is possible to do.

Sigmun avatar Mar 17 '17 12:03 Sigmun

yep, they removed the detailed GML data from their frontend about a year and a a half ago, game over, sad :(

dferrante avatar Mar 17 '17 14:03 dferrante

Too bad. Any app to process data in the same way ?

Sigmun avatar Mar 20 '17 06:03 Sigmun

not that i know of

dferrante avatar Mar 23 '17 21:03 dferrante

@dferrante You underestimate your product :) Thank you very much, I've taken your "exportdrivers.py" script, very easily modified for my needs (I was needed just simply export my recent 5k kilometers trip to KML format so that I can import it to Google Maps), 'cause you already have done all hard work.

import os
import sys
import json
import datetime
import requests
from tqdm import *
from lxml import etree
from pykml.parser import Schema
from pykml.factory import KML_ElementMaker as KML
from pykml.factory import GX_ElementMaker as GX

# waze API urls
GET_CSRF_URL = "https://www.waze.com/login/get"
SESSION_URL = "https://www.waze.com/login/create"
SESSION_LIST_URL = "https://www.waze.com/row-Descartes/app/Archive/List"
SESSON_DATA_URL = "https://www.waze.com/row-Descartes/app/Archive/SessionGPS"

# specify your real credentials here
username = ""
password = ""

# login
req = requests.get(GET_CSRF_URL)
csrfdict = dict(req.cookies)
csrfdict['editor_env'] = 'usa'
headers = {'X-CSRF-Token': csrfdict['_csrf_token']}

req = requests.post(SESSION_URL, data={'user_id': username, 'password': password}, cookies=csrfdict, headers=headers)

try:
    authdict = dict(req.cookies)
except:
    log.error('login failed, check credentials')
    sys.exit(255)

doc = KML.kml(
    KML.Document(
        KML.Name("Waze")
    )
)

# get sessions
sessionlist = []
for offset in range(0, 500, 50):
    response = requests.get(SESSION_LIST_URL, params={'count': 50, 'offset': offset}, cookies=authdict).json()
    sessions = response['archives']['objects']
    if not sessions:
        break
    sessionlist += [x for x in sessions]

files = []
for session in tqdm(sessionlist, 'converting to kml', leave=True):
    try:
        starttime = datetime.datetime.fromtimestamp(session['startTime']/1000)
        endtime = datetime.datetime.fromtimestamp(session['endTime']/1000)
        length = round(session['totalRoadMeters']*.000621371, 1)
        filename = '%s-%s-%smi' % (starttime.strftime('%y-%m-%d-%H:%M'), endtime.strftime('%y-%m-%d-%H:%M'), length)
    except:
        continue

    kmlfile = 'data/%s.kml' % filename
    if not os.path.exists(kmlfile):
        data = requests.get(SESSON_DATA_URL, params={'id': session['id']}, cookies=authdict)

        jsonDriveParts = data.json()['archiveSessions']['objects'][0]['driveParts']

        drivePartsCoordinates = []
        for dpc in jsonDriveParts:
            drivePartsCoordinates += [x for x in dpc['geometry']['coordinates']]

        kmlCoordinates = ""
        for lat, lng in drivePartsCoordinates:
            kmlCoordinates += "%s, %s " % (lat, lng)

        lineString = KML.Placemark(
            KML.name('%s | %s' % (starttime.strftime('%d-%m-%y %H:%M'), endtime.strftime('%d-%m-%y %H:%M'))),
            KML.styleUrl("#transBluePoly"),
            KML.LineString(
                KML.coordinates(
                    kmlCoordinates.rstrip()
                )
            )
        )

        doc.Document.append(lineString)

outfile = file(kmlfile,'w')
outfile.write(etree.tostring(doc, pretty_print=True))
print "Done!"

anton-kasperovich avatar Sep 10 '17 19:09 anton-kasperovich

@dferrante You underestimate your product :) Thank you very much, I've taken your "exportdrivers.py" script, very easily modified for my needs (I was needed just simply export my recent 5k kilometers trip to KML format so that I can import it to Google Maps), 'cause you already have done all hard work.

import os
import sys
import json
import datetime
import requests
from tqdm import *
from lxml import etree
from pykml.parser import Schema
from pykml.factory import KML_ElementMaker as KML
from pykml.factory import GX_ElementMaker as GX

# waze API urls
GET_CSRF_URL = "https://www.waze.com/login/get"
SESSION_URL = "https://www.waze.com/login/create"
SESSION_LIST_URL = "https://www.waze.com/row-Descartes/app/Archive/List"
SESSON_DATA_URL = "https://www.waze.com/row-Descartes/app/Archive/SessionGPS"

# specify your real credentials here
username = ""
password = ""

# login
req = requests.get(GET_CSRF_URL)
csrfdict = dict(req.cookies)
csrfdict['editor_env'] = 'usa'
headers = {'X-CSRF-Token': csrfdict['_csrf_token']}

req = requests.post(SESSION_URL, data={'user_id': username, 'password': password}, cookies=csrfdict, headers=headers)

try:
    authdict = dict(req.cookies)
except:
    log.error('login failed, check credentials')
    sys.exit(255)

doc = KML.kml(
    KML.Document(
        KML.Name("Waze")
    )
)

# get sessions
sessionlist = []
for offset in range(0, 500, 50):
    response = requests.get(SESSION_LIST_URL, params={'count': 50, 'offset': offset}, cookies=authdict).json()
    sessions = response['archives']['objects']
    if not sessions:
        break
    sessionlist += [x for x in sessions]

files = []
for session in tqdm(sessionlist, 'converting to kml', leave=True):
    try:
        starttime = datetime.datetime.fromtimestamp(session['startTime']/1000)
        endtime = datetime.datetime.fromtimestamp(session['endTime']/1000)
        length = round(session['totalRoadMeters']*.000621371, 1)
        filename = '%s-%s-%smi' % (starttime.strftime('%y-%m-%d-%H:%M'), endtime.strftime('%y-%m-%d-%H:%M'), length)
    except:
        continue

    kmlfile = 'data/%s.kml' % filename
    if not os.path.exists(kmlfile):
        data = requests.get(SESSON_DATA_URL, params={'id': session['id']}, cookies=authdict)

        jsonDriveParts = data.json()['archiveSessions']['objects'][0]['driveParts']

        drivePartsCoordinates = []
        for dpc in jsonDriveParts:
            drivePartsCoordinates += [x for x in dpc['geometry']['coordinates']]

        kmlCoordinates = ""
        for lat, lng in drivePartsCoordinates:
            kmlCoordinates += "%s, %s " % (lat, lng)

        lineString = KML.Placemark(
            KML.name('%s | %s' % (starttime.strftime('%d-%m-%y %H:%M'), endtime.strftime('%d-%m-%y %H:%M'))),
            KML.styleUrl("#transBluePoly"),
            KML.LineString(
                KML.coordinates(
                    kmlCoordinates.rstrip()
                )
            )
        )

        doc.Document.append(lineString)

outfile = file(kmlfile,'w')
outfile.write(etree.tostring(doc, pretty_print=True))
print "Done!"

This is what print (req.text) returns to me:

{"reply":{"error":429,"message":"rate exceeded","user_id":-1,"rank":0,"full_name":"","login":false}}

capedra avatar Oct 12 '18 08:10 capedra

@anton-kasperovich How may we solve that?

capedra avatar Oct 12 '18 08:10 capedra