-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweather_21.js
40 lines (31 loc) · 995 Bytes
/
weather_21.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { OpenWeather } from './open_weather';
const apiKey = '8058e2e53a8cdc888b244254fc6ceeed';
const Weather = (dt, temp) =>
({
dt,
temp
})
const toFarenheit = k => k + 1000
const toWeather = (dt, temp) =>
Weather((new Date(dt)).toLocaleDateString(), toFarenheit(temp))
const prepareItems = w =>
toWeather(w.dt, w.main.temp)
const getWeatherItems = zip =>
OpenWeather.fetch({ zip, apiKey })
.map(json => json.list.map(prepareItems))
.map(weathers => weathers.map(toLi))
const toLi = weather =>
`<li>${weather.dt} ${weather.temp}</li>`
// =======================
const app = () => {
const goButton = document.getElementById('go')
const input = document.getElementById('zip')
const results = document.getElementById('results')
goButton.addEventListener('click', () => {
const zip = input.value.trim()
getWeatherItems(zip).fork(console.error, html => {
results.innerHTML = html
})
})
}
app()