trying to retrieve comments with activated API key

Chris Angelico rosuav at gmail.com
Fri Mar 8 15:51:00 EST 2019


On Sat, Mar 9, 2019 at 7:47 AM Drake Gossi <drake.gossi at gmail.com> wrote:
>
> Still having issues:
>
> 7. import requests
> 8. import csv
> 9. import time
> 10. import sys
> 11. api_key = 'PUT API KEY HERE'
> 12. docket_id = 'ED-2018-OCR-0064'
> 13. total_docs = 32068
> 14. docs_per_page = 1000
> 15.
> 16. r = requests.get("https://api.data.gov:443/regulations/v3/documents.json
> <https://api.data.gov/regulations/v3/documents.json>",
> 17. params={
> 18.    "api_key": api_key,
> 19.    "dktid": docket_id,
>  20.    "rrp": docs_per_page,
>
> })
>
> I'm getting an "imported but unused" by 8, 9 & 10.

Doesn't matter - may as well leave them in.

> But then also, on the interactive API
> <https://regulationsgov.github.io/developers/console/#!/documents.json/documents_get_0>,
> it has something called a "po"--i.e., page offset. I was able to figure out
> that "rrp" means results per page, but now I'm unsure how to get all 32000
> comments into a response object. Do I have to add an "ro" on line 21? or
> something else?

Probably you'll need a loop. For now, don't worry about it, and
concentrate on getting the first page.

> Also, I ran the code as is starting on line 7 and got this:
>
> runfile('/Users/susan/.spyder-py3/temp.py', wdir='/Users/susan/.spyder-py3')
>
> This was in the terminal, I think. Since nothing popped up in what I assume
> is the environment--I'm running this in spyder--I assume it didn't work.

Ahh, that might be making things confusing.

My recommendation is to avoid Spyder altogether. Just run your script
directly and let it do its downloading. Keep it simple!

ChrisA



More information about the Python-list mailing list