Last active
August 23, 2018 14:41
-
-
Save Scrxtchy/02acdbcf118111971a5d414617f11d58 to your computer and use it in GitHub Desktop.
Maccas Android Offers
This file contains hidden or 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
import requests, json | |
from base64 import b64encode | |
from hashlib import md5 | |
config = { | |
"username":"[REDACTED]", | |
"password":"[REDACTED]", | |
"postcode":"3000", | |
"nonce": "happybaby", | |
"versionId": "0.0.1.I", | |
"application": "MOT" | |
} | |
api = requests.session() | |
api.headers['mcd_apikey'] = "AUandPROD2TIHIKU895DF68RT23ERIAU" | |
api.headers['MarketID'] = "AU.PROD2" | |
api.headers['X-NewRelic-ID'] = "UwUDUVNVGwIGVlVVDwkH" #UwU | |
api.headers['User-Agent'] = "User-Agent: Dalvik/2.1.0 (Linux; U; Android 8.1.0; Nexus 5X Build/OPM1.171019.011)" | |
def get(endpoint, params=None): | |
return api.get("https://ap.api.mcd.com/v3" + endpoint, params=params) | |
def post(endpoint, body=None): | |
return api.post("https://ap.api.mcd.com/v3" + endpoint, json=body) | |
def computeHash(Id, Version, Nonce): | |
return b64encode(md5("=PA64E47237FC34714AF852B795DAF8DEC\\o/{0}o|o{1}=/{2}".format(Version, Id, Nonce).encode('utf-8')).hexdigest().encode('utf-8')).decode('utf-8') | |
def login(username, password): | |
resp = post('/customer/session/sign-in-and-authenticate', body={ | |
"marketId": "AU", | |
"application": config["application"], | |
"languageName": "en-AU", | |
"platform": "android", | |
"versionId": config["versionId"], | |
"nonce": config["nonce"], | |
"hash": computeHash(config["application"], config["versionId"], config["nonce"]), | |
"userName": username, | |
"password": password, | |
"newPassword": None}) | |
api.headers["Token"] = resp.json()["Data"]["AccessData"]["Token"] | |
return resp | |
def postcodeLookup(postcode): | |
return requests.get('http://v0.postcodeapi.com.au/suburbs/{0}.json'.format(postcode)).json() #100 unique requests per hour, per IP | |
def getStores(latitude, longitude): | |
return get("/restaurant/location", params={ | |
"filter":"search", | |
"query":'{"market":"AU","pageSize":"25","local":"en-AU","generalStoreStatusCode":"OPEN,TEMPCLOSE,RENOVATION","locationCriteria":{"latitude":'+str(latitude)+',"longitude":'+str(longitude)+',"distance":"20"}}' | |
}) | |
def offers(latitude, longitude, storeid=None): | |
resp = get('/customer/offer', params={ | |
"marketId": "AU", | |
"application": config["application"], | |
"languageName": "en-AU", | |
"platform": "android", | |
"userName": config["username"], | |
"latitude": latitude, | |
"longitude": longitude, | |
"storeid": storeid | |
}) | |
return resp | |
import pprint | |
login(config["username"], config["password"]) | |
location = postcodeLookup(config["postcode"]) | |
stores = getStores(location[0]['latitude'], location[0]['longitude']).json() | |
pprint.pprint(offers(stores[0]['address']['location']['lat'], stores[0]['address']['location']['lon'], "[]".format(stores[0]['identifiers']['storeIdentifier'][0]['identifierValue'])).json()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment