Data flow
LAMetro scraper
- Python backend
- Based off of
python-legistar-scraper - Depends on
pupascraper/importer
- Based off of
- Data is fetched from the Legistar API
- It is normalized as specified in either
python-legistar-scraperorscrapers-lametro - To be included in database import, API data needs to be part of the construction of a pupa scrape object like
Billor added to a scrape object, using a pupa method likeBill.add_sponsorship(), orBill.add_action(). - Pupa import is backed by
opencivicdata(OCD) models - Imported data then is available in the database for Django apps to access and build their own models on top of, in ways that are convenient for accessing data for presentation.
LAMetro Councilmatic
- Django frontend
- Models based off of
django-councilmaticmodels - Which are themselves based off of
python-opencivicdatamodels - Which are again, an implementation of OCD models
- Models based off of
- In addition to Django models, the frontend also creates a Haystack search index object which maps model fields onto search document fields for serialization in
search_indexes.py resultin search templates refers to these Haystack search index objects- If you can’t find a property or method on an
LAMetro...orLAMetro...Indexmodel, you may need to look deeper in the model dependencies above.
Example: Bill Sponsors
Fetch API data
In the case of bill sponsors, given a
MatterIDfor a bill,scrapers-lametrobill scraper (lametro/bills.py) calls a function inherited frompython-legistar-scraperto fetch data from the MatterSponsor API endpoint using that matter ID (sponsors(matter_id)).Normalize data
scrapers-lametrouses a LAMetro-specificsponsorships()method to wrap the raw sponsorship data into dicts, with the first sponsorship being flagged as primary, and yielding each in turnAdd to Bill object
The LAMetro scraper then calls the pupa method
add_sponsorship(sponsorship**)to unpack each yieldedsponsorshipdict to guarantee the data structure conforms to the OCD format before it is appended to theBillobject.Import
LAMetro Scrapers bill importer (
la_metro_bill.py) calls the pupaBillImporter, and the bill is written as a row toopencivicdata_bill, and writes each sponsorship as a row in theopencivicdata_billsponsorshiptable withbill_idreferencing that bill.Councilmatic model
django-councilmaticdefines its own Bill model based on the OCD model, which adds, among other things, a propertyprimary_sponsor, which filters for the primary sponsor and unwraps the queryset withfirst().Search Index
The Haystack search index
LAMetroBillIndexdeclares and populates aprimary_sponsorfield with thenameof the primary sponsor.Templates
Now the
search/_tags.htmltemplate can referenceresult.primary_sponsorto display the name of the first sponsor listed on the bill.