Created
January 27, 2018 20:55
-
-
Save Experiment5X/ab7ed86805863d22fccb8d7e79e4f138 to your computer and use it in GitHub Desktop.
PyLoko - basic usage of FourLoko API
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
import json | |
import requests | |
def find_loko(street_address): | |
request_params = { | |
'action': 'fourLoko/findProduct', | |
'address': street_address | |
} | |
web_response = requests.post('http://fourloko.com/find', data=request_params).text | |
json_data = json.loads(web_response) | |
return json_data['results'] | |
def format_flavors(flavors): | |
cleaned_flavors = [f for f in flavors if f is not None] | |
return ', '.join(cleaned_flavors) | |
address = input('Street Address: ') | |
loko_locations = find_loko(address) | |
for loko_location in loko_locations: | |
print(loko_location['name']) | |
print('%s %s, %s' % (loko_location['address'], loko_location['city'], loko_location['governingDistrict'])) | |
print('Flavors: ' + format_flavors(loko_location['otherBrands'])) | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment