0% found this document useful (0 votes)
5 views2 pages

Program 4

The document outlines a step-by-step guide to fetch the current date and time along with real-time weather data from the OpenWeatherMap API using R. It includes instructions on obtaining an API key, installing necessary packages, and executing R code to retrieve and display weather information. The expected output includes the current date and time, temperature, humidity, and weather conditions for a specified city.

Uploaded by

sangumadagi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Program 4

The document outlines a step-by-step guide to fetch the current date and time along with real-time weather data from the OpenWeatherMap API using R. It includes instructions on obtaining an API key, installing necessary packages, and executing R code to retrieve and display weather information. The expected output includes the current date and time, temperature, humidity, and weather conditions for a specified city.

Uploaded by

sangumadagi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

To fetch the current date and time and real-time weather data from an online cloud API

(OpenWeatherMap) using R

Objective
 To retrieve system date and time
 To access real-time weather data using a cloud API
 To understand API-based cloud computing interaction

Requirements
 R or RStudio
 Internet connection
 OpenWeatherMap API key (free)

Step 1: Get OpenWeatherMap API Key


1. Go to: [Link]
2. Sign up / login
3. Generate API key
4. Copy the API key

Step 2: Install Required Packages


[Link]("httr")
[Link]("jsonlite")

Step 3: Load Libraries


library(httr)
library(jsonlite)

Step 4: Fetch Current Date and Time


current_time <- [Link]()
print(current_time)

Step 5: Define API URL


Replace "YOUR_API_KEY" with your actual key:

api_key <- "YOUR_API_KEY"


city <- "Bangalore"
url <- paste0("[Link]
city,
"&appid=",
api_key,
"&units=metric")

Step 6: Send Request to Cloud API


response <- GET(url)

Step 7: Extract Data


data <- content(response, "text")
weather_data <- fromJSON(data)

Step 8: Display Weather Information


cat("City:", weather_data$name, "\n")
cat("Temperature:", weather_data$main$temp, "°C\n")
cat("Humidity:", weather_data$main$humidity, "%\n")
cat("Weather:", weather_data$weather[[1]]$description, "\n")

Expected Output
 Current system date and time
 Real-time weather details such as:
o Temperature
o Humidity
o Weather condition

You might also like