-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rb
executable file
·61 lines (46 loc) · 1.39 KB
/
build.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
#!/usr/bin/env ruby
require 'tinder'
require 'active_support/core_ext'
require 'chronic'
# expects a participant's standup report starting with "Yesterday:" or "Friday:"
begin
campfire = Tinder::Campfire.new 'yourdomain', :username => 'youruname', :password => 'yourpwd'
rescue
raise "fix the script first to use your Campfire credentials"
end
room_name = ARGV[0]
raise "please pass in the exact room name - ./build.rb <roomname>" if room_name.blank?
puts "Name: "
name = $stdin.gets.chomp
raise "please supply a name" if name.blank?
puts "Start Date: "
date1 = $stdin.gets.chomp
puts "End Date: "
date2 = $stdin.gets.chomp
d1 = Chronic.parse(date1)
d2 = Chronic.parse(date2)
if !(d1&&d2) || (d1>d2)
raise "please supply a valid date range"
end
d1,d2=d1.to_date,d2.to_date
class String
def starts_with?(str)
str = str.to_str
head = self[0, str.length]
head == str
end
end
def messages_for(messages, username)
messages.reject {|m| !m.user.name.upcase.include?(username) rescue nil}.reject {|m| m.type!="TextMessage"}
end
room = campfire.find_room_by_name(room_name)
puts "Standup Report for #{name} from #{d1} to #{d2}"
$d = d1
while $d <= d2 do
puts $d.to_s(:long)
messages = room.transcript($d)
messages_for(messages,name.upcase).select{|m| m.body.upcase.starts_with?("YESTERDAY:")||m.body.upcase.starts_with?("FRIDAY:") }.each do |m|
puts m.body
end
$d +=1
end