Created
July 6, 2014 05:28
-
-
Save mjstrasser/13d55c3d1ae3417887f5 to your computer and use it in GitHub Desktop.
Pimp it hard: Ruby script to pummel http://pimpmylight.catchpole.net/ a number of times, using random colour choice and random delays between messages.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run Pimp My Light for a while | |
require 'httparty' | |
COLOURS = [:red, :orange, :green] | |
PML_URL = 'http://pimpmylight.catchpole.net/?update=%s' | |
TOTAL = ARGV.length > 0 ? ARGV[0].to_i : 5 | |
COUNTS = { red: 0, orange: 0, green: 0, except: 0 } | |
def pimp(colour) | |
HTTParty.get PML_URL % colour.to_s | |
rescue Exception => e | |
puts "Oops! #{e.message}" | |
COUNTS[:except] += 1 | |
end | |
def pimp_away | |
puts "Pimping #{TOTAL} times" | |
1.upto(TOTAL) do |i| | |
delay = Random.rand(2.5) | |
colour = COLOURS.sample | |
COUNTS[colour] += 1 | |
puts '%6d: %5.2fs, %s' % [i, delay, colour] | |
sleep(delay) | |
pimp colour | |
end | |
end | |
if $0 == __FILE__ | |
pimp_away | |
puts "Pimped #{COUNTS[:red]} red, #{COUNTS[:orange]} orange, #{COUNTS[:green]} green & #{COUNTS[:except]} exceptions" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment