Objective: Write a program in Python using wrapper API to get weather information.  Step 1.1: Get PyOWM API key  Follow these steps to get a weather info API key from Open Weather Map.org:  Go to openweathermap.org/appid  Under “Sign up and call API for free”, click “Sign up”  Register. Click “Create an Account”. Remember your login and password.  They may send a confirmation link to the email you used to register. Use it to confirm.  Go to “API keys”.  Copy key from gray box into a text file and save it for later. You will insert the key into the provided Python code that accesses the API.    Step 1.2. Install PyOWM module on your computer   Follow these steps to install PyOWM module on your computer:  Start your terminal (Windows users start WSL terminal or Windows Console). Type pip3 install pyowm (the module should install).    Step 1.3: Download, Add Code, and Test interactive App  You should use the starter app weather.py. It includes a predefined function getweather() that calls OWM’s Web-API to get today’s temperatures (in Fahrenheit) for the specified city and return them in a dictionary with keys “temp_max”, “temp”, and “temp_min”. Do not edit getweather(). Insert your API key where indicated. Add code in main() that asks users for a city and country, calls getweather() with the city and country, prints the min, current, and max temperatures from the returned dictionary in both Fahrenheit and Celsius ( (°F - 32) / 1.8 = °C), then asks the user if they want to check another city (with input validation). The program’s input and output should look like this if the user enters Y or N (but if the user enters anything other than Y or N, it asks again):    Check temperature in cities worldwide  City: Paris  Country: France    The max temperature: 42.01 F 5.56 C  The current temperature: 36.39 F 2.44 C The minimum temperature: 28.99 F -1.67 C   Check the weather in another city? (Y or N): Y City: NY Country: USA

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Objective: Write a program in Python using wrapper API to get weather information. 

Step 1.1: Get PyOWM API key 

Follow these steps to get a weather info API key from Open Weather Map.org: 

  • Go to openweathermap.org/appid 
  • Under “Sign up and call API for free”, click “Sign up” 
  • Register. Click “Create an Account”. Remember your login and password. 
  • They may send a confirmation link to the email you used to register. Use it to confirm. 
  • Go to “API keys”. 
  • Copy key from gray box into a text file and save it for later. You will insert the key into the provided Python code that accesses the API. 

 

Step 1.2. Install PyOWM module on your computer 

 Follow these steps to install PyOWM module on your computer: 

  • Start your terminal (Windows users start WSL terminal or Windows Console).
  • Type pip3 install pyowm (the module should install). 

 

Step 1.3: Download, Add Code, and Test interactive App 

You should use the starter app weather.py. It includes a predefined function getweather() that calls OWM’s Web-API to get today’s temperatures (in Fahrenheit) for the specified city and return them in a dictionary with keys “temp_max”, “temp”, and “temp_min”. Do not edit getweather(). Insert your API key where indicated. Add code in main() that asks users for a city and country, calls getweather() with the city and country, prints the min, current, and max temperatures from the returned dictionary in both Fahrenheit and Celsius ( (°F - 32) / 1.8 = °C), then asks the user if they want to check another city (with input validation). The program’s input and output should look like this if the user enters Y or N (but if the user enters anything other than Y or N, it asks again): 

 

Check temperature in cities worldwide 

City: Paris 

Country: France 

 

The max temperature: 42.01 F 5.56 C 

The current temperature: 36.39 F 2.44 C

The minimum temperature: 28.99 F -1.67 C

 

Check the weather in another city? (Y or N): Y

City: NY

Country: USA

weather.py
1
# App to Get Temperature Data from "0pen Weather Map" Service
import pyowm
2
3
#Define global variable to store OWM weather-query object
pyowm. OWM ( 'Replace this text with your py0WM API-key')
owm.weather_manager()
5
Owm =
6.
wman
7
8
- DO NOT EDIT
#Function that gets weather info from API
# Returns results in dictionary with
# keys 'temp', 'temp_max', 'temp_min'
# and values that are floats4
9
10
11
12
# DO NOT EDIT THIS FUNCTION
def getWeather(city, country):
location
13
city+','+country
wman.weather_at_place(location).weather
14
15
observation
16
return observation.temperature('fahrenheit')
17
18
def main():
# Add code that prints program's purpose, then:
1. Prompts user for city and country
2. Calls getWeather with city and country and saves returned dictionary
3. Uses keys "temp_max", "temp", and "temp_min" to extract temperatures
4. Prints the temperatures
5. Asks if user wants to check another city (Y or N)
6. Validates user response
19
20
#3
21
#3
22
23
23
#3
24
23
#3
7. If Y, loop back to step 1
25
26
#
27
28
#Start the app
29
main()
30
Transcribed Image Text:weather.py 1 # App to Get Temperature Data from "0pen Weather Map" Service import pyowm 2 3 #Define global variable to store OWM weather-query object pyowm. OWM ( 'Replace this text with your py0WM API-key') owm.weather_manager() 5 Owm = 6. wman 7 8 - DO NOT EDIT #Function that gets weather info from API # Returns results in dictionary with # keys 'temp', 'temp_max', 'temp_min' # and values that are floats4 9 10 11 12 # DO NOT EDIT THIS FUNCTION def getWeather(city, country): location 13 city+','+country wman.weather_at_place(location).weather 14 15 observation 16 return observation.temperature('fahrenheit') 17 18 def main(): # Add code that prints program's purpose, then: 1. Prompts user for city and country 2. Calls getWeather with city and country and saves returned dictionary 3. Uses keys "temp_max", "temp", and "temp_min" to extract temperatures 4. Prints the temperatures 5. Asks if user wants to check another city (Y or N) 6. Validates user response 19 20 #3 21 #3 22 23 23 #3 24 23 #3 7. If Y, loop back to step 1 25 26 # 27 28 #Start the app 29 main() 30
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY