-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalytics.js
89 lines (75 loc) · 2.27 KB
/
analytics.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// analytics.js: to store user files.
const fs = require("fs")
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
})
class Analytics {
fileName = ""
constructor(fileName) {
this.fileName = fileName
}
createFile() {
fs.exists(this.fileName, (exists)=> {
if (exists) {
}
else {
// file does not exist
// create file here
fs.appendFile(this.fileName, "** FILE CREATED **\n", (err)=>{
if (err) {
console.log(err)
}
})
}
})
}
addData(returned_response) {
let parsed = JSON.stringify(returned_response)
fs.appendFile(this.fileName, `${parsed}`, function(err){
if (err) {
console.log(err)
}
else {
console.log("Success.")
}
})
}
readData() {
let parsed = JSON.stringify(returned_response)
fs.readFile(this.fileName,"utf8", function(err,data){
if (err) {
console.log(err)
}
else {
console.log(data)
}
})
}
}
class CommandLineShell extends Analytics {
constructor(fileName, version="1.0.0") {
super(fileName)
this.version = version
}
shell() {
this.createFile() // create the file if it does not exists
console.log("Welcome to WTD Analytics Command Line Shell!")
console.log("analytics file name: ", this.fileName)
console.log("version: ", this.version)
readline.question(`>>> `, (input) => {
input = input.toLowerCase()
if (input == 'q') {
console.log("Thanks for using the shell.")
readline.close()
}
else {
if (input == "analyse") {
// process the analyse function here
}
}
})
}
}
let s = new CommandLineShell("analytics.json")
s.shell()