Question

In: Computer Science

Must be coded in python. Consuming A Web Service with Python Consuming data from programmable web...

Must be coded in python.

Consuming A Web Service with Python

Consuming data from programmable web based API’s is growing rapidly. According to ProgrammableWeb, in just six years (2010-2016), web API counts increased 758 percent with the majority being REST based. This is driven by a myriad of factors but growth of cloud based applications, (distributed computing by another name), and the resulting need to integrate the different categories is a major factor.

Description

Write a client to consume a REST web service of you choice using Python. There are many listings of such services but an excellent resource is ProgrammableWeb. Your information should produce useful information. I.e. a dump of cryptic data is not the desired product. Examples could be a weather forecast, stock quote, Bible verse, etc.,

Your solution should present the user with a question with the answer contributing to the data used in the REST web service call. For example, a weather forecast would prompt the user to enter a zip code or other location information. Once the web transaction is complete, the program should prompt again with the same question to complete another transaction. This should continue until the user enters a specified termination condition.

You output must be presented in an understandable manner. Dumps of XML, JSON, etc., are substandard and will be graded accordingly.

Hint:

Be sure to click on the examples and look at the address bar of your browser. That is what you will need to generate with the Python requests module.

You are free to use any REST web service you find but I recommend this one if you are looking for something straightforward. One word of caution, some services require you to request access via an API key. The approval may not be immediate so you will want to find something sooner rather than later. The example I listed above requires no approval.

Solutions

Expert Solution

import requests

URL = "http://labs.bible.org/api/?passage="

print("To terminate the program, use 'exit'")
while True:
print("-"*30)
inp = input("For random facts, use 'random': ")
print("-"*30)
if inp.lower()=="random":
#to fetch the result from the API
#requests.get needs a url
response = requests.get(URL+"random")
proper_text ="-->".join( response.text[3:].split('</b>'))
print(proper_text)
elif inp.lower()=="exit":
print("TERMINATING...")
break
else:
print("Use proper input")

OUTPUT:


Related Solutions

THE FOLLOWING MUST BE CODED IN C THE FOLLOWING MUST BE CODED IN C THE FOLLOWING...
THE FOLLOWING MUST BE CODED IN C THE FOLLOWING MUST BE CODED IN C THE FOLLOWING MUST BE CODED IN C   THE FOLLOWING MUST BE CODED IN C Write a program that demonstrates handling pointers. Create two integer variables m and n, and two pointers, pm pointing to m, and pn pointing to n. Produce the following output: Address of m: 0x7ffcc3ad291c Value of m: 29 Address of n: 0x7ffcc3ad291d Value of n: 34 Now pm is pointed to m...
Need this program in python. The data must be taken from user as input. Write a...
Need this program in python. The data must be taken from user as input. Write a program that prompts the user to select either Miles-to-Kilometers or Kilometers-to-Miles, then asks the user to enter the distance they wish to convert. The conversion formula is: Miles = Kilometers X 0.6214 Kilometers = Miles / 0.6214 Write two functions that each accept a distance as an argument, one that converts from Miles-to-Kilometers and another that converts from Kilometers-to-Miles The conversion MUST be done...
Evaluate your margin al and total utility of consuming a good or service and from your...
Evaluate your margin al and total utility of consuming a good or service and from your analysis, what do you think is more important to determine your consumption? You will want to examine a time where you experienced diminishing marginal returns with your consumption in the last week and explain how you determine when diminishing marginal returns set it. Please make sure to use the terms from this unit in your analysis.
Historical data show that customers who download music from a popular Web service spend approximately​ $24...
Historical data show that customers who download music from a popular Web service spend approximately​ $24 per​ month, with a standard deviation of ​$3. Assume the spending follows the normal probability distribution. Find the probability that a customer will spend at least ​$20 per month. How much​ (or more) do the top 7​% of customers spend? What is the probability that a customer will spend at least ​$20 per​ month? How much do the top 7​% of customers​ spend?
Needs to be coded in Python. Hello i am working on a project for my computer...
Needs to be coded in Python. Hello i am working on a project for my computer programming course and i am having trouble with one part. The code needs to be able to produce two versions of an output given inputs by the user. for instance. Here is the code i have to produce the following output. The input from the user are num1 num2 and asc which is just asking if they want the output to be ascending or...
Research information on how Python is used for Web applications and accessing resources on the Web?...
Research information on how Python is used for Web applications and accessing resources on the Web? Please help me for short discussion. Thanks in advance.
In this assignment, you will develop a simple Web server in Python that is capable of...
In this assignment, you will develop a simple Web server in Python that is capable of processing only one request. Specifically, your Web server will (i) create a connection socket when contacted by a client (browser); (ii) receive the HTTP request from this connection; (iii) parse the request to determine the specific file being requested; (iv) get the requested file from the server’s file system; (v) create an HTTP response message consisting of the requested file preceded by header lines;...
Web Projects If you are learning a web technology, you must create a new page that...
Web Projects If you are learning a web technology, you must create a new page that is web-accessible (use your individual burrow account) that includes a form with a field that allows the user to enter a number only. ● Create an input that allows a number to be entered. Only whole numbers should be allowed. ● Add a button below the input that says "Translate". ● When the button is clicked, it should grab the current number in the...
Using this SAS code for the data. The outcome variable is SBP and should be coded...
Using this SAS code for the data. The outcome variable is SBP and should be coded to appear on the y-axis. Note: you have to write the appropriate program Answer the following questions: Report the correlation coefficient and the p-value. (2pts) Report the parameter estimate for the intercept and heart rate (4pts) Using the regression equation, what is the expected blood pressure for someone with a heart rate of 153? (4pts) data sas_test; input hr sbp; datalines; 35 80 50...
How do I make a simple TCP python web client and web server using only "import...
How do I make a simple TCP python web client and web server using only "import socket"? Basically, the client connects to the server, and sends a HTTP GET request for a specific file (like a text file, HTML page, jpeg, png etc), the server checks for the file and sends a copy of the data to the client along with the response headers (like 404 if not found, or 200 if okay etc). The process would be: You first...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT