Created
May 12, 2014 18:34
-
-
Save emad-elsaid/c199f2146093e73a7772 to your computer and use it in GitHub Desktop.
Auto change wallpaper on linux from reddit
this script will get a new image from reddit every period and write it to an ixisting image on you Hard drive, if you set this image as your wallpaper you will have a constantly changing desktop wallpaper from the amazing subreddit called EarthPorn, they post grazy beautiful images of our mother earth. …
This file contains hidden or 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
#!/usr/bin/env ruby | |
# Author : Emad Elsaid (https://github.com/blazeeboy) | |
# | |
# autochanging wallpaper from reddit images | |
# you have to point the script to your existing | |
# file you set it as a wallpaper and it will override | |
# it with a new image every 5 minutes. | |
# | |
# this script works on centos 6 with GNOME/GTK2 interface | |
require 'open-uri' # we'll need to download image with that | |
require 'ruby_reddit_api' # gem install ruby_reddit_api | |
# class will be initialized with | |
# a subreddit to monitor and a | |
# destination file to write the | |
# downloaded image to it | |
class RedditWallpaper | |
def initialize( subreddit, destination_file = 'bg.jpg' ) | |
@subreddit = subreddit | |
@path = destination_file | |
@downloaded = [] | |
@not_downloaded = [] | |
end | |
# download the url to destination | |
def download( url ) | |
image = open( "#{url}.jpg" ).read | |
File.write @path, image | |
end | |
# update wallpaper and update images cache | |
def update | |
# make me a reddit client please | |
r = Reddit::Api.new | |
# update earth | |
posts = r.browse @subreddit | |
posts.each do |r| | |
@not_downloaded << r.url if r.url.include?('imgur') and [email protected]?(r.url) | |
end | |
image = @not_downloaded.shift | |
download image | |
end | |
end | |
# i'll get images from earthporn | |
# they have lots of great images of | |
# nature places | |
# and then i'll update it every 5 minutes | |
downloader = RedditWallpaper.new 'earthPorn', '/home/eelsaid/Pictures/bg.jpg' | |
loop do | |
downloader.update | |
sleep 5*60 # wait for 5 minutes | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment