-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
145 lines (124 loc) · 2.97 KB
/
index.js
File metadata and controls
145 lines (124 loc) · 2.97 KB
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
var config = require(__dirname + '/config.json')
const request = require('request')
const reqp = require('request-promise')
function formatURI(uri) {
var eventname = uri.split('/')
return 'https://api.ftcscores.com/api/events/' + eventname[eventname.length - 1]
}
/*reqp(formatURI(config.target))
.then((htmlString) => {
console.log(find5190Rank(JSON.parse(htmlString)).name)
})*/
var wait =
ms => new Promise(
r => setTimeout(r, ms)
);
var repeat =
(ms, func) => new Promise(
r => (
setInterval(func, ms),
wait(ms).then(r)
)
);
var screenRefreshes = 0;
// 2 * 60 *
repeat(2 * 60 * 1000, () => {
reqp(formatURI(config.target))
.then((htmlString) => {
var blessed = require('blessed');
var ranks = JSON.parse(htmlString).rankings;
var info = JSON.parse(htmlString)
// Create a screen object.
var screen = blessed.screen({
smartCSR: true
});
screen.title = 'FTCScoresCurses';
// Create a box perfectly centered horizontally and vertically.
var top5 = "";
for (var i = 0; i < config.show; i++) {
top5 += `{bold}${i + 1}. ${ranks[i].number} - ${ranks[i].name}{/bold}\n`
}
var bigTitle = blessed.box({
top: '0',
left: 'center',
width: '100%',
height: '20%',
content: 'Technoramic 5190',
align: 'center',
valign: 'center',
tags: true,
style: {
fg: 'white',
bg: 'red'
}
});
var box = blessed.box({
top: 'center',
left: 'center',
width: '45%',
height: '50%',
content: `{bold}Top ${config.show} Teams{/bold}\n${top5}`,
tags: true,
style: {
fg: 'white',
bg: 'blue'
}
});
var eventInfoPane = blessed.box({
top: 'center',
right: '0',
width: '25%',
height: '50%',
content: '{bold}Event Info{/bold}\n' + `Name: ${info.shortName}\nType: ${info.type}\nLocation: ${info.location}\nDivision: ${info.subtitle}\nStart: ${Date(info.startDate)}\nEnd: ${Date(info.endDate)}`,
tags: true,
style: {
fg: 'white',
bg: 'green'
}
});
var teamInfo = blessed.box({
top: 'center',
left: '0',
width: '25%',
height: '50%',
content: '{bold}5190 Info{/bold}\nLocation: Saint Louis, MO\nSchool: MICDS',
tags: true,
style: {
fg: 'white',
bg: 'yellow'
}
});
var diagnostics = blessed.text({
bottom: '0',
left: 'center',
width: '100%',
height: '20%',
content: `Diagnostics\nScreen Refreshes: ${screenRefreshes.toString()}`,
align: 'center',
valign: 'center',
tags: true,
style: {
fg: 'white',
bg: 'black'
}
});
// Append our box to the screen.
screen.append(box);
screen.append(eventInfoPane);
screen.append(teamInfo);
screen.append(bigTitle);
screen.append(diagnostics);
// Quit on Escape, q, or Control-C.
screen.key(['escape', 'q', 'C-c'], function(ch, key) {
return process.exit(0);
});
// Focus our element.
box.focus();
// Render the screen.
screen.render();
screenRefreshes += 1;
})
.catch((error) => {
console.log(error);
});
});