# # Works with version: Python 2.7.1 (r271:86832, Aug 5 2011, 03:30:24) # import hashlib # Source file: http://hg.python.org/cpython/file/2.7/Lib/hashlib.py import time import urllib class FandangoApiManager(object): def __init__(self): self.FandangoApiManager = [ ] def Sha256Encode(self, stringToEncode): s = hashlib.sha256(); s.update(stringToEncode) result = s.hexdigest() return result def BuildAuthorizationParameters(self, apiKey, sharedSecret): paramsToEncode = "{0}{1}{2}".format(apiKey, sharedSecret, int(time.time())) encodedParams = self.Sha256Encode(paramsToEncode) result = "apikey={0}&sig={1}".format(apiKey, encodedParams) return result def GetResponse(self, parameters): baseUri = "http://api.fandango.com" apiVersion = "1" apiKey = "ypsvs4ud7cp2q6geey5y9y98" sharedSecret = "y7UZWj8Sga" authorizationParameters = self.BuildAuthorizationParameters(apiKey, sharedSecret) requestUri = "{0}/v{1}/?{2}&{3}".format(baseUri, apiVersion, parameters, authorizationParameters) response = urllib.urlopen(requestUri) result = response.read() return result def main(): api = FandangoApiManager() zipCode = "87104"; parameters = "op=theatersbypostalcodesearch&postalcode={0}".format(zipCode) responseFromServer = api.GetResponse(parameters) print responseFromServer # process responseFromServer... if __name__ == "__main__": main()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question