Skip to content

Instantly share code, notes, and snippets.

@gfontenot
Created July 30, 2012 15:35
Show Gist options
  • Save gfontenot/3207863 to your computer and use it in GitHub Desktop.
Save gfontenot/3207863 to your computer and use it in GitHub Desktop.
QC notification script for WTV
#!/usr/bin/env ruby
#
# qc_reminder
#
# Created by Gordon Fontenot for WheelsTV
#
# Scans a set of folders used for Quality Control,
# and if it finds scripts or videos, emails the employee responsible
# for that stage of the QC process to let them know they
# have scripts or videos ready to QC.
require 'rubygems'
require 'pony'
require 'tinder'
@email_array = {"Gordon" => "[email protected]",
"Leo" => "[email protected]",
"Kipp" => "[email protected]",
"Ryan" => "[email protected]",
"Collin" => "[email protected]",
"Jim" => "[email protected]",
"Jeff" => "[email protected]",
"Rich" => "[email protected]",
"Jackie" => "[email protected]"}
Pony.options = { :from => "[email protected]", :via => :smtp, :via_options => {
:address => "address",
:port => "25",
:user_name => "username",
:password => "password",
:authentication => :plain,
:domain => "localhost.localdomain",
} }
def user_on_campfire?(user_name)
campfire = Tinder::Campfire.new 'test', :token => 'token'
room = campfire.find_room_by_name "The Office"
room.users.map { |u| u.name.downcase }.include? user_name.downcase
end
def notify_user(person, qc_items)
if user_on_campfire? person
cf_msg_user(person, qc_items)
else
email_user(person, qc_items)
end
end
def email_user(person, qc_items)
subject = "You have items ready for QC"
msg = "Hi #{person},\n\nThis is a friendly notification to let you know that you currently have the following items ready for your QC:\n\n"
qc_items.each do |qc_item|
msg += "#{qc_item[:count]} #{qc_item[:product]} #{qc_item[:type]}s in #{qc_item[:location]}\n"
end
msg += "\nThanks,\nThe Management"
Pony.mail(:to => @email_array[person], :subject => subject, :body => msg)
time_stamp = Time.now.strftime("%D - %r")
puts "#{time_stamp} - Email sent to #{person} - #{qc_items}"
end
def cf_msg_user(person, qc_items)
campfire = Tinder::Campfire.new 'wheelstv', :token => 'b00ffa07d0e3e9ad47ba809ccad4ee34b51e2e44'
room = campfire.find_room_by_name "The Office"
qc_items.each do |qc_item|
room.speak "#{person}: You have #{qc_item[:count]} #{qc_item[:product]} #{qc_item[:type]}s ready for QC (#{qc_item[:location]})"
end
time_stamp = Time.now.strftime("%D - %r")
puts "#{time_stamp} - #{person} Notified via Campfire - #{qc_items}"
end
def qc_items_count(qc_loc)
Dir.entries("#{qc_loc}").delete_if {|file| /^\./.match(file)}.size
end
def check_video_qc
base_dir = "/Volumes/Exported items/"
product_array = { "1onONE" => "Jackie",
"Top200" => "Gordon",
"POV" => "Leo",
"AutoTrader" => "Ryan",
"Lifestyle" => "Gordon"}
qc_array = {"1. Technical" => "Rich",
"2. Creative" => "Jim",
"4. Final Review" => "Gordon"}
product_array.each_pair do |product, editor|
qc_dir = File.join(base_dir, product, "/Latest Batch/QC/")
begin
for box in ["0. Editor Review", "3. Editor Fixes"] do box
count = qc_items_count("#{qc_dir}#{box}")
unless count == 0
@qc_container[editor] << { :product => product,
:count => count,
:location => box.split(". ")[1],
:type => :video }
end
end
qc_array.each_pair do |box, person|
count = qc_items_count("#{qc_dir}#{box}")
unless count == 0
@qc_container[person] << { :product => product,
:count => count,
:location => box.split(". ")[1],
:type => :video }
end
end
rescue Exception => e
puts e
end
end
end
def check_script_qc
base_dir = '/Users/Gordon/Dropbox/WTV Dropbox/Products/'
top200_qc = { "2. QC" => "Rich",
"3. Final Review" => "Jim",
"4. Ready for Production" => "Gordon"}
oneonone_qc = { "2. QC" => "Rich",
"3. Final Review" => "Jim",
"4. Ready for Production" => "Gordon"}
pov_qc = { "2. QC" => "Rich",
"3. Final Review" => "Jim",
"4. Ready for Production" => "Gordon"}
product_hash = { "1onONE" => oneonone_qc,
"Top200" => top200_qc
}
product_hash.each_pair do |product, qc_hash|
qc_dir = File.join(base_dir, product, "#{product} Scripts/")
begin
qc_hash.each_pair do |box, person|
count = qc_items_count("#{qc_dir}#{box}")
unless count == 0
@qc_container[person] << { :product => product,
:count => count,
:location => box.split(". ")[1],
:type => :script }
end
end
rescue Exception => e
puts e
end
end
end
@qc_container = Hash.new { |hash, key| hash[key] = [] }
check_video_qc
check_script_qc
@qc_container.each_pair do |person, qc_items|
notify_user person, qc_items
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment