# Example file for Socorro API use with Python

from __future__ import print_function

from pprint import pprint

# See http://stackoverflow.com/a/30362669/205832
import requests

URL = (
    'https://crash-stats.mozilla.com/api/SuperSearch/?product=Firefox&version=VERSION'
    '&_facets=signature&_columns=date&_columns=signature&_columns=product'
    '&_columns=version&_columns=build_id&_columns=platform'
    '&_results_number=10&_facets_size=10'
)


def run(*args):
    if args:
        version = args[0]
    else:
        version = '46.0a1'

    url = URL.replace('VERSION', version)
    print(url)

    response = requests.get(url)
    results = response.json()
    print("TOTAL")
    pprint(results['total'])
    print("HITS")
    pprint(results['hits'])
    print("SIGNATURE FACET")
    pprint(results['facets']['signature'])

if __name__ == '__main__':
    import sys
    sys.exit(run(*sys.argv[1:]))

@@ -82,85 +82,112 @@
 tion
-%0A%0Afrom pprint import pprint%0A%0A# See http://stackoverflow.com/a/30362669/205832
+  # to make print available in py3%0Afrom pprint import pprint  # pretty print python objects%0A%0Aimport json
 %0Aimp
@@ -200,16 +200,20 @@
 quests%0A%0A
+base
 URL = (%0A
@@ -479,16 +479,90 @@
 =10'%0A)%0A%0A
+outfilename = 'apitest-VERSION.json'%0A%0A# Run the actual meat of the script.
 %0Adef run
@@ -657,16 +657,20 @@
   url = 
+base
 URL.repl
@@ -939,16 +939,247 @@
 ure'%5D)%0A%0A
+    # Write signatures to a file.%0A    with open(outfilename.replace('VERSION', version), 'w') as outfile:%0A        json.dump(results%5B'facets'%5D%5B'signature'%5D, outfile)%0A%0A%0A# Avoid running the script when e.g. simply importing the file.%0A
 if __nam

add some comments, write signatures facet to a file