empyrean 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,441 @@
1
+ <%#-*- coding: utf-8 -*-%>
2
+ <%
3
+ table_width = 710
4
+
5
+ def _generate_colour(count, position)
6
+ table_colour_start = 'babadc'
7
+ table_colour_end = 'cccccc'
8
+
9
+ start_red = table_colour_start.match(/([0-9A-Fa-f]{2}).{4}/)[1].to_i(16)
10
+ start_green = table_colour_start.match(/.{2}([0-9A-Fa-f]{2}).{2}/)[1].to_i(16)
11
+ start_blue = table_colour_start.match(/.{4}([0-9A-Fa-f]{2})/)[1].to_i(16)
12
+ end_red = table_colour_end.match(/([0-9A-Fa-f]{2}).{4}/)[1].to_i(16)
13
+ end_green = table_colour_end.match(/.{2}([0-9A-Fa-f]{2}).{2}/)[1].to_i(16)
14
+ end_blue = table_colour_end.match(/.{4}([0-9A-Fa-f]{2})/)[1].to_i(16)
15
+
16
+ blue = sprintf "%0.2x", ((((end_blue - start_blue) / count.to_f) * + position) + start_blue).abs
17
+ green = sprintf "%0.2x", ((((end_green - start_green) / count.to_f) * + position) + start_green).abs
18
+ red = sprintf "%0.2x", ((((end_red - start_red) / count.to_f) * + position) + start_red).abs
19
+
20
+ "##{red}#{green}#{blue}"
21
+ end
22
+
23
+ def _colour(time)
24
+ case time
25
+ when (0..5) then "blue"
26
+ when (6..11) then "green"
27
+ when (12..17) then "yellow"
28
+ when (18..23) then "red"
29
+ end
30
+ end
31
+
32
+ table_colours_mentions = []
33
+ table_colours_clients = []
34
+ table_colours_hashtags = []
35
+ table_colours_smileys = []
36
+
37
+ (0...@config[:mentions][:top]).each do |i|
38
+ table_colours_mentions << _generate_colour(@config[:mentions][:top], i)
39
+ end
40
+ (0...@config[:clients][:top]).each do |i|
41
+ table_colours_clients << _generate_colour(@config[:clients][:top], i)
42
+ end
43
+ (0...@config[:hashtags][:top]).each do |i|
44
+ table_colours_hashtags << _generate_colour(@config[:hashtags][:top], i)
45
+ end
46
+ (0...@config[:smileys][:top]).each do |i|
47
+ table_colours_smileys << _generate_colour(@config[:smileys][:top], i)
48
+ end
49
+ %>
50
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
51
+ <html>
52
+ <head>
53
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
54
+ <title>Twitter Stats</title>
55
+ <style type="text/css" title="default">
56
+ a {
57
+ text-decoration: none;
58
+ }
59
+ a:link {
60
+ color: #0b407a;
61
+ }
62
+ a:visited {
63
+ color: #0b407a;
64
+ }
65
+
66
+ a:hover {
67
+ text-decoration: underline;
68
+ color: #0b407a;
69
+ }
70
+
71
+ a.background {
72
+ text-decoration: none;
73
+ }
74
+
75
+ a.background:link {
76
+ color: #0b407a;
77
+ }
78
+
79
+ a.background:visited {
80
+ color: #0b407a;
81
+ }
82
+
83
+ a.background:hover {
84
+ text-decoration: underline;
85
+ color: #0b407a;
86
+ }
87
+
88
+ body {
89
+ background-color: #dedeee;
90
+ font-family: Verdana, Arial, sans-serif;
91
+ font-size: 13px;
92
+ color: black;
93
+ }
94
+
95
+ td {
96
+ font-family: Verdana, Arial, sans-serif;
97
+ font-size: 13px;
98
+ color: black;
99
+ text-align: left;
100
+ }
101
+
102
+ .title {
103
+ font-family: Tahoma, Arial, sans-serif;
104
+ font-size: 16px;
105
+ font-weight: bold;
106
+ }
107
+
108
+ .headtext {
109
+ color: white;
110
+ font-weight: bold;
111
+ text-align: center;
112
+ background-color: #666699;
113
+ }
114
+
115
+ .headlinebg {
116
+ background-color: #000000;
117
+ }
118
+
119
+ .tdtop {
120
+ background-color: #C8C8DD;
121
+ }
122
+
123
+ .hicell {
124
+ background-color: #BABADD;
125
+ }
126
+
127
+ .hicell10 {
128
+ background-color: #BABADD;
129
+ font-size: 10px;
130
+ }
131
+
132
+ .rankc {
133
+ background-color: #CCCCCC;
134
+ }
135
+
136
+ .hirankc {
137
+ background-color: #AAAAAA;
138
+ font-weight: bold;
139
+ }
140
+
141
+ .rankc10 {
142
+ background-color: #CCCCCC;
143
+ font-size: 10px;
144
+ }
145
+
146
+ .rankc10center {
147
+ background-color: #CCCCCC;
148
+ font-size: 10px;
149
+ text-align: center;
150
+ }
151
+
152
+ .hirankc10center {
153
+ background-color: #AAAAAA;
154
+ font-weight: bold;
155
+ font-size: 10px;
156
+ text-align: center;
157
+ }
158
+
159
+ .small {
160
+ font-family: Verdana, Arial, sans-serif;
161
+ font-size: 10px;
162
+ }
163
+
164
+
165
+ .asmall {
166
+ font-family: "Arial narrow", Arial, sans-serif;
167
+ font-size: 10px;
168
+ color: black;
169
+ text-align: center;
170
+ }
171
+
172
+ .blue-v {
173
+ display: inline-block;
174
+ margin: auto;
175
+ width: 15px;
176
+ background: #929ded;
177
+ background: -moz-linear-gradient(left, #929ded 0%, #0629ad 100%);
178
+ background: -webkit-gradient(linear, left top, right top, color-stop(0%,#929ded), color-stop(100%,#0629ad));
179
+ background: -webkit-linear-gradient(left, #929ded 0%,#0629ad 100%);
180
+ background: -o-linear-gradient(left, #929ded 0%,#0629ad 100%);
181
+ background: -ms-linear-gradient(left, #929ded 0%,#0629ad 100%);
182
+ background: linear-gradient(to right, #929ded 0%,#0629ad 100%);
183
+ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#929ded', endColorstr='#0629ad',GradientType=1 );
184
+ }
185
+ .green-v {
186
+ display: inline-block;
187
+ margin: auto;
188
+ width: 15px;
189
+ background: #bded92;
190
+ background: -moz-linear-gradient(left, #bded92 0%, #10ae05 100%);
191
+ background: -webkit-gradient(linear, left top, right top, color-stop(0%,#bded92), color-stop(100%,#10ae05));
192
+ background: -webkit-linear-gradient(left, #bded92 0%,#10ae05 100%);
193
+ background: -o-linear-gradient(left, #bded92 0%,#10ae05 100%);
194
+ background: -ms-linear-gradient(left, #bded92 0%,#10ae05 100%);
195
+ background: linear-gradient(to right, #bded92 0%,#10ae05 100%);
196
+ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#bded92', endColorstr='#10ae05',GradientType=1 );
197
+ }
198
+ .yellow-v {
199
+ display: inline-block;
200
+ margin: auto;
201
+ width: 15px;
202
+ background: #ede192;
203
+ background: -moz-linear-gradient(left, #ede192 0%, #b6b309 100%);
204
+ background: -webkit-gradient(linear, left top, right top, color-stop(0%,#ede192), color-stop(100%,#b6b309));
205
+ background: -webkit-linear-gradient(left, #ede192 0%,#b6b309 100%);
206
+ background: -o-linear-gradient(left, #ede192 0%,#b6b309 100%);
207
+ background: -ms-linear-gradient(left, #ede192 0%,#b6b309 100%);
208
+ background: linear-gradient(to right, #ede192 0%,#b6b309 100%);
209
+ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ede192', endColorstr='#b6b309',GradientType=1 );
210
+ }
211
+ .red-v {
212
+ display: inline-block;
213
+ margin: auto;
214
+ width: 15px;
215
+ background: #ed9292;
216
+ background: -moz-linear-gradient(left, #ed9292 0%, #ad0506 100%);
217
+ background: -webkit-gradient(linear, left top, right top, color-stop(0%,#ed9292), color-stop(100%,#ad0506));
218
+ background: -webkit-linear-gradient(left, #ed9292 0%,#ad0506 100%);
219
+ background: -o-linear-gradient(left, #ed9292 0%,#ad0506 100%);
220
+ background: -ms-linear-gradient(left, #ed9292 0%,#ad0506 100%);
221
+ background: linear-gradient(to right, #ed9292 0%,#ad0506 100%);
222
+ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ed9292', endColorstr='#ad0506',GradientType=1 );
223
+ }
224
+ </style>
225
+ </head>
226
+ <body>
227
+ <div align="center">
228
+
229
+ <span class="title">Twitter Stats</span><br />
230
+ <br />
231
+ Statistics generated on <%= Time.now.strftime("%A %d %B %Y - %T") %><br />
232
+ Total number of tweets: <%= counters[:tweets] %> (<%= counters[:retweets_percentage] %>% retweets)
233
+ <br /><br />
234
+
235
+ <table width="<%= table_width %>" cellpadding="1" cellspacing="0" border="0">
236
+ <tr>
237
+ <td class="headlinebg">
238
+ <table width="100%" cellpadding="2" cellspacing="0" border="0">
239
+ <tr>
240
+ <td class="headtext">Most active times</td>
241
+ </tr>
242
+ </table>
243
+ </td>
244
+ </tr>
245
+ </table>
246
+
247
+ <table border="0">
248
+ <tr>
249
+ <% times_of_day.each_with_index do |time, index| %>
250
+ <td align="center" valign="bottom" class="asmall"><%= time[:percentage] %>%<% if time[:size] > 0 %><br /><div class="<%= _colour(index) %>-v" style="height: <%= time[:size] %>px;" alt="<%= time[:count] %>" title="<%= time[:count] %>"/><% end %></td>
251
+ <% end %>
252
+ </tr><tr>
253
+ <% times_of_day.each_with_index do |time, index| %>
254
+ <td class="<% if time[:max] %>hi<% end %>rankc10center" align="center"><%= index %></td>
255
+ <% end %>
256
+ </tr></table><br />
257
+ <br />
258
+
259
+ <% if mentions[:enabled] %>
260
+ <table width="<%= table_width %>" cellpadding="1" cellspacing="0" border="0">
261
+ <tr>
262
+ <td class="headlinebg">
263
+ <table width="100%" cellpadding="2" cellspacing="0" border="0">
264
+ <tr>
265
+ <td class="headtext">Most mentioned users</td>
266
+ </tr>
267
+ </table>
268
+ </td>
269
+ </tr>
270
+ </table>
271
+
272
+ <table border="0" width="<%= table_width + 4 %>">
273
+ <tr>
274
+ <td>&nbsp;</td>
275
+ <td class="tdtop"><b>User</b></td>
276
+ <td class="tdtop"><b>How often?</b></td>
277
+ <td class="tdtop"><b>Random quote</b></td>
278
+ </tr>
279
+ <% mentions[:top].each_with_index do |user, index| %>
280
+ <tr>
281
+ <td class="<% if index == 0 %>hi<% end %>rankc" align="left"><%= index + 1 %></td>
282
+ <td style="background-color: <%= table_colours_mentions[index] %>"><span><a href="https://twitter.com/<%= user[:name] %>">@<%= user[:name] %></a></span></td>
283
+ <td style="background-color: <%= table_colours_mentions[index] %>"><%= user[:count] %></td>
284
+ <td style="background-color: <%= table_colours_mentions[index] %>">"<%= user[:example][:text] %>" <a href="https://twitter.com/statuses/<%= user[:example][:id] %>">&rarr;</a></td>
285
+ </tr>
286
+ <% end %>
287
+ </table><br />
288
+ <br />
289
+ <% if mentions[:nottop].length > 0 %><b><i>These didn't make it to the top:</i></b><table><tr>
290
+ <% mentions[:nottop].each_with_index do |user, index| %>
291
+ <td class="rankc10"><span><a href="https://twitter.com/<%= user[:name] %>">@<%= user[:name] %></a> (<%= user[:count] %>)</span></td>
292
+ <% if index % 5 == 4 %>
293
+ </tr>
294
+ <tr>
295
+ <% end %>
296
+ <% end %>
297
+ </tr>
298
+ </table><br />
299
+ <br />
300
+ <% end %>
301
+ <% end %>
302
+ <% if clients[:enabled] %>
303
+ <table width="<%= table_width %>" cellpadding="1" cellspacing="0" border="0">
304
+ <tr>
305
+ <td class="headlinebg">
306
+ <table width="100%" cellpadding="2" cellspacing="0" border="0">
307
+ <tr>
308
+ <td class="headtext">Most used clients</td>
309
+ </tr>
310
+ </table>
311
+ </td>
312
+ </tr>
313
+ </table>
314
+
315
+ <table border="0" width="<%= table_width + 4 %>">
316
+ <tr>
317
+ <td>&nbsp;</td>
318
+ <td class="tdtop"><b>Client</b></td>
319
+ <td class="tdtop"><b>Times used</b></td>
320
+ <td class="tdtop"><b>Percentage</b></td>
321
+ </tr>
322
+ <% clients[:top].each_with_index do |client, index| %>
323
+ <tr>
324
+ <td class="<% if index == 0 %>hi<% end %>rankc" align="left"><%= index + 1 %></td>
325
+ <td style="background-color: <%= table_colours_clients[index] %>"><span><a href="<%= client[:url] %>"><%= client[:name] %></a></span></td>
326
+ <td style="background-color: <%= table_colours_clients[index] %>"><%= client[:count] %></td>
327
+ <td style="background-color: <%= table_colours_clients[index] %>"><%= client[:percentage] %>%</td>
328
+ </tr>
329
+ <% end %>
330
+ </table><br />
331
+ <br />
332
+ <% if clients[:nottop].length > 0 %><b><i>These didn't make it to the top:</i></b><table><tr>
333
+ <% clients[:nottop].each_with_index do |client, index| %>
334
+ <td class="rankc10"><span><a href="<%= client[:url] %>"><%= client[:name] %></a> (<%= client[:count] %>)</span></td>
335
+ <% if index % 5 == 4 %>
336
+ </tr>
337
+ <tr>
338
+ <% end %>
339
+ <% end %>
340
+ </tr>
341
+ </table><br />
342
+ <br />
343
+ <% end %>
344
+ <% end %>
345
+
346
+ <% if smileys[:enabled] %>
347
+ <table width="<%= table_width %>" cellpadding="1" cellspacing="0" border="0">
348
+ <tr>
349
+ <td class="headlinebg">
350
+ <table width="100%" cellpadding="2" cellspacing="0" border="0">
351
+ <tr>
352
+ <td class="headtext">Most used smileys :^)</td>
353
+ </tr>
354
+ </table>
355
+ </td>
356
+ </tr>
357
+ </table>
358
+
359
+ <table border="0" width="<%= table_width + 4 %>">
360
+ <tr>
361
+ <td>&nbsp;</td>
362
+ <td class="tdtop"><b>Smiley</b></td>
363
+ <td class="tdtop"><b>Times used</b></td>
364
+ <td class="tdtop"><b>Random quote</b></td>
365
+ </tr>
366
+ <% smileys[:top].each_with_index do |smiley, index| %>
367
+ <tr>
368
+ <td class="<% if index == 0 %>hi<% end %>rankc" align="left"><%= index + 1 %></td>
369
+ <td style="background-color: <%= table_colours_smileys[index] %>"><span><%= smiley[:smiley] %></span></td>
370
+ <td style="background-color: <%= table_colours_smileys[index] %>"><%= smiley[:count] %></td>
371
+ <td style="background-color: <%= table_colours_smileys[index] %>">"<%= smiley[:example][:text] %>" <a href="https://twitter.com/statuses/<%= smiley[:example][:id] %>">&rarr;</a></td>
372
+ </tr>
373
+ <% end %>
374
+ </table><br />
375
+ <br />
376
+ <% if smileys[:nottop].length > 0 %><b><i>These didn't make it to the top ;_;</i></b><table><tr>
377
+ <% smileys[:nottop].each_with_index do |smiley, index| %>
378
+ <td class="rankc10"><span><%= smiley[:smiley] %> (<%= smiley[:count] %>)</span></td>
379
+ <% if index % 5 == 4 %>
380
+ </tr>
381
+ <tr>
382
+ <% end %>
383
+ <% end %>
384
+ </tr>
385
+ </table><br />
386
+ <br />
387
+ <% end %>
388
+ <% end %>
389
+
390
+ <% if hashtags[:enabled] %>
391
+ <table width="<%= table_width %>" cellpadding="1" cellspacing="0" border="0">
392
+ <tr>
393
+ <td class="headlinebg">
394
+ <table width="100%" cellpadding="2" cellspacing="0" border="0">
395
+ <tr>
396
+ <td class="headtext">Most used hashtags</td>
397
+ </tr>
398
+ </table>
399
+ </td>
400
+ </tr>
401
+ </table>
402
+
403
+ <table border="0" width="<%= table_width + 4 %>">
404
+ <tr>
405
+ <td>&nbsp;</td>
406
+ <td class="tdtop"><b>Hashtag</b></td>
407
+ <td class="tdtop"><b>Times used</b></td>
408
+ <td class="tdtop"><b>Random quote</b></td>
409
+ </tr>
410
+ <% hashtags[:top].each_with_index do |hashtag, index| %>
411
+ <tr>
412
+ <td class="<% if index == 0 %>hi<% end %>rankc" align="left"><%= index + 1 %></td>
413
+ <td style="background-color: <%= table_colours_hashtags[index] %>"><span><a href="https://twitter.com/search?q=%23<%= hashtag[:hashtag] %>">#<%= hashtag[:hashtag] %></a></span></td>
414
+ <td style="background-color: <%= table_colours_hashtags[index] %>"><%= hashtag[:count] %></td>
415
+ <td style="background-color: <%= table_colours_hashtags[index] %>">"<%= hashtag[:example][:text] %>" <a href="https://twitter.com/statuses/<%= hashtag[:example][:id] %>">&rarr;</a></td>
416
+ </tr>
417
+ <% end %>
418
+ </table><br />
419
+ <br />
420
+ <% if hashtags[:nottop].length > 0 %><b><i>These didn't make it to the top:</i></b><table><tr>
421
+ <% hashtags[:nottop].each_with_index do |hashtag, index| %>
422
+ <td class="rankc10"><span><a href="https://twitter.com/search?q=%23<%= hashtag[:hashtag] %>">#<%= hashtag[:hashtag] %></a> (<%= hashtag[:count] %>)</span></td>
423
+ <% if index % 5 == 4 %>
424
+ </tr>
425
+ <tr>
426
+ <% end %>
427
+ <% end %>
428
+ </tr>
429
+ </table><br />
430
+ <br />
431
+ <% end %>
432
+ <% end %>
433
+
434
+ <span class="small">
435
+ Stats generated by <a href="https://github.com/Leafcat/Empyrean" class="background"><%= Empyrean::VERSION_STR %></a><br />
436
+ Empyrean by <a href="http://leafc.at" class="background">Leafcat</a>
437
+ </span>
438
+ </div>
439
+ </body>
440
+ </html>
441
+
@@ -0,0 +1,50 @@
1
+ # tweetloader.rb - loads tweet files
2
+ #
3
+ # This file is part of Empyrean
4
+ # Copyright (C) 2015 nilsding, pixeldesu
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ require 'json'
20
+ require 'empyrean/defaults'
21
+
22
+ module Empyrean
23
+ class TweetLoader
24
+
25
+ ##
26
+ # Returns a list of file names in a directory.
27
+ def self.read_directory(directory)
28
+ files = []
29
+ entries = Dir.entries(directory)
30
+ entries.each do |e|
31
+ if e =~ /^\d{4}_\d{2}\.js$/
32
+ files << File.expand_path(e, directory)
33
+ end
34
+ end
35
+ files.sort
36
+ end
37
+
38
+ ##
39
+ # Reads a tweet file
40
+ def self.read_file(file)
41
+ puts "reading file #{file}"
42
+ fh = File.open(file)
43
+ contents = fh.read
44
+ contents.sub! /Grailbird\.data\.tweets_\d{4}_\d{2} =/, '' # get rid of the JS assignment
45
+ json_tweets = JSON.parse(contents)
46
+ end
47
+ end
48
+ end
49
+
50
+ # kate: indent-width 2