Last active
April 4, 2023 06:49
-
-
Save anthonydouc/ac0b4251d6dd0626280d50648f1dff01 to your computer and use it in GitHub Desktop.
PTV API signature generator code - Python 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from hashlib import sha1 | |
import hmac | |
def getUrl(request): | |
devId = 1000000 | |
key = bytes('mykey','UTF-8') | |
request = request + ('&' if ('?' in request) else '?') | |
raw = bytes(request+'devid={0}'.format(devId),'UTF-8') | |
hashed = hmac.new(key, raw, sha1) | |
signature = hashed.hexdigest() | |
raw = str(raw,'UTF-8') | |
return 'http://timetableapi.ptv.vic.gov.au/'+raw+'&signature={1}'.format(devId, signature),'UTF-8' | |
request_url = '/v3/routes' | |
print(getUrl(request_url)) |
JFC, thank you.
You are welcome. whats JFC mean?
Jesus Fucking Christ :)
Sorry, PTV’s explanation on how to calculate the signature truly sucked. I wasn’t far off though! Nonetheless, thanks mate, I owe you a beer.
Ah yep, it made literally no sense - leading me to post this here in the off chance others struggled and found it.
Yeah, right. To be honest, I actually almost had it right but was missing a
slash from the endpoint. What a crazy way of authenticating tho?!
Anywhoo, cheers!
…On Sun, Aug 16, 2020 at 11:32 PM Anthony Doucouliagos < ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Ah yep, it made literally no sense - leading me to post this here in the
off chance others struggled and found it.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://gist.github.com/ac0b4251d6dd0626280d50648f1dff01#gistcomment-3419101>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJ2DV7ATFZ66CVXWL7SFULSA7NXPANCNFSM4P4SOUVA>
.
Thanks for this, I was really stuck.
One comment is that you can change line 14 to remove reference to "devID" as you already deal with it in line 9. eg
return 'http://timetableapi.ptv.vic.gov.au'+raw+'&signature={0}'.format(signature)
For me this removes a Type warning.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
JFC, thank you.