This isn't really a place to code-review your script, even if it uses the API.
Here is were you would publish your script.
However, after a quick glance at the code, I don't see any glaring problems.
But, if you start making lots, or rapid, calls you will need to check and respect the backoff
value and the quota_remaining
value.
The API documentation is at api.stackexchange.com/docs.