Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 78bbf12
Showing
3 changed files
with
49 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 @@ | ||
/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,10 @@ | ||
# It's easy to add more libraries or choose different versions. Any libraries | ||
# specified here will be installed and made available to your morph.io scraper. | ||
# Find out more: https://morph.io/documentation/python | ||
|
||
# Custom version of scraperwiki library | ||
-e git+http://github.com/openaustralia/scraperwiki-python.git@morph_defaults#egg=scraperwiki | ||
|
||
lxml==3.4.4 | ||
cssselect==0.9.1 | ||
requests==2.7.0 |
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,37 @@ | ||
#!/usr/bin/env python | ||
|
||
import csv | ||
import re | ||
from urlparse import urlsplit | ||
|
||
import requests | ||
import scraperwiki | ||
|
||
'''This "scraper" just changes the columns in the YourNextMP elected | ||
candidates data from the UK 2015 general election''' | ||
|
||
url = 'https://candidates.democracyclub.org.uk/media/candidates-elected-2015.csv' | ||
|
||
r = requests.get(url, stream=True) | ||
|
||
for row in csv.DictReader(r.raw): | ||
parlparse_person_id = re.sub(r'^.*/(\d+)$', r'\1', row['parlparse_id']) | ||
wikiname = '' | ||
if row['wikipedia_url']: | ||
split = urlsplit(row['wikipedia_url']) | ||
wikiname = split.path[len('/wiki/'):] | ||
wikiname.replace('_', ' ') | ||
scraperwiki.sqlite.save( | ||
unique_keys=['id'], | ||
data={ | ||
'id': parlparse_person_id, | ||
'name': row['name'], | ||
'twitter': row['twitter_username'], | ||
'facebook': row['facebook_page_url'], | ||
'wikipedia': row['wikipedia_url'], | ||
'wikiname': wikiname, | ||
'birth_date': row['birth_date'], | ||
'linkedin': row['linkedin_url'], | ||
'image': row['image_url'], | ||
} | ||
) |