from pprint import pprint as pp
import requests
# Get strain list
strains = requests.get("https://docs.google.com/spreadsheets/d/1V6YHzblaDph01sFDI8YK_fP0H7sVebHQTXypGdiQIjI/pub?output=tsv")
strains = filter(len,set([x.split("\t")[1] for x in strains.text.splitlines()[1:]]))
for x in strains:
url = "http://api.wormbase.org/rest/field/strain/" + x + "/origin"
r = requests.get(url, headers = {"content-type":"application/json"})
if r.status_code == 200:
x = r.json()["origin"]
strain = x["name"]["data"]["label"]
place = x["place"]["data"]
landscape = x["landscape"]["data"]
substrate = x["substrate"]["data"]
place = x["landscape"]["data"]
date_isolated = x["date_isolated"]["data"]
sampled_by = x["landscape"]["data"]
isolated_by = x["laboratory"]["data"][0]["representative"][0]["label"]
out = [strain, landscape, substrate, place, date_isolated, sampled_by, isolated_by]
out = ["" if x==None else x for x in out]
print "\t".join(out)