Skip to content

Commit

Permalink
TwitBase.jrb from chapter 6
Browse files Browse the repository at this point in the history
  • Loading branch information
ndimiduk committed Jun 6, 2012
1 parent 494abf3 commit d2e570f
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions resources/TwitBase.jrb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env hbase shell

def list_users()
users_table = @hbase.table('users', @formatter)
scan = {"COLUMNS" => ['info:user', 'info:name', 'info:email']}
results = {}
users_table.scan(scan) do |row,col|
results[row] ||= {}
m = /^.*info:(.*), t.*value=(.*)$/.match(col)
results[row][m[1]] = m[2] if m
end

results.each do |row,vals|
puts "<User %s, %s, %s>" % [vals['user'], vals['name'], vals['email']]
end
end

def main(args)
if args.length == 0 || args[0] == 'help'
puts <<EOM
TwitBase.jrb action ...
help - print this message and exit
list - list all installed users.
EOM
exit
end

if args[0] == 'list'
list_users
end

exit
end

main(ARGV)

0 comments on commit d2e570f

Please sign in to comment.