-
Notifications
You must be signed in to change notification settings - Fork 0
/
usersearch.js
66 lines (51 loc) · 1.54 KB
/
usersearch.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
55
56
57
58
59
60
61
62
63
64
65
inquirer = require("inquirer");
weather = require("weather-js");
fsob = require("fs");
function Usersearch(){
this.city = null;
this.weather = null;
}
Usersearch.prototype.getWeather = function(){
inquirer.prompt([
{
name:"user",
message:"what is your name?"
},
{
name:"location",
message:"what is the location?"
}
]).then(function(answer){
// console.log(answer);
var user = answer.user;
var weatherloc = answer.location;
weather.find({ search: weatherloc, degreeType: "F" }, function(err, result) {
// If there is insufficient data, notify the user.
if (err) {
console.log("Sorry we don't have enough data on that location! Try somewhere else.");
return;
}
// Then print the Weather information and complete Address
console.log("Current Temperature: " + result[0].current.temperature + " F");
var timeinMs = Date.now();
var date = new Date(timeinMs);
var curdate = date.getDate();
var curmonth = date.getMonth();
var curyear = date.getFullYear();
// console.log(curdate,curmonth+1,curyear);
var weatherlog = user + ", " + weatherloc + ", " + (curmonth +1) + "-" + curdate + "-" + curyear + " ";
fsob.appendFile("data.txt",weatherlog,"UTF-8",(err) => {
if(err){
console.log("data logging failed");
return;
}
else{
console.log("data logging completed");
}
});
});
});
};
//var usersearch = new Usersearch();
//usersearch.getWeather();
module.exports = Usersearch;