Exemple #1
0
def info(cache_dir, args):
    if len(args) == 0:
        args = ['http://json-stat.org/samples/oecd-canada-col.json']

    d = jsonstat.cache_dir(cache_dir)
    print("downloaded file(s) are stored into '{}'\n".format(d))
    for arg in args:

        if arg.startswith("http"):
            print("download '{}'".format(arg))
            o = jsonstat.from_url(arg)
        else:
            print("reading '{}'".format(arg))
            o = jsonstat.from_file(arg)

        print(o)
        if isinstance(o, jsonstat.JsonStatCollection):
            print("\nfirst dataset:\n")
            print(o.dataset(0))
Exemple #2
0
def info(cache_dir, args):
    if len(args) == 0:
        args = ['http://json-stat.org/samples/oecd-canada-col.json']

    d = jsonstat.cache_dir(cache_dir)
    print("downloaded file(s) are stored into '{}'\n".format(d))
    for arg in args:

        if arg.startswith("http"):
            print("download '{}'".format(arg))
            o = jsonstat.from_url(arg)
        else:
            print("reading '{}'".format(arg))
            o = jsonstat.from_file(arg)

        print(o)
        if isinstance(o, jsonstat.JsonStatCollection):
            print("\nfirst dataset:\n")
            print(o.dataset(0))
    collection = jsonstat.JsonStatCollection()
    collection.from_string(json_string)

    print("*** multiple datasets info")
    print(collection)
    oecd = collection.dataset(0)

    print("\n*** dataset '{}' info".format(oecd.name))
    print(oecd)
    for d in oecd.dimensions():
        print("\n*** info for dimensions '{}'".format(d.did))
        print(d)

    print("\n*** value oecd(area:IT,year:2012): {}".format(
        oecd.data(area='IT', year='2012')))

    print("\ngenerate all vec")
    oecd.generate_all_vec(area='CA')
    df = oecd.to_data_frame('year', content='id', blocked_dims={'area': 'CA'})
    print(df)


if __name__ == "__main__":
    uri = 'http://json-stat.org/samples/oecd-canada-col.json'
    filename = "oecd-canada-col.json"

    # store downloaded data file in cache_dir
    cache_dir = os.path.join(jsonstat._examples_dir, "www.json-stat.org")
    jsonstat.cache_dir(cache_dir)
    test(uri, filename)
Exemple #4
0
    json_string = jsonstat.download(uri, filename)
    collection = jsonstat.JsonStatCollection()
    collection.from_string(json_string)

    print("*** multiple datasets info")
    print(collection)
    oecd = collection.dataset(0)

    print("\n*** dataset '{}' info".format(oecd.name))
    print(oecd)
    for d in oecd.dimensions():
        print("\n*** info for dimensions '{}'".format(d.did))
        print(d)

    print("\n*** value oecd(area:IT,year:2012): {}".format(oecd.data(area="IT", year="2012")))

    print("\ngenerate all vec")
    oecd.generate_all_vec(area="CA")
    df = oecd.to_data_frame("year", content="id", blocked_dims={"area": "CA"})
    print(df)


if __name__ == "__main__":
    uri = "http://json-stat.org/samples/oecd-canada-col.json"
    filename = "oecd-canada-col.json"

    JSONSTAT_HOME = os.path.join(os.path.dirname(__file__), "..")
    cache_dir = os.path.join(JSONSTAT_HOME, "tests", "fixtures", "www.json-stat.org")
    jsonstat.cache_dir(cache_dir)
    test(uri, filename)