Mercurial > repos > bernhardlutz > rest_tool
comparison rest_tool_search.py @ 6:9ee84d9fd3a7 draft
Uploaded
author | bernhardlutz |
---|---|
date | Thu, 03 Apr 2014 06:50:57 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
5:1ad356686717 | 6:9ee84d9fd3a7 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 import sys, os | |
4 import argparse | |
5 import readfile | |
6 | |
7 def main(args): | |
8 #search for acitivity or target | |
9 url="http://pubchem.ncbi.nlm.nih.gov/rest/pug/"+args.type+"/name/"+args.name | |
10 if args.type == "assay": | |
11 url+="/aids" | |
12 elif args.type == "compound": | |
13 url+="/cids" | |
14 else: | |
15 url+="/sids" | |
16 url+="/txt" | |
17 #print("url: "+url) | |
18 data=readfile.getresult(url) | |
19 args.outfile.write(data) | |
20 args.outfile.close() | |
21 | |
22 | |
23 if __name__ == "__main__": | |
24 parser = argparse.ArgumentParser() | |
25 parser.add_argument('--name', type=str, required=True, | |
26 help="Enter the name") | |
27 parser.add_argument('--type', type=str, required=True, | |
28 help="What you want to search for") | |
29 parser.add_argument('--outfile', type=argparse.FileType('w'), required=True, | |
30 help="Specify output file") | |
31 if len(sys.argv) < 2: | |
32 print "Too few arguments..." | |
33 parser.print_help() | |
34 exit(1) | |
35 args = parser.parse_args() | |
36 main( args ) |