-
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
Samuel Morgan-Tyghe
committed
Sep 18, 2020
1 parent
a3b770f
commit df195a3
Showing
7 changed files
with
161 additions
and
94 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,76 @@ | ||
|
||
// public date; of moment.js type | ||
// - public temperature; of int type | ||
// - public weather_type; of int or string type to show the correct icon | ||
// sun/cloud | ||
import axios from 'axios' | ||
|
||
|
||
|
||
|
||
|
||
|
||
export function weatherInfo(api: string, iTimes: any) { | ||
var nameValue | ||
var tempValue | ||
var tempValueC | ||
var dateValue | ||
var descValue | ||
var iconValue | ||
var iconPNG | ||
var j = 0 | ||
var element | ||
var nElement | ||
|
||
|
||
axios.get(api) | ||
.then((response: any) => { | ||
|
||
|
||
|
||
nameValue = response.data['city']['name'] | ||
|
||
tempValue = response.data['list'][(iTimes.toString())]['main']['temp'] | ||
tempValueC = (parseInt(tempValue) - 273.15).toFixed(0) //Kelvin To Celsius | ||
|
||
dateValue = response.data['list'][iTimes.toString()]['dt_txt'] | ||
|
||
descValue = response.data['list'][iTimes.toString()]['weather']['0']['description'] | ||
|
||
iconValue = response.data['list'][iTimes.toString()]['weather']['0']['icon'] | ||
iconPNG = 'http://openweathermap.org/img/wn/' + iconValue + '@2x.png' | ||
|
||
const weatherData = { name: nameValue, temp: tempValueC, date: dateValue, desc: descValue, icon: iconPNG } | ||
|
||
|
||
console.log(iconValue) | ||
|
||
console.log(weatherData) | ||
var oLength = Object.keys(weatherData).length; | ||
|
||
for (j > oLength - 1; j++;) { | ||
element = document.getElementById(iTimes) | ||
nElement = document.createTextNode(weatherData.entries(j)) | ||
element.appendChild(nElement) | ||
iTimes++ | ||
} | ||
element = document.getElementById(iTimes) | ||
nElement = document.createElement('img') | ||
nElement.src = weatherData.icon | ||
|
||
|
||
}) | ||
|
||
|
||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
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 |
---|---|---|
@@ -1,50 +1,50 @@ | ||
|
||
// public date; of moment.js type | ||
// - public temperature; of int type | ||
// - public weather_type; of int or string type to show the correct icon | ||
// sun/cloud | ||
import axios from 'axios' | ||
// // public date; of moment.js type | ||
// // - public temperature; of int type | ||
// // - public weather_type; of int or string type to show the correct icon | ||
// // sun/cloud | ||
// import axios from 'axios' | ||
|
||
export function weatherData(api : string) { | ||
let indexOf = 1 | ||
let i = 0 | ||
// export function weatherData(api : string) { | ||
// let indexOf = 1 | ||
// let i = 0 | ||
|
||
|
||
|
||
|
||
axios.get(api) | ||
.then((response: any) => { | ||
for( i = 0 ; i <=3; i++ ){ | ||
// axios.get(api) | ||
// .then((response: any) => { | ||
// for( i = 0 ; i <=3; i++ ){ | ||
|
||
var nameValue = response.data['city']['name'] | ||
// var nameValue = response.data['city']['name'] | ||
|
||
var tempValue = response.data['list'][i.toString()]['main']['temp'] | ||
// var tempValue = response.data['list'][i.toString()]['main']['temp'] | ||
|
||
var dateValue = response.data['list'][i.toString()]['dt_txt'] | ||
// var dateValue = response.data['list'][i.toString()]['dt_txt'] | ||
|
||
var descValue = response.data['list'][i.toString()]['weather']['0']['description'] | ||
// var descValue = response.data['list'][i.toString()]['weather']['0']['description'] | ||
|
||
var iconValue = response.data['list'][i.toString()]['weather']['0']['icon'] | ||
// var iconValue = response.data['list'][i.toString()]['weather']['0']['icon'] | ||
|
||
|
||
var tempValueC = (parseInt(tempValue) - 273.15).toFixed(0) //Kelvin To Celsius | ||
document.getElementById("i"+indexOf.toString()).innerHTML = nameValue | ||
indexOf++ | ||
document.getElementById("i"+indexOf.toString()).innerHTML = tempValueC +'C' | ||
indexOf++ | ||
document.getElementById("i"+indexOf.toString()).innerHTML = dateValue | ||
indexOf++ | ||
document.getElementById("i"+indexOf.toString()).innerHTML = descValue | ||
indexOf++ | ||
(<HTMLImageElement>document.getElementById("i"+indexOf.toString())).src = 'http://openweathermap.org/img/wn/'+iconValue+'@2x.png' | ||
indexOf++ | ||
if (indexOf > 20 ){indexOf=1} | ||
// var tempValueC = (parseInt(tempValue) - 273.15).toFixed(0) //Kelvin To Celsius | ||
// document.getElementById("i"+indexOf.toString()).innerHTML = nameValue | ||
// indexOf++ | ||
// document.getElementById("i"+indexOf.toString()).innerHTML = tempValueC +'C' | ||
// indexOf++ | ||
// document.getElementById("i"+indexOf.toString()).innerHTML = dateValue | ||
// indexOf++ | ||
// document.getElementById("i"+indexOf.toString()).innerHTML = descValue | ||
// indexOf++ | ||
// (<HTMLImageElement>document.getElementById("i"+indexOf.toString())).src = 'http://openweathermap.org/img/wn/'+iconValue+'@2x.png' | ||
// indexOf++ | ||
// if (indexOf > 20 ){indexOf=1} | ||
|
||
} i=0 | ||
// } i=0 | ||
|
||
}) | ||
return api | ||
} | ||
// }) | ||
// return api | ||
// } | ||
|
||
|
||
|
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