Skip to content

Instantly share code, notes, and snippets.

@psychemedia
Last active October 27, 2015 20:47
Show Gist options
  • Save psychemedia/f7385255f89137c503b5 to your computer and use it in GitHub Desktop.
Save psychemedia/f7385255f89137c503b5 to your computer and use it in GitHub Desktop.
Code Club week 7 code resources
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('"', '&quot;')))
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))
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
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment