EX 4 - Use The GAE Launcher To Launch The Web Applications
EX 4 - Use The GAE Launcher To Launch The Web Applications
: 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:
Result:
Thus, the task to use the GAE launcher to launch the web applications was successful.