Mercurial > repos > melissacline > ucsc_xena_platform
diff xenaGetDataset.py @ 0:8bb037f88ed2
Uploaded
author | melissacline |
---|---|
date | Tue, 13 Jan 2015 23:37:23 -0500 |
parents | |
children | 02b0824c7d60 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xenaGetDataset.py Tue Jan 13 23:37:23 2015 -0500 @@ -0,0 +1,33 @@ +#!/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("metadatafile", 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:]) + print datasetUrl + metadataUrl = datasetUrl + ".json" + mm = urllib2.urlopen(metadataUrl) + with open(args.metadatafile, "w") as metadata: + metadata.write(mm.read()) + mm.close() + dd = urllib2.urlopen(datasetUrl) + with open(args.datafile, "w") as data: + data.write(dd.read()) + dd.close() + + +if __name__ == "__main__": + main() +