-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
54 lines (43 loc) · 1.82 KB
/
app.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
require('dotenv').config()
const { default: axios } = require("axios")
const { readInput, promptMenu, pause, listPlaces } = require("./helpers/inquirer")
const Searches = require("./models/searches")
const main = async () => {
let opt
const sch = new Searches()
do {
opt = await promptMenu()
switch (opt) {
case 1:
//Show msg
const place = await readInput('City: ')
//Search places
const places = await sch.city(place)
//Choose place
const placeId = await listPlaces(places)
if (placeId === 0) continue
const placeName = places.find(p => p.id === placeId)
//Save place
sch.save(placeName.name)
//Weather data
const weather = await sch.getWeather(placeName.lat, placeName.lng)
//Show data
console.log('\nCity and Weather information\n'.cyan)
console.log('Actual weather'.cyan,`${weather.desc}`.green)
console.log('City:'.cyan, placeName.name)
console.log('Lat:'.cyan, placeName.lat, 'Lon:'.cyan, placeName.lng)
console.log('Temp:'.cyan, weather.temp,`ºC`)
console.log('Min:'.cyan, weather.min, `ºC`, 'Max:'.cyan, weather.max, `ºC`)
console.log('Humitidy:'.cyan, weather.hum, `%`)
break;
case 2:
sch.history.forEach((p, index) => {
let idx = `${index + 1}`.cyan
console.log(idx, '.', p.replace(/\w\S*/g, (w) => (w.replace(/^\w/, (c) => c.toUpperCase()))))
})
break;
}
if (opt !== 0) { await pause() }
} while (opt !== 0)
}
main()