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