-
Notifications
You must be signed in to change notification settings - Fork 0
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
Address change in lobbyist structure, fix bug preventing download of all filings #36
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
@@ -1,82 +1,34 @@ | ||
# Lobbyist expenditures and contributions | ||
LOBBYIST_DATA_DIR=data/lobbyist | ||
|
||
.PRECIOUS : $(LOBBYIST_DATA_DIR)/raw/lobbyist.csv \ | ||
$(LOBBYIST_DATA_DIR)/raw/filings.csv \ | ||
$(LOBBYIST_DATA_DIR)/raw/lobbyist_client.csv \ | ||
$(LOBBYIST_DATA_DIR)/intermediate/lobbyist_contributions.csv \ | ||
$(LOBBYIST_DATA_DIR)/intermediate/lobbyist_expenditures.csv | ||
|
||
data/processed/lobbyist.xlsx : $(LOBBYIST_DATA_DIR)/processed/lobbyist_employer.csv \ | ||
data/processed/lobbyist.xlsx : $(LOBBYIST_DATA_DIR)/raw/lobbyist.csv \ | ||
$(LOBBYIST_DATA_DIR)/raw/lobbyist_client.csv \ | ||
$(LOBBYIST_DATA_DIR)/processed/lobbyist_contributions.csv \ | ||
$(LOBBYIST_DATA_DIR)/processed/lobbyist_expenditures.csv | ||
python scripts/to_excel.py $^ $@ | ||
|
||
$(LOBBYIST_DATA_DIR)/processed/lobbyist_employer.csv : $(LOBBYIST_DATA_DIR)/raw/lobbyist.csv \ | ||
$(LOBBYIST_DATA_DIR)/intermediate/client.csv | ||
csvsql --query "SELECT \ | ||
ClientID, \ | ||
MemberID, \ | ||
Phone, \ | ||
LobbyistName, \ | ||
LobbyistAddress, \ | ||
Email, \ | ||
StartYear, \ | ||
EndYear \ | ||
FROM ( \ | ||
SELECT \ | ||
ClientID, \ | ||
MemberID, \ | ||
MAX(MemberVersionID) AS MemberVersionID, \ | ||
MAX(Year) AS Year, \ | ||
MIN(Year) AS StartYear, \ | ||
MAX(Year) AS EndYear \ | ||
FROM STDIN \ | ||
GROUP BY ClientID, MemberID \ | ||
) AS lobbyists \ | ||
JOIN STDIN \ | ||
USING (ClientID, MemberID, MemberVersionID, Year)" < $< | \ | ||
csvjoin -c ClientID - $(word 2, $^) > $@ | ||
$(LOBBYIST_DATA_DIR)/raw/lobbyist_client.csv : $(LOBBYIST_DATA_DIR)/raw/lobbyist.csv | ||
python scrapers/lobbyist/cli.py scrape-lobbyist-clients < $< > $@ | ||
|
||
$(LOBBYIST_DATA_DIR)/processed/lobbyist_%.csv : $(LOBBYIST_DATA_DIR)/intermediate/lobbyist_%.csv \ | ||
$(LOBBYIST_DATA_DIR)/intermediate/filings.csv \ | ||
$(LOBBYIST_DATA_DIR)/intermediate/lobbyist.csv | ||
$(LOBBYIST_DATA_DIR)/raw/filings.csv \ | ||
$(LOBBYIST_DATA_DIR)/raw/lobbyist.csv | ||
csvjoin --left -c Source,ReportFileName $< $(word 2, $^) | \ | ||
csvjoin --left -c MemberID - $(word 3, $^) > $@ | ||
csvjoin --left -c ID - $(word 3, $^) > $@ | ||
|
||
$(LOBBYIST_DATA_DIR)/intermediate/lobbyist_%.csv : lobbyist_filings | ||
python -m scrapers.lobbyist.extract_transactions $* $(LOBBYIST_DATA_DIR) > $@ | ||
python scrapers/lobbyist/cli.py extract-transactions -t $* -d $(LOBBYIST_DATA_DIR)/assets > $@ | ||
|
||
lobbyist_filings : $(LOBBYIST_DATA_DIR)/intermediate/filings.csv | ||
python -m scrapers.lobbyist.download_filings $(LOBBYIST_DATA_DIR) < $< | ||
lobbyist_filings : $(LOBBYIST_DATA_DIR)/raw/filings.csv | ||
python scrapers/lobbyist/cli.py download-filings -d $(LOBBYIST_DATA_DIR)/assets < $< | ||
|
||
$(LOBBYIST_DATA_DIR)/intermediate/lobbyist.csv : $(LOBBYIST_DATA_DIR)/raw/lobbyist.csv | ||
csvsql --query "SELECT \ | ||
MemberID, \ | ||
Phone, \ | ||
LobbyistName, \ | ||
LobbyistAddress, \ | ||
Email \ | ||
FROM ( \ | ||
SELECT \ | ||
MemberID, \ | ||
MAX(MemberVersionID) AS MemberVersionID, \ | ||
MAX(Year) AS Year, \ | ||
MAX(ClientID) AS ClientID \ | ||
FROM STDIN \ | ||
GROUP BY MemberID \ | ||
) AS lobbyists \ | ||
JOIN STDIN \ | ||
USING (MemberID, MemberVersionID, Year, ClientID)" < $< > $@ | ||
$(LOBBYIST_DATA_DIR)/raw/filings.csv : $(LOBBYIST_DATA_DIR)/raw/lobbyist.csv | ||
python scrapers/lobbyist/cli.py scrape-filings < $< > $@ | ||
|
||
$(LOBBYIST_DATA_DIR)/intermediate/filings.csv : $(LOBBYIST_DATA_DIR)/raw/lobbyist.csv | ||
csvsql --query "SELECT DISTINCT MemberID AS id, MemberVersionID AS version FROM STDIN" < $< | \ | ||
python -m scrapers.lobbyist.scrape_filings | \ | ||
csvsql --query 'select ReportFileName, ReportTypeCode, MAX(MemberID) as MemberID from STDIN group by ReportFileName, ReportTypeCode' > $@ | ||
|
||
$(LOBBYIST_DATA_DIR)/raw/lobbyist.csv : $(LOBBYIST_DATA_DIR)/intermediate/client.csv | ||
python -m scrapers.lobbyist.scrape_lobbyists < $< > $@ | ||
|
||
$(LOBBYIST_DATA_DIR)/intermediate/client.csv : $(LOBBYIST_DATA_DIR)/raw/client.csv | ||
csvsql --query "SELECT ClientID, ClientVersionID, MAX(ClientName) AS ClientName FROM STDIN GROUP BY ClientID" < $< > $@ | ||
|
||
$(LOBBYIST_DATA_DIR)/raw/client.csv : lobbyist_data_dirs | ||
python -m scrapers.lobbyist.scrape_clients > $@ | ||
$(LOBBYIST_DATA_DIR)/raw/lobbyist.csv : lobbyist_data_dirs | ||
python scrapers/lobbyist/cli.py scrape-lobbyists > $@ |
Empty file.
Empty file.
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,75 @@ | ||
import functools | ||
|
||
import click | ||
|
||
|
||
def scrapelib_opts(f): | ||
@click.option("--rpm", default=180, show_default=True) | ||
@click.option("--retries", default=3, show_default=True) | ||
@click.option("--verify/--no-verify", default=False, show_default=True) | ||
@functools.wraps(f) | ||
def wrapped_func(*args, **kwargs): | ||
return f(*args, **kwargs) | ||
|
||
return wrapped_func | ||
Comment on lines
+6
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was the main reason for pulling this into a CLI. That way, we can run scrapes faster locally by specifying --rpm=something larger than 3 |
||
|
||
|
||
@click.group() | ||
def scrape(): | ||
... | ||
|
||
|
||
@scrape.command() | ||
@scrapelib_opts | ||
def scrape_lobbyist_clients(rpm, retries, verify): | ||
import scrape_lobbyist_clients | ||
|
||
scrape_lobbyist_clients.main(rpm=rpm, retries=retries, verify=verify) | ||
|
||
|
||
@scrape.command() | ||
@scrapelib_opts | ||
def scrape_lobbyists(rpm, retries, verify): | ||
import scrape_lobbyists | ||
|
||
scrape_lobbyists.main(rpm=rpm, retries=retries, verify=verify) | ||
|
||
|
||
@scrape.command() | ||
@scrapelib_opts | ||
def scrape_employers(rpm, retries, verify): | ||
import scrape_employers | ||
|
||
scrape_employers.main(rpm=rpm, retries=retries, verify=verify) | ||
|
||
|
||
@scrape.command() | ||
@scrapelib_opts | ||
@click.option("--employer", "is_employer_scrape", is_flag=True) | ||
def scrape_filings(rpm, retries, verify, is_employer_scrape): | ||
import scrape_filings | ||
|
||
scrape_filings.main( | ||
rpm=rpm, retries=retries, verify=verify, is_employer_scrape=is_employer_scrape | ||
) | ||
|
||
|
||
@scrape.command() | ||
@click.option("-d", "--asset-directory", "asset_directory") | ||
def download_filings(asset_directory): | ||
import download_filings | ||
|
||
download_filings.main(asset_directory) | ||
|
||
|
||
@scrape.command() | ||
@click.option("-t", "--transaction-type", "transaction_type") | ||
@click.option("-d", "--asset-directory", "asset_directory") | ||
def extract_transactions(transaction_type, asset_directory): | ||
import extract_transactions | ||
|
||
extract_transactions.main(transaction_type, asset_directory) | ||
|
||
|
||
if __name__ == "__main__": | ||
scrape() |
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parallelizes building of these files.