-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscraper.py
28 lines (20 loc) · 874 Bytes
/
scraper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import scraperwiki
import time
scraperwiki.sqlite.attach("uk_parliamentary_constituencies")
constituencies = scraperwiki.sqlite.select("id, country_name from uk_parliamentary_constituencies.swdata order by id")
last_id = scraperwiki.sqlite.get_var("last_id") or 0
for constituency in constituencies:
if constituency["id"] <= last_id:
continue
# Think that Northern Ireland in general doesn't have map data.
if constituency["country_name"] == "Northern Ireland":
continue
data = scraperwiki.scrape("http://mapit.mysociety.org/area/" + str(constituency["id"]) + ".kml")
record = {
"id": constituency["id"],
"kml": data,
}
scraperwiki.sqlite.save(unique_keys=["id"], data=record)
scraperwiki.sqlite.save_var("last_id", constituency["id"])
# Try to avoid annoying dracos too much.
time.sleep(1)