-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstats.rb
executable file
·69 lines (58 loc) · 1.29 KB
/
stats.rb
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
# require 'net/http'
# require 'date'
require 'open-uri'
require 'xmlsimple'
require 'redis'
require 'json'
redis = Redis.new
enable_padding = false
def pad(num, content)
pad_length = num - content.length
for i in 1..pad_length
content += ' '
end
content
end
if enable_padding
header = pad(40, "Artist") + pad(60, "Song") + pad(15, "Station") + "Plays"
else
header = ("Artist|Song|Station|Plays")
end
puts header
if enable_padding
header = ''
for i in 1..125
header += '-'
end
puts header
end
redis.keys('song:*').each do |key|
begin
t = JSON.parse(redis.get(key))
rescue
t = JSON.parse(redis.get(key).gsub(/=>/, ':'))
redis.set(key, t.to_json)
puts key
end
line = t["artist"]
pad = 50 - t["artist"].length
for i in 1..pad
line = line + ' '
end
line = line + t["song"]
pad = 50 - t["song"].length
for i in 1..pad
line = line + ' '
end
line = line + '|' + t["station"]
pad = 20 - t["station"].length
for i in 1..pad
line = line + ' '
end
line = line + '|' + t["plays"].to_s
if enable_padding
puts pad(40, t["artist"]) + pad(60, t["song"]) + pad(15, t["station"]) + t["plays"].to_s
else
puts t["artist"] + '|' + t["song"] + '|' + t["station"] + '|' + t["plays"].to_s
end
end