0% found this document useful (0 votes)
149 views3 pages

EX 4 - Use The GAE Launcher To Launch The Web Applications

The document outlines a procedure to use the Google App Engine (GAE) launcher for launching web applications. It includes steps for importing the Google Cloud public key, installing the gcloud CLI, creating a weather application, and running it to display weather information for a specified city. The task was successfully completed as per the outlined procedure.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
149 views3 pages

EX 4 - Use The GAE Launcher To Launch The Web Applications

The document outlines a procedure to use the Google App Engine (GAE) launcher for launching web applications. It includes steps for importing the Google Cloud public key, installing the gcloud CLI, creating a weather application, and running it to display weather information for a specified city. The task was successfully completed as per the outlined procedure.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Exp. No.

: 4
Date:
EX 4: Use the GAE launcher to launch the web applications.

Aim:
To use the GAE launcher to launch the web applications.
Procedure:
1. Import the Google Cloud public key:
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o
/usr/share/keyrings/cloud.google.gpg
2. Add the gcloud CLI distribution URI as a package source:
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg]
https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a
/etc/apt/sources.list.d/google-cloud-sdk.list
3. Update and install the gcloud CLI:
sudo apt-get update && sudo apt-get install google-cloud-cli
4. Run gcloud init to open google cloud.
5. Pick configuration to use:
[1] Re-initialize this configuration [default] with new settings
6. Select an account:
[1] 22b120@psgitech.ac.in
7. Pick cloud project to use:
[1] principal-truck-434504-n6
8. Open cloud shell using the command:
gcloud cloud-shell ssh
9. Create your web application
nano weather.py
10. Program:
import requests
import urllib.parse
API_KEY = 'af9e65722413ec1cbc3f68cdbb04794c'
BASE_URL = "http://api.openweathermap.org/data/2.5/weather?"
def get_weather(city_name):
if not city_name.strip():
print("City name cannot be empty!")
return
city_name_encoded = urllib.parse.quote(city_name)
url = BASE_URL + "q=" + city_name_encoded + "&appid=" + API_KEY +
"&units=metric"
response = requests.get(url)
if response.status_code == 200:
data = response.json()
main = data['main']
wind = data['wind']
weather_desc = data['weather'][0]['description']
print(f"City: {city_name}")
OUTPUT:

g22b144@cloudshell:-/python-docs-samples (principal-truck-434504-n6)$ cd appengine


g22b144@cloudshell:-/python-docs-samples/appengine (principal-truck-434504-n6)$ ls
flexible flexible_python37_and_earlier standard standard_python3
g22b144@cloudshell:-/python-docs-samples/appengine (principal-truck-434504-n6)$ cd standard_python3
g22b144@cloudshell:-/python-docs-samples/appengine/standard_python3 (principal-truck-434504-n6)$ ls
bigquery building-an-app bundled-services cloudsql custon-server django hello_world migration pubsub redis spanner warmup
g22b144@cloudshell:-/python-docs-samples/appengine/standard_python3 (principal-truck-434504-n6)$ cd hello_world
g22b144@cloudshell:-/python-docs-samples/appengine/standard_python3/hello_world (principal-truck-434504-n6)$ ls
app.yaml main.py main_test.py requirements-test.txt requirements.txt weather.py
g22b144@cloudshell:~/python-docs-samples/appengine/standard_python3/hello_world (principal-truck-434504-n6)$ nano weather.py
g22b144@cloudshell:-/python-docs-samples/appengine/standard_python3/hello_world (principal-truck-434504-n6)$ python3 weather.py
Enter city name: Muscat
City: Muscat
Temperature: 35.01°C
Humidity: 52% Pressure: 1007 hPa Weather Description: Clear sky Wind Speed: 1.06 m/s
print(f"Temperature: {main['temp']}°C")
print(f"Humidity: {main['humidity']}%")
print(f"Pressure: {main['pressure']} hPa")
print(f"Weather Description: {weather_desc.capitalize()}")
print(f"Wind Speed: {wind['speed']} m/s")
else:
print(f"City {city_name} not found, please check the city name.")
city = input("Enter city name: ").strip()
get_weather(city)
11. Run the program:
python3 weather.py
12. The output will be displayed

Result:
Thus, the task to use the GAE launcher to launch the web applications was successful.

You might also like