Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

method for getting pdf-ified versions of bills #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions legistar/bills.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
from .base import LegistarScraper, LegistarAPIScraper
from pupa.scrape import Scraper
from lxml.etree import tostring
from collections import deque
from functools import partialmethod
import datetime
import urllib.parse

from pupa.scrape import Scraper
from lxml.etree import tostring
import pytz
import requests
import scrapelib

from .base import LegistarScraper, LegistarAPIScraper


class LegistarBillScraper(LegistarScraper):
def legislation(self, search_text='', created_after=None,
created_before=None) :
Expand Down Expand Up @@ -358,9 +362,27 @@ def text(self, matter_id) :
return response.json()

def legislation_detail_url(self, matter_id) :
gateway_url = self.BASE_WEB_URL + '/gateway.aspx?m=l&id={0}'
gateway_url = self.BASE_WEB_URL + '/gateway.aspx?m=l&id={}'

legislation_detail_route = self.head(gateway_url.format(matter_id)).headers['Location']

return self.BASE_WEB_URL + legislation_detail_route

def legislation_pdf_url(self, matter_id):
'''
For some Legistar sites, the official legislation text is
the RTF file we can get from the `text` method (for others it's a
pdf we can get from the `attachments` method).

But, even if the RTF is the canonical format, we might want a nicely
formatted PDF version of the text. Such a PDF is available from the
Legistar sites and this method gets us URL for that PDF
'''
if not hasattr(self, gid):
gateway_url = self.BASE_WEB_URL + '/gateway.aspx?M=R2&ID={}&GUID=LATEST&Extra=L5'
pdf_route = self.head(gateway_url.format(matter_id)).headers['Location']
self.gid = urllib.parse.parse_qs(urllib.parse.urlparse(pdf_route).query)['GID']

url = self.BASE_WEB_URL + '/ViewReport.ashx?M=R&N=Text&GID={gid}&ID={matter_id}&GUID=LATEST&Extra=L5'

return url.format(gid=self.gid, matter_id=matter_id)