-
Notifications
You must be signed in to change notification settings - Fork 5
/
fill_dummy_data.rb
39 lines (35 loc) · 1.12 KB
/
fill_dummy_data.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
require 'rubygems'
require 'json'
require 'csv'
require 'redis'
r = Redis.new
r.flushdb
message = {
:id => 1,
:unread => 1,
:from => 'Vladimir Kolesnikov <[email protected]>',
:to => '[email protected]',
:subject => 'Hello World!',
:recieved => 1270178691,
:attachments => 0
}
r.rpush 'mailbox:INBOX:messages', 1
r.set 'message:1', message.to_json
r.set 'message:1:body', File.read('dummy/message.txt')
content = CSV.parse(File.read('dummy/messages.csv'), RUBY_VERSION.match(/1\.8/) ? '|' : {:col_sep => '|'}).sort {|b, a| a[3] <=> b[3] }
content.each_with_index do |row, i|
id = i + 2
message = {
:id => id,
:unread => rand(10)>8 ? 1 : 0,
:from => row[5] == 'SENT' ? '[email protected]' : "#{row[1]} <#{row[2]}>",
:to => row[5] != 'SENT' ? '[email protected]' : "#{row[1]} <#{row[2]}>",
:subject => row[3],
:recieved => row[4].to_i,
:attachments => rand(10) > 8 ? rand(3) : 0
}
r.rpush "mailbox:#{row[5]}:messages", id
r.incr "mailbox:#{row[5]}:unread" if message[:unread] == 1
r.set "message:#{id}", message.to_json
r.set "message:#{id}:body", `lorem #{rand(5)+1} paragraphs`
end