Skip to content
Snippets Groups Projects
Commit aef122dc authored by Adam Caprez's avatar Adam Caprez
Browse files

Merge branch '36-chip-meta-download-should-support-resuming' into 'master'

Add resume option to meta download script.

Closes #36

See merge request !35
parents 857d585e b743bb97
No related branches found
No related tags found
1 merge request!35Add resume option to meta download script.
...@@ -13,6 +13,8 @@ import datetime ...@@ -13,6 +13,8 @@ import datetime
parser = argparse.ArgumentParser(description="Download raw JSON for all experiments.") parser = argparse.ArgumentParser(description="Download raw JSON for all experiments.")
parser.add_argument("-o", "--output-dir", dest="outputdir", default=os.getcwd(), help="Output directory. (default: %(default)s)") parser.add_argument("-o", "--output-dir", dest="outputdir", default=os.getcwd(), help="Output directory. (default: %(default)s)")
parser.add_argument("-q", "--quiet", action='store_true', help="Quiet mode. Do not print progress information. (default: false)") parser.add_argument("-q", "--quiet", action='store_true', help="Quiet mode. Do not print progress information. (default: false)")
parser.add_argument("-r", "--resume", action='store_false', \
help="Skip re-fetching existing experiment JSON files to speed up overall download. (default: true)")
args = parser.parse_args() args = parser.parse_args()
encode_baseurl = "https://www.encodeproject.org/experiments/" encode_baseurl = "https://www.encodeproject.org/experiments/"
...@@ -37,9 +39,17 @@ if not os.path.isdir(os.path.join(args.outputdir, "data")): ...@@ -37,9 +39,17 @@ if not os.path.isdir(os.path.join(args.outputdir, "data")):
total = len(exp_ids) total = len(exp_ids)
for i, exp_id in enumerate(exp_ids): for i, exp_id in enumerate(exp_ids):
exp_url = urlparse.urljoin(encode_baseurl, exp_id) exp_url = urlparse.urljoin(encode_baseurl, exp_id)
r = requests.get(exp_url, params=json_arg) json_file = os.path.join(args.outputdir, "data", "%s.json" % (exp_id,))
with open(os.path.join(args.outputdir, "data", "%s.json" % (exp_id,)), "w") as wh: if args.resume:
wh.write(r.text) if not os.path.isfile(json_file) or os.path.getsize(json_file) == 0:
r = requests.get(exp_url, params=json_arg)
with open(json_file, "w") as wh:
wh.write(r.text)
else:
r = requests.get(exp_url, params=json_arg)
with open(json_file, "w") as wh:
wh.write(r.text)
if not args.quiet: if not args.quiet:
progress(i, total) progress(i, total)
if not args.quiet: if not args.quiet:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment