comparison xenaGetDataset.py @ 50:3167c1a26101

fix
author jingchunzhu
date Wed, 12 Aug 2015 16:38:12 -0700
parents 02b0824c7d60
children bb840cc2603d
comparison
equal deleted inserted replaced
49:8da6920a39ac 50:3167c1a26101
7 7
8 def main(): 8 def main():
9 parser = argparse.ArgumentParser() 9 parser = argparse.ArgumentParser()
10 parser.add_argument("dataHub", type=str) 10 parser.add_argument("dataHub", type=str)
11 parser.add_argument("datasetId", type=str) 11 parser.add_argument("datasetId", type=str)
12 #parser.add_argument("metadatafile", type=str)
13 parser.add_argument("datafile", type=str) 12 parser.add_argument("datafile", type=str)
14 args = parser.parse_args() 13 args = parser.parse_args()
15 14
16 datasetUrlHost = re.sub("/proj/", "/download/", args.dataHub) 15 datasetUrlHost = re.sub("/proj/", "/download/", args.dataHub)
17 datasetIdTokens = re.split("/", args.datasetId) 16 datasetIdTokens = re.split("/", args.datasetId)
18 datasetUrl = datasetUrlHost + "/" + "/".join(datasetIdTokens[1:]) 17 datasetUrl = datasetUrlHost + "/" + "/".join(datasetIdTokens[1:])
19 print datasetUrl 18
20 """ 19 data = open(args.datafile, "w")
21 metadataUrl = datasetUrl + ".json" 20
22 mm = urllib2.urlopen(metadataUrl) 21 try:
23 with open(args.metadatafile, "w") as metadata: 22 dd = urllib2.urlopen(datasetUrl)
24 metadata.write(mm.read())
25 mm.close()
26 """
27 dd = urllib2.urlopen(datasetUrl)
28 with open(args.datafile, "w") as data:
29 data.write(dd.read()) 23 data.write(dd.read())
30 dd.close() 24 dd.close()
31 25 data.close()
26 except:
27 data.wriet("You entered dataset id: %s\n" % (args.datasetId))
28 data.write("Dataset does not exist. check typo.")
29 data.close()
30 sys.exit(1)
32 31
33 if __name__ == "__main__": 32 if __name__ == "__main__":
34 main() 33 main()
35 34