Skip to content

Commit 08ea646

Browse files
authored
Add Mood Meter
1 parent e393836 commit 08ea646

File tree

3 files changed

+252
-0
lines changed

3 files changed

+252
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env node
2+
3+
// Dependency: This script requires Nodejs.
4+
// Install Node: https://nodejs.org/en/download/
5+
6+
// Required parameters:
7+
// @raycast.schemaVersion 1
8+
// @raycast.title Add Mood
9+
// @raycast.mode silent
10+
// @raycast.packageName Dashboard
11+
//
12+
// Optional parameters:
13+
// @raycast.icon ☕️
14+
// @raycast.argument1 { "type": "text", "placeholder": "mood rating 1-5",}
15+
// @raycast.argument2 { "type": "text", "placeholder": "Day number", "optional":true }
16+
17+
18+
// Documentation:
19+
// @raycast.description Add mood value to current or specified date
20+
// @raycast.author Federico Miraglia
21+
// @raycast.authorURL https://github.com/Mitra98t
22+
23+
24+
const { exec } = require('child_process')
25+
const fs = require("fs")
26+
const homedir = require('os').homedir();
27+
const filePath = `${homedir}/.moodTable.json`
28+
let now = new Date()
29+
30+
if (!fs.existsSync(filePath)) {
31+
exec(`echo '{}' > ${filePath}`)
32+
}
33+
34+
35+
let json = fs.readFileSync(filePath)
36+
let parsedMoods = JSON.parse(json)
37+
var moodVal = Number(process.argv.slice(2)[0])
38+
var dayNum = Number(process.argv.slice(2)[1])
39+
40+
if (parsedMoods[now.getFullYear()] == null) {
41+
parsedMoods[now.getFullYear()] = [[], [], [], [], [], [], [], [], [], [], [], []]
42+
fs.writeFileSync(filePath, JSON.stringify(parsedMoods))
43+
}
44+
45+
if (moodVal > 0 && moodVal <= 5) {
46+
let dayVal = dayNum && dayNum > 0 && dayNum <= 31 ? dayNum : now.getDate()
47+
let index = parsedMoods[now.getFullYear()][now.getMonth()].findIndex(d => d.date == dayVal)
48+
if (index != -1)
49+
parsedMoods[now.getFullYear()][now.getMonth()][index] = { date: dayVal, mood: moodVal }
50+
else
51+
parsedMoods[now.getFullYear()][now.getMonth()].push({ date: dayVal, mood: moodVal })
52+
fs.writeFileSync(filePath, JSON.stringify(parsedMoods))
53+
console.log("Added mood for today ☕️")
54+
}
55+
else console.log("Mood must be between 1 and 5")
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env node
2+
3+
// Dependency: This script requires Nodejs.
4+
// Install Node: https://nodejs.org/en/download/
5+
6+
// Required parameters:
7+
// @raycast.schemaVersion 1
8+
// @raycast.title Display Mood Month
9+
// @raycast.mode inline
10+
// @raycast.refreshTime 5s
11+
// @raycast.packageName Dashboard
12+
//
13+
// Optional parameters:
14+
// @raycast.icon ☕️
15+
16+
// Documentation:
17+
// @raycast.description Displays month mood table
18+
// @raycast.author Federico Miraglia
19+
// @raycast.authorURL https://github.com/Mitra98t
20+
21+
22+
const { exec } = require('child_process')
23+
const fs = require("fs")
24+
const homedir = require('os').homedir();
25+
const filePath = `${homedir}/.moodTable.json`
26+
27+
if (!fs.existsSync(filePath)) {
28+
exec(`echo '{}' > ${filePath}`)
29+
}
30+
let json = fs.readFileSync(filePath)
31+
let parsedMoods = JSON.parse(json)
32+
let now = new Date()
33+
let bars = { full: "▓", empty: "░" }
34+
35+
if (parsedMoods[now.getFullYear()] == null) {
36+
parsedMoods[now.getFullYear()] = [[], [], [], [], [], [], [], [], [], [], [], []]
37+
fs.writeFileSync(filePath, JSON.stringify(parsedMoods))
38+
console.log("loading...")
39+
}
40+
41+
let resArr = [];
42+
for (let i = 0; i < daysInMonth(now.getMonth(), now.getFullYear()); i++) {
43+
let toAdd = 0
44+
for (const day of parsedMoods[now.getFullYear()][now.getMonth()]) {
45+
if (day.date - 1 == i) {
46+
toAdd = day.mood
47+
}
48+
}
49+
resArr.push(toAdd)
50+
}
51+
52+
53+
let res = "";
54+
for (const day of resArr) {
55+
let val = ""
56+
switch (day) {
57+
case 1:
58+
val = `\x1b[38;5;88m${bars.full}\x1b[0m`
59+
break;
60+
case 2:
61+
val = `\x1b[38;5;166m${bars.full}\x1b[0m`
62+
break;
63+
case 3:
64+
val = `\x1b[38;5;214m${bars.full}\x1b[0m`
65+
break;
66+
case 4:
67+
val = `\x1b[38;5;70m${bars.full}\x1b[0m`
68+
break;
69+
case 5:
70+
val = `\x1b[38;5;46m${bars.full}\x1b[0m`
71+
break;
72+
73+
default:
74+
val = `${bars.empty}`
75+
break;
76+
}
77+
res += val
78+
}
79+
80+
81+
console.log(res)
82+
83+
function daysInMonth(month, year) {
84+
return month <= 6
85+
? (month % 2 == 0 ? 31 : month == 1 ? isLeapYear(year) ? 29 : 28 : 30)
86+
: (month % 2 == 0 ? 30 : 31)
87+
}
88+
89+
function isLeapYear(year) {
90+
return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
91+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/usr/bin/env node
2+
3+
// Dependency: This script requires Nodejs.
4+
// Install Node: https://nodejs.org/en/download/
5+
6+
// Required parameters:
7+
// @raycast.schemaVersion 1
8+
// @raycast.title Display Mood Year
9+
// @raycast.mode fullOutput
10+
// @raycast.packageName Dashboard
11+
//
12+
// Optional parameters:
13+
// @raycast.icon ☕️
14+
// @raycast.argument1 { "type": "text", "placeholder": "Year", "optional": true}
15+
16+
// Documentation:
17+
// @raycast.description Displays year mood table
18+
// @raycast.author Federico Miraglia
19+
// @raycast.authorURL https://github.com/Mitra98t
20+
21+
22+
const { exec } = require('child_process')
23+
const fs = require("fs")
24+
const homedir = require('os').homedir();
25+
const filePath = `${homedir}/.moodTable.json`
26+
const monthNames = ["January", "February", "March", "April", "May", "June",
27+
"July", "August", "September", "October", "November", "December"
28+
];
29+
30+
if (!fs.existsSync(filePath)) {
31+
exec(`echo '{}' > ${filePath}`)
32+
}
33+
34+
let json = fs.readFileSync(filePath)
35+
let parsedMoods = JSON.parse(json)
36+
let now = new Date()
37+
let yearVal = Number(process.argv.slice(2)[0])
38+
let bars = { full: "▓", empty: "░" }
39+
40+
if (parsedMoods[now.getFullYear()] == null) {
41+
parsedMoods[now.getFullYear()] = [[], [], [], [], [], [], [], [], [], [], [], []]
42+
fs.writeFileSync(filePath, JSON.stringify(parsedMoods))
43+
}
44+
45+
let nowYear = yearVal && yearVal > 0 ? yearVal : now.getFullYear()
46+
if (parsedMoods[nowYear] == null) {
47+
console.log("Empty year!")
48+
return
49+
}
50+
let resArr = [];
51+
// * Mese parte da 0 (ottimo per index)
52+
for (const month in parsedMoods[nowYear]) {
53+
resArr.push([]);
54+
for (let i = 0; i < daysInMonth(month, nowYear); i++) {
55+
let toAdd = 0
56+
let dayIndex = parsedMoods[nowYear][month].findIndex(d => d.date == i + 1)
57+
if (dayIndex != -1)
58+
toAdd = parsedMoods[nowYear][month][dayIndex].mood
59+
resArr[month].push(toAdd)
60+
}
61+
}
62+
63+
let res = "";
64+
for (const month in resArr) {
65+
res += `${monthNames[month]}\n`
66+
for (const day of resArr[month]) {
67+
let val = ""
68+
69+
switch (day) {
70+
case 1:
71+
val = `\x1b[38;5;88m${bars.full}\x1b[0m`
72+
break;
73+
case 2:
74+
val = `\x1b[38;5;166m${bars.full}\x1b[0m`
75+
break;
76+
case 3:
77+
val = `\x1b[38;5;214m${bars.full}\x1b[0m`
78+
break;
79+
case 4:
80+
val = `\x1b[38;5;70m${bars.full}\x1b[0m`
81+
break;
82+
case 5:
83+
val = `\x1b[38;5;46m${bars.full}\x1b[0m`
84+
break;
85+
86+
default:
87+
val = `${bars.empty}`
88+
break;
89+
}
90+
res += val
91+
}
92+
if (month != 11)
93+
res += `\n`
94+
}
95+
96+
console.log(res)
97+
98+
function daysInMonth(month, year) {
99+
return month <= 6
100+
? (month % 2 == 0 ? 31 : month == 1 ? isLeapYear(year) ? 29 : 28 : 30)
101+
: (month % 2 == 0 ? 30 : 31)
102+
}
103+
104+
function isLeapYear(year) {
105+
return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
106+
}

0 commit comments

Comments
 (0)