-
Notifications
You must be signed in to change notification settings - Fork 5
/
url_parser.py
executable file
·70 lines (38 loc) · 1.51 KB
/
url_parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
""" Global variable search_vars """
search_vars=[]
def get_vars( url ):
""" Function takes a url string as an argumenent and returns a list of variables"""
from urlparse import urlparse
from urlparse import parse_qs
o = urlparse(url)
""" variables avalable
o.scheme, o.netloc, o.hostname o.port o.path o.params parse_qs(o.query) o.fragment o.username o.password
"""
global search_vars
search_vars=parse_qs(o.query)
"""
Variables extracted this list is nt complete
search_elements=search_vars['elements'][0]
search_nelements=search_vars['nelements'][0]
output_id=search_vars['id'][0]
output_format=search_vars['format'][0]
auth_email=search_vars['email'][0]
auth_key=search_vars['key'][0]
return search_vars
"""
def usage_message():
""" Print message if info is specified"""
if ('info' in search_vars):
print "please take a look at the documentation"
def response():
""" dump a json output complient with the specifications"""
""" ###################### Test program ##################"""
url="http://example.com/minapi/v1/structures?elements=Si,Al,O&nelements=4&id=true&format=json&info=true&email=user@domain.org&key=hhj667"
"""
url="http://example.com/minapi/v1/structures?filter={'reduced_chemical_formula':'SiO2'}"
url="http://example.com/minapi/v1/structures?chemical_formula=SiO2&limit=100"
"""
variables=get_vars(url)
print search_vars
usage_message()