Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
56 changes: 56 additions & 0 deletions css/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
header,
main
{
border: solid black 1px;
padding: .5em;
}

header {
grid-area: header;
background-color: rgb(220, 227, 233);
}

main {
grid-area: main;
background-color: aliceblue;
padding-top: 20px;
}

#zipCode {
width: 6em;
}

#forecast {
width: 100%;
display: flexbox;
flex-direction: row;
color: grey;
}

#temperature{
font-size: 2em;
}

img {
width: 50px;
height: 50px;
display: block;
margin: auto;
padding-bottom: 5px;
}

#imgForTemp {
width: 150px;
height: 150px;
display: inline-block;
margin: auto;
padding: 15px;
}

.container {
grid-template-columns: 1fr;
grid-template-rows: minmax(200px, auto) minmax(200px, auto);
grid-template-areas:
"header"
"main";
}
Binary file added imgs/.DS_Store
Binary file not shown.
Binary file added imgs/clear.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/cloudy.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/lightsnow.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/mcloudy.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/partlycloudy.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/rain.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/snow.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/thunderstorm.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/thunderstormwithrain.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 34 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,43 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<title>Weather App</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css"
integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
<link rel="stylesheet" href="css/custom.css">
</head>

<body>
<h1>Hola Mundo</h1>
<div class="container">
<header>
<h1 id="title" class="text-center">Weather App</h1>

</header>

<main>

<label id="location"></label>
<hr>

<label for="">Temperature: </label>
<label id="temperature"></label>
<img id="imgForTemp">

<hr>
<p>Forecast:</p>
<div id="forecast"></div>
</main>

</div>

<!-- jQuery first, then Popper.js, then Bootstrap JS, then local js file -->
<script src="http://code.jquery.com/jquery-3.5.1.min.js"
integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>  
<script src="js/plugins.js"></script>
</body>

</html>
114 changes: 114 additions & 0 deletions js/plugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/// <reference path="../typings/globals/jquery/index.d.ts" />

let weatherTemp;
let weekdays = { 0 : "Sunday", 1 : "Monday", 2 : "Tuesday", 3 : "Wednesday", 4 : "Thursday", 5 : "Friday", 6 : "Saturday" };


$(document).ready(function() {
$forecast = $('#forecast');
$($forecast).removeClass();

const watchId = navigator.geolocation.watchPosition(successCallback, errorCallback);
});

const successCallback = (position) => {
let longitude = position.coords.longitude;
let latitude = position.coords.latitude;

GetWeather(longitude, latitude);
DisplayLocation(longitude, latitude);
NextSevenDays();
};

const errorCallback = (error) => {
console.log(error);
};


function GetWeather(longitude, latitude) {
let product = "civillight";
let output = "json";

let client = new XMLHttpRequest();

client.open("GET", `http://www.7timer.info/bin/api.pl?lon=${longitude}&lat=${latitude}&product=${product}&output=${output}`, false);

client.overrideMimeType("application/document");

if (client.onreadystatechange = function () {

if (client.readyState == 4) {
let response = JSON.parse(client.responseText);
weatherTemp = response.dataseries;
console.log(weatherTemp);
$('#temperature').text(ConvertToFaranHeight(response.dataseries[0].temp2m.max));
$('#imgForTemp').attr("src", `imgs/${weatherTemp[0].weather}.jpeg`);
}

});

client.send();
}

function ConvertToFaranHeight(celcius) {
return (celcius * 9 / 5) + 32;
}

function DisplayLocation(longitude, latitude){

const request = new XMLHttpRequest();

const method = 'GET';
const url = `https://api.bigdatacloud.net/data/reverse-geocode-client?latitude=${latitude}&longitude=${longitude}&localityLanguage=en`;
const async = false;

request.open(method, url, async);
request.onreadystatechange = function(){
if(request.readyState == 4 && request.status == 200){
const data = JSON.parse(request.responseText);
const localLocation = data.city.length > 0 ? data.city : data.locality;
const country = data.countryCode;
$('#location').text(`${localLocation}, ${country}`);
}
};
request.send();

};

function NextSevenDays() {
const $forecast = $('#forecast');
$forecast.html("");
const todaysDate = new Date().getDay();


let i = todaysDate;
let k = 0;
for(; i < 7; i++){
SetCard(i, weatherTemp[k].temp2m.min, weatherTemp[k].temp2m.max, weatherTemp[i].weather);
k++;
}
for(let j = 0; j < todaysDate; j++){
SetCard(j, weatherTemp[k].temp2m.min, weatherTemp[k].temp2m.max, weatherTemp[j].weather);
k++;
}


}

function SetCard(day, min, max, weatherPic) {
$forecast.append(
`
<div class="card" style="width: calc(95% / 7);">
<h6 class="card-title" style="padding-top: 5px">${weekdays[day].substring(0, 3)}</h6>

<div class="card-body">
<img src="imgs/${weatherPic}.jpeg" alt="${weatherPic}">
<span class="card-text" style="font-weight: bold;">${ConvertToFaranHeight(max)}\u00B0</span>
<span class="card-text">${ConvertToFaranHeight(min)}\u00B0</span>
</div>
</div>
`
);

$forecast.addClass("d-inline-flex justify-content-around text-center");
}