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

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?
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.
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...
8-17. Listed below are several types of accounting data to be coded. For each data item,...
8-17. Listed below are several types of accounting data to be coded. For each data item, recommend a type of code (mnemonic, sequence, block, or group) and support your choice. a. Employee identification number on a computer file b. Product number for a sales catalog c. Inventory number for the products of a wholesale drug company d. Inventory part number for a bicycle manufacturing company e. Identification numbers on the forms waiters and waitresses use to take orders f. Identification...
Must be coded in C#. 10.8 (Rational Numbers) Create a class called Rational for performing arithmetic...
Must be coded in C#. 10.8 (Rational Numbers) Create a class called Rational for performing arithmetic with fractions. Write an app to test your class. Use integer variables to represent the private instance variables of the class—the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it’s declared. The constructor should store the fraction in reduced form. The fraction 2/4 is equivalent to 1/2 and would be stored in the object...
In a Servlet, how do you read HTML Form Data (data from the previous Web page)...
In a Servlet, how do you read HTML Form Data (data from the previous Web page) into the Servlet?
Program must be in Python Write a program in Python whose inputs are three integers, and...
Program must be in Python Write a program in Python whose inputs are three integers, and whose output is the smallest of the three values. Input is 7 15 3
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT