'How to specify Python API results

Trying to use Lobbying Disclosure API from the US Congress database in Python.

I want to get only the contributions for specific members of congress along with who contributed (lobbyist or organization).

import requests
import re
import json

parameters = {
    "contribution_payee": "Rashida Tlaib for Congress"

}
response = requests.get("https://lda.senate.gov/api/v1/contributions", params=parameters)

# print(response.json())


def jprint(obj):
    lines = json.dumps(obj, sort_keys=True, indent=4)
    with open('Test.txt', 'w') as f:
        for line in lines:
            f.write(line)

    
jprint(response.json())

I am getting dictionary lists of not just Rashida Tlaib for example, but from everyone on the LDA-203 form that also received a donation from that lobbyist or organization.

Output in text file, only want data from Rashida Tlaib and not John Thune or Ted Lieu for example. But I still want the name of org and lobbyist who donated.

Example of what each LDA-203 contribution form looks like: includes all candidates who received donation from specific org or lobbyist. Using Python to narrow down data for specific members of congress rather than just sift through it by hand. https://lda.senate.gov/filings/public/contribution/6285c999-2ec6-4d27-8963-b40bab7def55/print/

Is there a way I can narrow down my results to only include certain members of congress that I pass as a parameter, while excluding the information of everyone else who received a donation from that lobbyist or org?

Was thinking regular expressions could do the trick, but I am not very good at implementing them. Should I try to do this in R instead of Python?

Thank you!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source