forked from numcys/Basic_website_HTML_CSS_only
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
102e0da
commit 098b359
Showing
4 changed files
with
439 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.