Question

We will be creating an application to interacts with a webservice in order to obtain data....

We will be creating an application to interacts with a webservice in order to obtain data.

Your program will use all of the information you’ve learned in the class in order to create a useful application.

Your program must prompt the user for their city or zip code and request weather forecast data from OpenWeatherMap:

http://openweathermap.org/

Your program must display the weather information in a READABLE format to the user.

Requirements: Create a header for your program just as you have in the past.

Create a Python Application which asks the user for their zip code or city.

Use the zip code or city name in order to obtain weather forecast data from OpenWeatherMap.

Display the weather forecast in a readable format to the user. Use comments within the application where appropriate in order to document what the program is doing.

Use functions including a main function.

Allow the user to run the program multiple times to allow them to look up weather conditions for multiple locations. Validate whether the user entered valid data.

If valid data isn’t presented notify the user.

Use the Requests library in order to request data from the webservice.

Use Try blocks to ensure that your request was successful.

If the connection was not successful display a message to the user.

Use Python 3

Use try blocks when establishing connections to the webservice.

You must print a message to the user indicating whether or not the connection was successful

Notes: Be creative. This assignment is a real world program. Use it as an opportunity to improve your knowledge. Sign up for API Key. The API key will look something similar to this: d5751b1a9e2e4b2b8c7983646072da8b

Make a connection to the API using the Requests library.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

NOTE: You need to follow the following steps to make the program work.

1) Create an account at the website "openweathermap.org" .

2) Then, you need to copy the api_key from the same site at "home.openweathermap.org/api_keys"

3) Paste it into the api_key variable in the weather_data function of the python program.

4) Run the program

Screenshot:

CODE:

# import required modules
import requests

# function to request for data
def weather_data(query):
   # Enter your API key here
   api_key = ""
   # base_url variable to store url
   base_url = "http://api.openweathermap.org/data/2.5/weather?"
   complete_url = base_url + "appid=" + api_key + "&" + query
   # response object
   res=requests.get(complete_url);
   return res.json();

# function to display results
def display_results(weathers,city):
   print("{}'s temperature: {}°C ".format(city,weathers['main']['temp']))
   print("Wind speed: {} m/s".format(weathers['wind']['speed']))
   print("Description: {}".format(weathers['weather'][0]['description']))
   print("Weather: {}".format(weathers['weather'][0]['main']))

# main function
def main():
   # Give city name
   city=input('Enter the city:')
   print()
   # try-except block
   try:
      query='q='+city;
      w_data=weather_data(query);
      display_results(w_data, city)
      print()
   except:
      print('City name not found')

if __name__=='__main__':
   main()

Add a comment
Know the answer?
Add Answer to:
We will be creating an application to interacts with a webservice in order to obtain data....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Weather Program Create an application to interacts with a web service in order to obtain data....

    Weather Program Create an application to interacts with a web service in order to obtain data. Program must prompt the user for their city or zip code and request weather forecast data from OpenWeatherMap (https://openweathermap.org). Program must display the weather information in a READABLE format to the user. Requirements: Create a header for your program just as you have in the past. Create a Python Application which asks the user for their zip code or city. Use the zip code...

  • This assignemnt for Android development using Java Weather Forecaster App Goal: Create an app to display...

    This assignemnt for Android development using Java Weather Forecaster App Goal: Create an app to display a weather forecast for the user’s current location Create the app titled Weather Forecaster The first screen will have a textbox for the user to enter a zip code and a button to submit When the user enters the zip code and clicks the button, the app will navigate to the weather forecast screen. The weather forecast screen will show the current weather for...

  • In this lab assignment, you'll write code that parses an email address and formats the ci and zip...

    Using Microsoft Visual Studio C# In this lab assignment, you'll write code that parses an email address and formats the ci and zip code portion of an address. String Handling Email: nne@murach.com Parse City: Fresno State: ca Zp code: 93722 Format ให้ 2 Parsed String Formatted String User name: anne Domain name: murach.comm City, State, Zip: Fresno, CA 93722 OK OK Create a new Windows Forms Application named StringHandling and build the form as shown above. 1. Add code to...

  • In this assessment, you will design and code a Java console application that validates the data...

    In this assessment, you will design and code a Java console application that validates the data entry of a course code (like IT4782) and report back if the course code is valid or not valid. The application uses the Java char and String data types to implement the validation. You can use either the Toolwire environment or your local Java development environment to complete this assignment. The requirements of this application are as follows: The application is to read a...

  • Flowchart for Python program: Design and create a program for the ULM Coffee Shop to provide...

    Flowchart for Python program: Design and create a program for the ULM Coffee Shop to provide some customer market research data. When a customer places an order, a clerk asks for the customer’s zip code and age. The clerk enters that data as well as the number of items the customer orders. The program operates continuously until the clerk enters a 0 for zip code at the end of the day. When the clerk enters an invalid zip code (more...

  • Create a Python list (use first three letters of your name followed by the letter L...

    Create a Python list (use first three letters of your name followed by the letter L as the name of the list.) with the following data: 10, 20.0, 50.00, 7000, 7500, 7700, 7800, 8000, 9000, ‘python’. Display the entire list with an appropriate message. Display the 4th element in the list with an appropriate message. Display the first 3 values of the list only. Display all the values starting from the sixth element to the end of the list. Change...

  • 2- Create Python file to allow the "Digital Library Website" projects to select one of the...

    2- Create Python file to allow the "Digital Library Website" projects to select one of the web pages in the website (A: Books Online, B: Collections, C: Research, Q: Log out or quit). Display message "Please enter your choice: ". When the user selects a choice; it will call a function to process the request and display a message "Welcome to Books Online" as an example for respond if the user selected "A". The user has chance to select another...

  • In Java please Create a GUI application that accepts student registration data. The GUI with valid...

    In Java please Create a GUI application that accepts student registration data. The GUI with valid data Shudent Fagtrtion x Rt Name Haold Moore Lst Name Yar of Brth 2001 Temporary PesowordHal200 Wlcome Harald Moore! RegsterEt The GUI with invalid data Shudent Fegtrtion DX Fect Name Haold Last Name ar of Brth 2001 Tempoay Pawod Haold 200 Pesse eer St and lact name and ye of bith Regster Et Specifications Use FXML to create the GUI The text box that...

  • C# WINDOWS FORMS APPLICATION (not CONSOLE APPLICATION ) (Please screenshot window form of this program and...

    C# WINDOWS FORMS APPLICATION (not CONSOLE APPLICATION ) (Please screenshot window form of this program and write code on computer. Thank you very much !) For this week's assignment , create and complete a Windows application for the following question. Airline Reservation System: An airline has just bought a computer for its new reservation system. Develop a new system to assign seats on the new airplane( capacity: 10 seats) Display the following alternatives: "Please type 1 for first class, and...

  • In C++ Task 3: Use the stack and queue to simulate receiving and transforming data We are creating a system that will co...

    In C++ Task 3: Use the stack and queue to simulate receiving and transforming data We are creating a system that will convert strings sent over a serial bus one character at a time. The conversion will be from big to little endian or from little to big endian. To simplify this, each character will be considered a word. Little endian will have the lowest address first. Big endian will have the biggest address first. For example (for this lab),...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT