view xenaGetDataset.py @ 50:3167c1a26101

fix
author jingchunzhu
date Wed, 12 Aug 2015 16:38:12 -0700
parents 02b0824c7d60
children bb840cc2603d
line wrap: on
line source

#!/usr/bin/env python

import argparse
import re
import urllib2


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("dataHub", type=str)
    parser.add_argument("datasetId", type=str)
    parser.add_argument("datafile", type=str)
    args = parser.parse_args()

    datasetUrlHost = re.sub("/proj/", "/download/", args.dataHub)
    datasetIdTokens = re.split("/", args.datasetId)
    datasetUrl = datasetUrlHost + "/" + "/".join(datasetIdTokens[1:])

    data = open(args.datafile, "w")

    try:
        dd = urllib2.urlopen(datasetUrl)
        data.write(dd.read())
        dd.close()
        data.close()
    except:
        data.wriet("You entered dataset id: %s\n" % (args.datasetId))
        data.write("Dataset does not exist. check typo.")
        data.close()
        sys.exit(1)

if __name__ == "__main__":
    main()