Skip to content

Instantly share code, notes, and snippets.

@mtholder
Created September 21, 2015 16:27
Show Gist options
  • Select an option

  • Save mtholder/ddae56851edd81180767 to your computer and use it in GitHub Desktop.

Select an option

Save mtholder/ddae56851edd81180767 to your computer and use it in GitHub Desktop.
pull study info from OTI
#!/usr/bin/env
import sys
'''
python gen-curl-oti.py template.txt studies.txt
where studies.txt is the list of studies used in synthesis.
and template is a cURL call with XYZ inplace of the study id (and no other XYZ)
cURL
'''
if False:
template = open(sys.argv[1], 'rU').read().strip()
else:
# when I ran this, template contained:
template = '''curl 'https://api.opentreeoflife.org/oti/v1/singlePropertySearchForStudies' -H 'Origin: https://tree.opentreeoflife.org' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Accept: */*' -H 'Referer: https://tree.opentreeoflife.org/opentree/argus/ottol@158484/Pan-paniscus' -H 'Connection: keep-alive' --data 'property=ot%3AstudyId&value=XYZ&verbose=true' --compressed'''
ts = template.split('XYZ')
assert len(ts) == 2
study_list = [i.strip() for i in open(sys.argv[2], 'rU').readlines() if i.strip()]
for s in study_list:
ns = s.join(ts)
print ns, '>', s + '.out'
@mtholder

Copy link
Copy Markdown
Author

redirect stdout to run.sh and then bash run.sh in a clean directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment