Skip to content

Instantly share code, notes, and snippets.

@TheSkorm
Last active September 16, 2018 07:16
Show Gist options
  • Select an option

  • Save TheSkorm/8941112cce8bfd287b26b1bb2ff55f78 to your computer and use it in GitHub Desktop.

Select an option

Save TheSkorm/8941112cce8bfd287b26b1bb2ff55f78 to your computer and use it in GitHub Desktop.
Reverse engineered API for vline
#requires python3
# pip3 install xmltodict --user
import hashlib
import hmac
import base64
import xmltodict
# https://gist.github.com/heskyji/5167567b64cb92a910a3
def make_digest(message, key):
key = bytes(key, 'UTF-8')
message = bytes(message, 'UTF-8')
digester = hmac.new(key, message, hashlib.sha1)
#signature1 = digester.hexdigest()
signature1 = digester.digest()
#print(signature1)
#signature2 = base64.urlsafe_b64encode(bytes(signature1, 'UTF-8'))
signature2 = signature1.hex()
#print(signature2)
return signature2
endpoint = "https://www.vline.com.au/apps/JourneyPlannerWCFServicesV2"
callerid = "2710A5E7-D3DD-4B73-97CE-0DF3E411F56D"
key = "A0A22396-257B-448B-B2B3-51D3216DC62D"
method_url = "/Service/VLinePlatformServices.svc/web/GetPlatformDepartures?LocationName=Melbourne,%20Southern%20Cross&Direction=D"
method_key = "JP_GETPLATFORMDEPARTURES"
tohmac = callerid + method_key
token = make_digest(tohmac, key)
url = endpoint + method_url + "&CallerID=" + callerid + "&AccessToken=" + token
import urllib.request
with urllib.request.urlopen(url) as response:
html = response.read()
data = xmltodict.parse(html)
for service in data['GetPlatformDeparturesResponse']['GetPlatformDeparturesResult']['a:PlatformService']:
destination = service['a:Destination']
platform = service['a:Platform']
departing = service['a:ScheduledDepartureTime']
print('{} {} {}'.format(platform, departing ,destination))
# 3B 2018-09-16T17:10:00 Waurn Ponds Station
# 1 2018-09-16T17:16:00 Wendouree Station
# 15 2018-09-16T17:20:00 Echuca Station
# 7A 2018-09-16T17:32:00 Seymour Station
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment