Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Wallpaper
- # This sets the specified image as the wallpaper and, by default, tiles it. Use
- # $ gsettings range org.gnome.desktop.background picture-options
- # to see other options for centring/stretching the image. You can also specify a different source directory
- def self.update(filename,display="wallpaper",dir="file:///path/to/wallpaper")
- `gsettings set org.gnome.desktop.background picture-uri #{dir}/#{filename} && gsettings set org.gnome.desktop.background picture-options "#{display}"`
- end
- end
- # This is where the fun bit starts
- require "rubygems"
- require "twitter" # https://github.com/sferik/twitter
- # Visit http://apps.twitter.com to set up your API keys
- client = Twitter::Streaming::Client.new do |config|
- config.consumer_key = "YOUR_CONSUMER_KEY"
- config.consumer_secret = "YOUR_CONSUMER_SECRET"
- config.access_token = "YOUR_ACCESS_TOKEN"
- config.access_token_secret = "YOUR_ACCESS_SECRET"
- end
- users = ["19455489"] # Just Matt, for the purposes of this script
- attempts = 0
- begin
- attempts = 1
- # Get the live stream for the relevant users
- client.filter(follow: users.join(",")) do |object|
- # We only care about tweets
- if object.is_a?(Twitter::Tweet)
- # This is so we don't trigger on replies/mentions etc.
- if object.user.screen_name.downcase == "jam_sponge"
- # Now we want to make sure this is one of the trigger phrases
- if object.text.include?("GOOD MORNING")
- Wallpaper.update("morning.png")
- elsif object.text.include?("GOOD NIGHT")
- Wallpaper.update("night.jpg")
- end
- end
- end
- end
- rescue Twitter::Error::TooManyRequests => error
- puts "#{Time.now.strftime("%H:%M:%S")} -- Attempt #{attempts} failed"
- if attempts % 3 == 0
- puts "#{Time.now.strftime("%H:%M:%S")} -- Waiting 15 minutes..."
- sleep(15*60)
- end
- retry
- end
Advertisement
Add Comment
Please, Sign In to add comment