-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added scraper to get votes data from html (due to bug in dataservice)
- Loading branch information
Showing
4 changed files
with
50 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 @@ | ||
__author__ = 'orihoch' |
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 @@ | ||
__author__ = 'orihoch' |
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,9 @@ | ||
import unittest | ||
from knesset_data.html_scrapers.votes import HtmlVote | ||
|
||
|
||
class TestHtmlVote(unittest.TestCase): | ||
|
||
def test(self): | ||
html_vote = HtmlVote.get_from_vote_id(24084) | ||
self.assertListEqual(html_vote.member_votes, [('863', 'voted for'), ('879', 'voted for'), ('953', 'voted for'), ('914', 'voted for'), ('918', 'voted for'), ('950', 'voted for'), ('922', 'voted for'), ('924', 'voted for'), ('932', 'voted for'), ('944', 'voted for'), ('230', 'voted for'), ('862', 'voted for'), ('865', 'voted for'), ('881', 'voted for'), ('818', 'voted for'), ('901', 'voted for'), ('216', 'voted for'), ('876', 'voted for'), ('915', 'voted for'), ('854', 'voted for'), ('941', 'voted for'), ('871', 'voted for')]) |
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,39 @@ | ||
import urllib2 | ||
import re | ||
|
||
|
||
class HtmlVote(object): | ||
|
||
def __init__(self, page): | ||
self.page = page | ||
|
||
@property | ||
def member_votes(self): | ||
""" | ||
Returns a tuple of (member_id, vote_result_code) describing the vote found in page, where: | ||
member_id = link to dataservice member id | ||
vote_result_code = "voted for"|"voted against"|"abstain"|"did not vote" - matching the codes in dataservice.votes.VoteMember.vote_result_code | ||
""" | ||
results = [] | ||
pattern = re.compile("""Vote_Bord""") | ||
match = pattern.split(self.page) | ||
for i in match: | ||
vote_result_code = "" | ||
if(re.match("""_R1""", i)): | ||
vote_result_code = "voted for" | ||
if(re.match("""_R2""", i)): | ||
vote_result_code = "voted against" | ||
if(re.match("""_R3""", i)): | ||
vote_result_code = "abstain" | ||
if(re.match("""_R4""", i)): | ||
vote_result_code = "did not vote" | ||
if(vote_result_code != ""): | ||
member_id = re.search("""mk_individual_id_t=(\d+)""",i).group(1) | ||
results.append((member_id, vote_result_code)) | ||
return results | ||
|
||
@classmethod | ||
def get_from_vote_id(cls, vote_id): | ||
url = 'http://www.knesset.gov.il/vote/heb/Vote_Res_Map.asp?vote_id_t=%s'%vote_id | ||
page = urllib2.urlopen(url).read() | ||
return cls(page) |