Reputation: 135
I will get output of a get request as follows
[u'Mango', u'Banana', u'Apple', u'Grapes']
And i will be asking user to select one of the fruit
fruit_name = raw_input("Enter fruit name from the above list :")
Once i get the input from user i wanted fire request as per the user input as below...
If fruit_name is Mango
execute below get request
http://12.345.67.891:8000/api/datasources/proxy/1/query?db=UK_GHS&q=SELECT%20sum(%22count%22)%20FROM%20%22gatling%22%20WHERE%20%22status%22%20%3D%20%27ok%27%20AND%20%22simulation%22%20%3D~%20%2Fsoak-test*%2F%20AND%20time%20%3E%201544491800000ms%20and%20time%20%3C%201544495400000ms%20GROUP%20BY%20%22script%22&epoch=ms
If fruit_name is Banana
http://12.345.67.891:8000/api/datasources/proxy/1/query?db=UK_GHS&q=SELECT%20sum(%22count%22)%20FROM%20%22gatling%22%20WHERE%20%22status%22%20%3D%20%27ok%27%20AND%20%22simulation%22%20%3D~%20%2Fspike-test*%2F%20AND%20time%20%3E%201544491800000ms%20and%20time%20%3C%201544495400000ms%20GROUP%20BY%20%22script%22&epoch=ms
If fruit_name is Apple
http://12.345.67.891:8000/api/datasources/proxy/1/query?db=UK_GHS&q=SELECT%20sum(%22count%22)%20FROM%20%22gatling%22%20WHERE%20%22status%22%20%3D%20%27ok%27%20AND%20%22simulation%22%20%3D~%20%2Fload-test*%2F%20AND%20time%20%3E%201544491800000ms%20and%20time%20%3C%201544495400000ms%20GROUP%20BY%20%22script%22&epoch=ms
Can someone help me to achieve this?
Upvotes: 0
Views: 106
Reputation: 863301
If different values per list better is create dictionary for lookup with get
method for return value if no match:
d = {'Mango': 'http://12.345.67.891:8000/api/datasources/proxy/1/query?db=UK_GHS&q=SELECT%20sum(%22count%22)%20FROM%20%22gatling%22%20WHERE%20%22status%22%20%3D%20%27ok%27%20AND%20%22simulation%22%20%3D~%20%2Fsoak-test*%2F%20AND%20time%20%3E%201544491800000ms%20and%20time%20%3C%201544495400000ms%20GROUP%20BY%20%22script%22&epoch=ms',
'Banana':'http://12.345.67.891:8000/api/datasources/proxy/1/query?db=UK_GHS&q=SELECT%20sum(%22count%22)%20FROM%20%22gatling%22%20WHERE%20%22status%22%20%3D%20%27ok%27%20AND%20%22simulation%22%20%3D~%20%2Fspike-test*%2F%20AND%20time%20%3E%201544491800000ms%20and%20time%20%3C%201544495400000ms%20GROUP%20BY%20%22script%22&epoch=ms',
'Apple':'http://12.345.67.891:8000/api/datasources/proxy/1/query?db=UK_GHS&q=SELECT%20sum(%22count%22)%20FROM%20%22gatling%22%20WHERE%20%22status%22%20%3D%20%27ok%27%20AND%20%22simulation%22%20%3D~%20%2Fload-test*%2F%20AND%20time%20%3E%201544491800000ms%20and%20time%20%3C%201544495400000ms%20GROUP%20BY%20%22script%22&epoch=ms'}
fruit_name = raw_input("Enter fruit name from the above list :")
out = d.get(fruit_name, 'No value in list')
print out
Enter fruit name from the above list :Banana
http://10.111.21.314:8000/api/datasources/proxy/1/query
Enter fruit name from the above list :test
No value in list
Upvotes: 2
Reputation: 71
Adding onto @jezrael's answer, you can do something like this:
L = [u'Mango', u'Banana', u'Apple', u'Grapes']
fruit_name = raw_input("Enter fruit name from the above list :")
url_dict = {'Mango': 'http://12.345.67.891:8000/api/datasources/proxy/1/query',
'Banana': 'http://10.111.21.314:8000/api/datasources/proxy/1/query',
'Apple': 'http://15.161.71.819:8000/api/datasources/proxy/1/query',
'Grapes': 'http://20.212.22.324:8000/api/datasources/proxy/1/query'}
print url_dict.get(fruit_name, 'No URL configured')
Upvotes: 1