Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fork of code from ScraperWiki at https://classic.scraperwiki.com/scra…
- Loading branch information
0 parents
commit 764ba6d
Showing
3 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Ignore output of scraper | ||
data.sqlite |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Haringey Wards 2 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
import json | ||
|
||
import requests | ||
import scraperwiki.sqlite as db | ||
|
||
PARENT_ID = 2511# London Borough of Haringey | ||
|
||
|
||
|
||
def iter_children_areas_kml(parent_id): | ||
children = getjs('http://mapit.mysociety.org/area/%s/children' % parent_id) | ||
for id, data in children.items(): | ||
kml = requests.get('http://mapit.mysociety.org/area/%s.kml' % id).content | ||
entry = {'parent_area': int(data['parent_area']), | ||
'id': int(id), | ||
'name': data['name'], | ||
'kml': kml} | ||
yield entry | ||
|
||
|
||
def getjs(url, **opts): | ||
return json.loads(requests.get(url, **opts).content) | ||
|
||
|
||
# | ||
# Main | ||
# | ||
data = list(iter_children_areas_kml(PARENT_ID)) | ||
db.save(['id'], data, verbose=0) |