Skip to content

Commit 3017ce9

Browse files
author
Mike McCrary
committed
Add restore script
1 parent 79d202a commit 3017ce9

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

restore.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
require 'json'
2+
require 'redis'
3+
4+
redis = Redis.new()
5+
# redis = Redis.new(:url => "redis://redistogo:<pw>@<host>:<port>")
6+
7+
file = File.read('pong.json')
8+
data = JSON.parse(file)
9+
10+
11+
data.each do |item|
12+
hash = item[1]
13+
key = hash['key']
14+
type = hash['type']
15+
16+
if type == 'hash'
17+
hash['value'].each do |val|
18+
hkey = val[0]
19+
hval = val[1]
20+
21+
redis.hset(key, hkey, hval)
22+
puts "HSET #{key} #{hkey} #{hval}"
23+
end
24+
elsif type == 'zset'
25+
hash['value'].each do |val|
26+
zkey = val[0]
27+
score = val[1]
28+
29+
redis.zadd(key, score, zkey)
30+
puts "ZADD #{key} #{score} #{zkey}"
31+
end
32+
end
33+
end
34+
35+
puts "Done."
36+

scripts/pingpong.coffee

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,18 @@ show_head_to_head = (msg, winner, loser) ->
111111
msg.send "Head-to-head record: #{replies[0] or 0} - #{replies[1] or 0}"
112112

113113
store_singles_results = (msg) ->
114-
msg.send "Match recorded."
115114
winner = msg.match[1]
116115
loser = msg.match[2]
117116

118117
give_win(winner)
119118
give_loss(loser)
120119

121120
give_head_to_head_win(winner, loser)
121+
msg.send "Match recorded."
122+
122123
update_ratings_singles(winner, loser)
123124

124125
store_doubles_results = (msg) ->
125-
msg.send "Match recorded."
126126
winner1 = msg.match[1]
127127
winner2 = msg.match[2]
128128
loser1 = msg.match[3]
@@ -137,6 +137,8 @@ store_doubles_results = (msg) ->
137137
losers = form_team_name(loser1, loser2)
138138

139139
give_head_to_head_win(winners, losers)
140+
msg.send "Match recorded."
141+
140142
update_ratings_doubles(winners, losers)
141143

142144
give_head_to_head_win = (winner, loser) ->

0 commit comments

Comments
 (0)