Last active
October 27, 2015 20:47
-
-
Save psychemedia/f7385255f89137c503b5 to your computer and use it in GitHub Desktop.
Code Club week 7 code resources
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
| from IPython.display import HTML | |
| import folium | |
| def inline_map(map): | |
| """ | |
| Embeds the HTML source of the map directly into the IPython notebook. | |
| This method will not work if the map depends on any files (json data). Also this uses | |
| the HTML5 srcdoc attribute, which may not be supported in all browsers. | |
| """ | |
| map._build_map() | |
| return HTML('<iframe srcdoc="{srcdoc}" style="width: 100%; height: 510px; border: none"></iframe>'.format(srcdoc=map.HTML.replace('"', '"'))) | |
| def embed_map(map, path="map.html"): | |
| """ | |
| Embeds a linked iframe to the map into the IPython notebook. | |
| Note: this method will not capture the source of the map into the notebook. | |
| This method should work for all maps (as long as they use relative urls). | |
| """ | |
| map.create_map(path=path) | |
| return HTML('<iframe src="files/{path}" style="width: 100%; height: 510px; border: none"></iframe>'.format(path=path)) |
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 json | |
| import requests | |
| def getFoodRatingData(name,address): | |
| params={'name':name,'address':address} | |
| r=requests.get('http://api.ratings.food.gov.uk/Establishments', | |
| headers={"x-api-version":2}, | |
| params=params) | |
| return r | |
| def parseFoodRatingData(jdata): | |
| df=pd.DataFrame() | |
| for establishment in jdata['establishments']: | |
| info={} | |
| for item in ['BusinessName','FHRSID','PostCode','RatingValue','RatingDate']: | |
| info[item]= establishment[item] | |
| for item in establishment['geocode']: | |
| info[item]= establishment['geocode'][item] | |
| for item in establishment['scores']: | |
| info[item]= establishment['scores'][item] | |
| df=df.append(info,ignore_index=True) | |
| return df | |
| def getAndParseFoodRatingData(name,address): | |
| r=getFoodRatingData(name,address) | |
| jdata=json.loads(r.content) | |
| df=parseFoodRatingData(jdata) | |
| return df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment