-
Notifications
You must be signed in to change notification settings - Fork 4
Example of processing a list of IDs querying the API
Pascal Christoph edited this page Aug 10, 2015
·
2 revisions
Say, you have a list of IDs and want to check if these are of type Journal
. You can use the API like this:
curl "http://lobid.org/resource?id=$i&type=http://purl.org/ontology/bibo/Journal"
and consecutively insert the IDs, where $i
is the id you want to check.
You can automize this using loops, e.g. in bash:
#!/bin/bash
for i in $(cat idList.txt); do
curl -s "http://lobid.org/resource?id=$i&type=http://purl.org/ontology/bibo/Journal" |
grep -v '#totalResults":0' |
sed -e 's#.*\(hbzId\)":"\(\w\w[0-9]\{9\}\).*#\2#g'
done
where you get the IDs residing in the file idList
. Note that the file must be properly formatted, that is one ID per line. You may also make this formatting automatically and write the result to idListOfCheckedType.txt
like this:
#!/bin/bash
for i in $(
for a in $(cat idList.txt); do
echo $a |
grep ^HT |
tr ',' '\n'
done ); do
curl -s "http://lobid.org/resource?id=$i&type=http://purl.org/ontology/bibo/Journal" |
grep -v '#totalResults":0' |
sed -e 's#.*\(hbzId\)":"\(\w\w[0-9]\{9\}\).*#\2#g' >> idListOfCheckedType.txt
done