-
-
Save ajokela/2e2aa4539af712672980a76651e09b06 to your computer and use it in GitHub Desktop.
Helium API get all data using cursor
This file contains hidden or 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
#!/usr/bin/env python3 | |
import requests | |
import json | |
import sys | |
from optparse import OptionParser | |
params = { | |
"count": "10000", | |
"cursor": "" | |
} | |
def main(url): | |
with requests.Session() as req: | |
allin = [] | |
for _ in range(1, 400): | |
r = req.get(url, params=params).json() | |
allin.append(r) | |
if 'cursor' in r: | |
params['cursor'] = r['cursor'] | |
else: | |
break | |
goal = json.dumps(allin, indent=4) | |
sys.stdout.write(goal) | |
url = "https://api.helium.io/v1/stats" | |
parser = OptionParser() | |
parser.add_option("-u", "--url", dest="url", help="Url to query") | |
(options, args) = parser.parse_args() | |
if options.url: | |
url = options.url | |
main(url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment