annotate xenaGetDataset.py @ 50:3167c1a26101

fix
author jingchunzhu
date Wed, 12 Aug 2015 16:38:12 -0700
parents 02b0824c7d60
children bb840cc2603d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
1 #!/usr/bin/env python
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
2
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
3 import argparse
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
4 import re
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
5 import urllib2
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
6
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
7
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
8 def main():
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
9 parser = argparse.ArgumentParser()
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
10 parser.add_argument("dataHub", type=str)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
11 parser.add_argument("datasetId", type=str)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
12 parser.add_argument("datafile", type=str)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
13 args = parser.parse_args()
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
14
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
15 datasetUrlHost = re.sub("/proj/", "/download/", args.dataHub)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
16 datasetIdTokens = re.split("/", args.datasetId)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
17 datasetUrl = datasetUrlHost + "/" + "/".join(datasetIdTokens[1:])
50
jingchunzhu
parents: 41
diff changeset
18
jingchunzhu
parents: 41
diff changeset
19 data = open(args.datafile, "w")
jingchunzhu
parents: 41
diff changeset
20
jingchunzhu
parents: 41
diff changeset
21 try:
jingchunzhu
parents: 41
diff changeset
22 dd = urllib2.urlopen(datasetUrl)
0
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
23 data.write(dd.read())
50
jingchunzhu
parents: 41
diff changeset
24 dd.close()
jingchunzhu
parents: 41
diff changeset
25 data.close()
jingchunzhu
parents: 41
diff changeset
26 except:
jingchunzhu
parents: 41
diff changeset
27 data.wriet("You entered dataset id: %s\n" % (args.datasetId))
jingchunzhu
parents: 41
diff changeset
28 data.write("Dataset does not exist. check typo.")
jingchunzhu
parents: 41
diff changeset
29 data.close()
jingchunzhu
parents: 41
diff changeset
30 sys.exit(1)
0
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
31
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
32 if __name__ == "__main__":
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
33 main()
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
34