-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhalo.js
167 lines (162 loc) · 5.19 KB
/
halo.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
const Notification = require("electron").Notification;
const scraperjs = require("scraperjs");
const path = require("path");
const imagesPath = path.join(__dirname, "images");
const halo = {
showMessage: async () => {
const { emoji, text } = await getTweet();
const notify = new Notification({
title: emoji || "Halo",
body: text,
closeButtonText: "close",
});
notify.show();
},
};
const getTweet = async () => {
const tweets1 = await scrapeTweets("tinycarebot");
const tweets2 = await scrapeTweets("selfcare_bot");
const tweets = [...tweets1, ...tweets2];
const tweetNo = Math.floor(Math.random() * tweets.length);
return tweets[tweetNo];
};
const scrapeTweets = (who) => {
return new Promise((resolve, reject) => {
const uri = "https://twitter.com/" + who;
const scrapeFn = ($) => {
const nodes = $(".js-tweet-text.tweet-text");
return nodes
.map((x, y) => {
const emoji = $(y).find("img").attr("alt");
let text = $(y).text();
text = text.replace(":", "").trim();
text = text.charAt(0).toUpperCase() + text.slice(1);
return { emoji, text };
})
.get();
};
const tweets = scraperjs.StaticScraper.create(uri)
.scrape(scrapeFn)
.then((tweets) => {
resolve(tweets);
})
.catch((err) => {
resolve(TWEETS);
});
});
};
module.exports = halo;
// If there is no internet, Will use hardcoded tweets
const TWEETS = [
{ emoji: "🌃", text: "Take a moment to rest your eyes please" },
{ emoji: "💖", text: "Remember to text a friend please" },
{ emoji: "💧", text: "Take a bit of time to go get a sip of water please" },
{ emoji: "💙", text: "Please ask your friends for help if you need it" },
{ emoji: "❤", text: "Please remember to say hi to your friends" },
{
emoji: "🏔",
text: "Dont forget to rest your eyes and look away from twitter please",
},
{
emoji: "💧",
text: "Remember to take a little bit of time to stay hydrated please",
},
{ emoji: "🌿", text: "Please remember to breathe calmly" },
{ emoji: "🙌", text: "Please remember to wiggle your toes" },
{ emoji: "🍛", text: "Please remember to eat something healthy" },
{ emoji: "🌃", text: "Please remember to give your eyes a break" },
{ emoji: "🚰", text: "Please remember to have a sip of water" },
{ emoji: "🙌🏽", text: "Remember to do a posture check please" },
{
emoji: "💟",
text:
"Remember to take a quick second to send some messages to your friends please",
},
{ emoji: "🌿", text: "Get some fresh air please" },
{
emoji: "🏔",
text:
"Please dont forget to take a quick second to spend some time outside if you can",
},
{
emoji: "🌿",
text: "Dont forget to take a quick break to get some fresh air please",
},
{ emoji: "💟", text: "Please ask for help if you need it" },
{ emoji: "🍃", text: "Please get some fresh air" },
{
emoji: "🎧",
text:
"Remember to take a quick second to listen to some music that helps you feel safe please",
},
{ emoji: "💪", text: "Hey! Life is tough, but so are you!" },
{
emoji: "📋",
text:
"If you have an action plan to manage any conditions you have, please remember to follow it.",
},
{
emoji: "🌄",
text:
"You cannot compare your successes to the apparent achievements of others.",
},
{ emoji: "💨", text: "Don't forget to breathe." },
{
emoji: "💨",
text:
"Is your breathing steady? Maybe try breathing with this gif. http//gph.is/2bComij?tc=1",
},
{
emoji: "📋",
text:
"If work is feeling too overwhelming, break it down into little jobs.",
},
{
emoji: "👍",
text:
"Not sure how to meditate? Maybe download a mindfulness app for your phone!",
},
{
emoji: "⏰",
text:
"Have you been waking up early enough lately? Might be time to adjust your sleep schedule.",
},
{
emoji: "🏡",
text:
"Is it possible to open a window? A breeze might make you feel a little brighter.",
},
{ emoji: "💧", text: "Have at least a little sip of water, yeah?" },
{ emoji: "👍", text: "Just keep going! You're doing really well." },
{ emoji: "👍", text: "Just do your best—it's the best you can do!" },
{ emoji: "💖", text: "Don't be too hard on yourself." },
{ emoji: "🎨", text: "Don't forget to do something creative today." },
{
emoji: "🍰",
text: "It's okay to treat yourself with your favourite food sometimes.",
},
{
emoji: "💕",
text:
"Everybody needs something a little different. Just be in tune with yourself.",
},
{
emoji: "🌲",
text: "Have you been outside recently? Go and take a nice, fresh breath.",
},
{
emoji: "💤",
text:
"How's your sleep schedule looking? Try to head to bed on time tonight, if you can.",
},
{
emoji: "🚶",
text:
"If you have a moment, maybe go for a nice walk (or head outside for some fresh air, however you can).",
},
{
emoji: "🍇",
text: "It's really important that you feed yourself, even a little!",
},
{ emoji: "😀", text: "Make sure you brush your teeth!" },
];