Permalink
Browse files

Adding in GA base work.

  • Loading branch information...
1 parent fea9909 commit 43a9c29db8d3224666a4755772dde9670fedc127 Paul Tagliamonte committed Nov 27, 2012
Showing with 103 additions and 42 deletions.
  1. +35 −9 openstates/ga/__init__.py
  2. +54 −33 openstates/ga/legislators.py
  3. +12 −0 openstates/ga/util.py
  4. +2 −0 requirements.txt
View
44 openstates/ga/__init__.py
@@ -1,6 +1,27 @@
from billy.utils.fulltext import text_after_line_numbers
import lxml.html
+# (Session){
+# IsDefault = True
+# Id = 21
+# Description = "2011-2012 Regular Session"
+# Library = "http://www.legis.ga.gov/Legislation/20112012/"
+# }
+# (Session){
+# IsDefault = False
+# Id = 23
+# Description = "2013-2014 Regular Session"
+# Library = "http://www.legis.ga.gov/Legislation/20132014/"
+# }
+# (Session){
+# IsDefault = False
+# Id = 22
+# Description = "2011 Special Session"
+# Library = "http://www.legis.ga.gov/Legislation/2011EX1/"
+# }
+
+
+
metadata = {
'name': 'Georgia',
'abbreviation': 'ga',
@@ -14,21 +35,26 @@
'lower_chamber_term': 2,
'terms': [
{'name': '2013-2014', 'start_year': 2013, 'end_year': 2014,
- 'sessions': ['20132014']},
+ 'sessions': ['2013_14']},
{'name': '2011-2012', 'start_year': 2011, 'end_year': 2012,
'sessions': ['2011_12', '2011_ss']}
],
'session_details': {
- '20132014': {
+ '2013_14': {
'display_name': '2013-2014 Regular Session',
- '_scraped_name': '2013-2014 Regular Session'
+ '_scraped_name': '2013-2014 Regular Session',
+ '_guid': 23
+ },
+ '2011_12': {
+ 'display_name': '2011-2012 Regular Session',
+ '_scraped_name': '2011-2012 Regular Session',
+ '_guid': 21
+ },
+ '2011_ss': {
+ 'display_name': '2011 Special Session',
+ '_scraped_name': '2011 Special Session',
+ '_guid': 22
},
- '2011_12': {'display_name': '2011-2012 Regular Session',
- '_scraped_name': '2011-2012 Regular Session',
- },
- '2011_ss': {'display_name': '2011 Special Session',
- '_scraped_name': '2011 Special Session',
- },
},
'feature_flags': ['influenceexplorer'],
'_ignored_scraped_sessions': ['2009-2010 Regular Session',
View
87 openstates/ga/legislators.py
@@ -1,38 +1,59 @@
from billy.scrape.legislators import LegislatorScraper, Legislator
-import lxml
-
-URLS = {
- "upper": "http://www.senate.ga.gov/senators/en-US/SenateMembersList.aspx",
- "lower": "http://www.house.ga.gov/Representatives/en-US/HouseMembersList.aspx"
-}
+from .util import get_client, get_url
class GALegislatorScraper(LegislatorScraper):
state = 'ga'
+ sservice = get_client("Members").service
+ ssource = get_url("Members")
+
+ def scrape_session(self, term, chambers, session):
+ session = self.metadata['session_details'][session]
+ sid = session['_guid']
+ members = self.sservice.GetMembersBySession(sid)['MemberListing']
+ for member in members:
+ guid = member['Id']
+ first_name, middle_name, last_name = (
+ member['Name'][x] for x in ['First', 'Middle', 'Last']
+ )
+ chamber, district = (
+ member['District'][x] for x in ['Type', 'Number']
+ )
+
+ party = member['Party']
+ if party == 'Democrat':
+ party = 'Democratic'
+
+ # print first_name, middle_name, last_name, party
+ # print chamber, district
+ name = "%s %s" % (first_name, last_name)
+
+ chamber = {
+ "House": 'lower',
+ "Senate": 'upper'
+ }[chamber]
+
+ if party.strip() == '':
+ party = 'other'
+
+ print party
+ legislator = Legislator(
+ term,
+ chamber,
+ str(district),
+ name,
+ party=party,
+ last_name=last_name,
+ first_name=first_name
+ )
+ if middle_name:
+ legislator['middle_name'] = middle_name
+
+ legislator.add_source(self.ssource)
+ # when I passed this into the instance's constructor
+ self.save_legislator(legislator)
- def lxmlize(self, url):
- with self.urlopen(url) as page:
- page = lxml.html.fromstring(page)
- page.make_links_absolute(url)
- return page
-
- def scrape_upper(self, href, chamber, term):
- page = self.lxmlize(href)
- title, name = [
- x.text_content() for x in page.xpath("//div[@class='senateh3']")
- ]
- print name
-
- def scrape_lower(self, href, chamber, term):
- pass
-
- def scrape(self, chamber, term):
- page = self.lxmlize(URLS[chamber])
- t = page.xpath("//div[@class='ggaMasterContent']/table[@width='100%']")
- if len(t) != 1:
- raise Exception("Something's broke with the scraper. Root "
- "legislator list isn't what I think it was.")
- t = t[0]
- legislators = t.xpath(".//a[contains(@href, 'member.aspx')]")
- for legislator in legislators:
- href = legislator.attrib['href']
- getattr(self, "scrape_%s" % (chamber))(href, chamber, term)
+ def scrape(self, term, chambers):
+ for t in self.metadata['terms']:
+ if t['name'] == term:
+ for session in t['sessions']:
+ self.scrape_session(term, chambers, session)
View
12 openstates/ga/util.py
@@ -0,0 +1,12 @@
+from suds.client import Client
+
+url = 'http://webservices.legis.ga.gov/GGAServices/%s/Service.svc?wsdl'
+
+
+def get_client(service):
+ client = Client(get_url(service))
+ return client
+
+
+def get_url(service):
+ return url % (service)
View
2 requirements.txt
@@ -9,3 +9,5 @@ http://downloads.sourceforge.net/project/dbfpy/dbfpy/2.2.5/dbfpy-2.2.5.tar.gz
# California
SQLAlchemy>=0.5.3
MySQL-python
+# GA
+suds

0 comments on commit 43a9c29

Please sign in to comment.