-
Notifications
You must be signed in to change notification settings - Fork 3
/
MMM-Astro.js
146 lines (120 loc) · 4.48 KB
/
MMM-Astro.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
/* Magic Mirror
* Module: MMM-Astro
*
* By cowboysdude
*
*/
Module.register('MMM-Astro', {
// Module config defaults.
defaults: {
updateInterval: 60 * 60 * 1000, // every 10 minutes
animationSpeed: 10,
initialLoadDelay: 875, // 0 seconds delay
retryDelay: 1500,
sign: '',
maxWidth: '90%',
fadeSpeed: 7,
iconset: '1',
extend: true,
debug: false,
starsign: {
'leo': 'Leo',
'capricorn': 'Capricorn',
'aquarius': 'Aquarius',
'pisces': 'Pisces',
'aries': 'Aries',
'taurus': 'Taurus',
'gemini': 'Gemini',
'cancer': 'Cancer',
'virgo': 'Virgo',
'libra': 'Libra',
'scorpio': 'Scorpio',
'sagittarius': 'Sagittarius',
'ophiuchus': 'Ophiuchus',
},
},
// Define required scripts.
getScripts: function() {
return ['moment.js'];
},
getStyles: function() {
return ['MMM-Astro.css'];
},
// Define start sequence.
start: function() {
Log.info('Starting module: ' + this.name);
this.sendSocketNotification('CONFIG', this.config);
// Set locale.
this.today = '';
this.scheduleUpdate();
},
getDom: function() {
let debug = this.config.debug;
if (debug !== false)
{
console.log('From Main.js ~~ Sign: '+this.config.sign+' Icon set: '+this.config.iconset+' Show Extended: '+this.config.extend);
console.log('All Data: Horo: '+this.horo+' <br>Extended: '+this.fortune+' <br>Numbers: '+this.lottery.numbers);
}
var today = this.astro;
var lottery = this.lottery;
console.log(lottery);
console.log(lottery);
var starSign = this.config.starsign[this.config.sign];
var wrapper = document.createElement('div');
wrapper.classList.add('wrap');
if (!this.loaded) {
wrapper.innerHTML = '<img src=modules/MMM-Astro/icons/loader.gif>';
return wrapper;
}
var ssign = document.createElement('div');
ssign.classList.add('tops','small','bright');
ssign.innerHTML = '<img class=mains src = modules/MMM-Astro/icons/' + this.config.iconset + '/' + starSign + '.svg> ' + starSign;
wrapper.appendChild(ssign);
var titless = document.createElement('div');
titless.classList.add('xsmall', 'bright','wrapdiv');
titless.style.float = 'left';
titless.innerHTML = 'Horoscope for ' + today.current_date;
wrapper.appendChild(titless);
var afterWithout = this.horo.substr(0, this.horo.lastIndexOf(","));
var scope = document.createElement('div');
scope.classList.add('xsmall', 'bright','wrapdiv');
scope.innerHTML = '<br><br>' + afterWithout+".";
wrapper.appendChild(scope);
if (this.config.extend != false){
var tom = document.createElement('div');
tom.classList.add('xsmall','bright','wrapdiv');
tom.innerHTML = 'Extended :<br>' + this.fortune;
wrapper.appendChild(tom);
}
var des = document.createElement('div');
des.classList.add('xsmall','bright','wrapdiv');
des.innerHTML = 'Your Mood today is: ' + today.mood + '<br> Your Color today is: ' + today.color + '<br>Today you are compatable with: ' + today.compatibility + '<br><br>Your lucky numbers are: <br>' + lottery;
wrapper.appendChild(des);
return wrapper;
},
processAstro: function(data) {
this.loaded = true;
this.today = data.Today;
this.astro = data.today;
this.lottery = data.lottery;
this.horo = data.dscope.horoscope;
this.fortune = data.fortune;
console.log(this.lottery);
},
scheduleUpdate: function() {
setInterval(() => {
this.getAstro();
}, this.config.updateInterval);
this.getAstro(this.config.initialLoadDelay);
},
getAstro: function() {
this.sendSocketNotification('GET_ASTRO');
},
socketNotificationReceived: function(notification, payload) {
if (notification === 'ASTRO_RESULTS') {
this.processAstro(payload);
this.updateDom(this.config.animationSpeed);
}
this.updateDom(this.config.initialLoadDelay);
},
});