Skip to content

Commit

Permalink
Add weather app
Browse files Browse the repository at this point in the history
  • Loading branch information
donkeshkavya authored Oct 23, 2022
1 parent 102e0da commit 098b359
Show file tree
Hide file tree
Showing 4 changed files with 439 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Weather App/app.js.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const express = require('express');
const https = require('https');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.urlencoded({extended: true}));

app.get("/", function(req, res) {
res.sendFile(__dirname + "/index.html");
});

app.post("/", function(req, res) {
const query = req.body.city;
const units = "metric";
const apiKey = "ohnooo"
const url = "https://api.openweathermap.org/data/2.5/weather?q=" + query + "&units=" + units + "&appid=" + apiKey;
https.get(url, function(response) {
console.log(response.statusCode);
response.on("data", function(data) {
const weatherData = JSON.parse(data);
const temp = weatherData.main.temp;
const description = weatherData.weather[0].description;
const icon = weatherData.weather[0].icon;
const imgURL = "http://openweathermap.org/img/wn/" + icon + "@2x.png";
res.write("<h1>The temperature in " + query + " is " + temp + " degrees Celsius</h1>");
res.write("<h4>The weather description is: " + description + ".</h4>");
res.write("<img src=" + imgURL + ">");
res.send();
});
});
});

app.listen(3000, function() {
console.log("Server started on port 3000");
});
16 changes: 16 additions & 0 deletions Weather App/index.html.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Weather App</title>
</head>
<body>
<div class="">
<form class="" action="/" method="post">
<h2>Enter the name of any city</h2>
<input id="city" type="text" name="city" value=""><br><br>
<button type="submit" name="button">Predict</button>
</form>
</div>
</body>
</html>
Loading

0 comments on commit 098b359

Please sign in to comment.