Skip to content

Commit

Permalink
Fork of code from ScraperWiki at https://classic.scraperwiki.com/scra…
Browse files Browse the repository at this point in the history
  • Loading branch information
tommac1204 committed Dec 9, 2014
0 parents commit 764ba6d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
# Ignore output of scraper
data.sqlite
1 change: 1 addition & 0 deletions README.textile
@@ -0,0 +1 @@
Haringey Wards 2
31 changes: 31 additions & 0 deletions scraper.py
@@ -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)

0 comments on commit 764ba6d

Please sign in to comment.