Re: And now... a totally trivial question about wallpaper/background images for Lispers



On Wed, 01 Mar 2006 12:53:13 -0800, Jonathon McKitrick wrote:


I hardly qualify as a true Lisper yet, but I'm getting tired of my
northern-lights-over-just-fallen-snow background image. I'm wondering
if any of you have any cool wallpaper, whether Lispish or not. Perhaps
some well-proportioned coed Lispers? All ideas welcome, even personal
attacks on my programming ability, manhood, and the appropriateness of
this post in c.l.l. ;-)

Hi, I have a script that pulls the astronomy picture of the day and
generates a desktop image from the picture as well as storing both the
wallpaper and the high resolution version in a folder so that I can use it
for my xscreensavers. It drops the wallpaper into your home directory
under the name wallpaper.jpg.

This script is written in Ruby (yeah I know, not lisp) and its free
software (GPL2). If you make changes/improvements, please pass them along
to them so that I can reintegrate them back into my version.

Also, be forewarned that the script does not cleanup after itself and will
leave droppings in /tmp/apod. Also, feel free to remove the xsetbg system
call at the end of the script if you'd prefer to run it yourself instead.

Set your screen resolution and the directories you want to use at the
beginning of the file.

Enjoy,
Brandon Edens

#!/usr/bin/ruby -w
#--
# apod - script to pull the astronomy picture of the day and generate an image
# suitable as a desktop wallpaper.
# See: http://antwrp.gsfc.nasa.gov/apod
#
# Copyright (c) 2006 Matthew Brandon Edens
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#++

# This program requires both RMagick and wget to function.
require 'ftools'
require 'fileutils'
require 'date'
require 'tmpdir'
require 'RMagick'

# globals - tweak the program here
SCREEN_WIDTH=1280
SCREEN_HEIGHT=768

TMPDIR="/tmp/apod"

HOME="/home/brandon"
WALLPAPER="#{HOME}/wallpaper.jpg"
HIGHRES="#{HOME}/media/pictures/astronomy_picture_of_the_day/highres"
DESKTOP="#{HOME}/media/pictures/astronomy_picture_of_the_day/wallpaper"

def wrap(str, max_size)
all = []
line = ''
for l in str.split
if (line+l).length >= max_size
all.push(line)
line = ''
end
line += line == '' ? l : ' ' + l
end
all.push(line).join("\n")
end

def month_to_number(str)
case str
when "January"
return 1
when "February"
return 2
when "March"
return 3
when "April"
return 4
when "May"
return 5
when "June"
return 6
when "July"
return 7
when "August"
return 8
when "September"
return 9
when "October"
return 10
when "November"
return 11
when "December"
return 12
end
end

if $0 == __FILE__
url = ARGV[0]

# some initial directory creation
FileUtils.mkdir(TMPDIR) unless File.directory?(TMPDIR)

# pull down the needed astronomy picture of the day images and html
wget = Kernel.system("wget -q -nd -nc -O#{TMPDIR}/index.html #{ARGV[0] ? ARGV[0] : 'http://antwrp.gsfc.nasa.gov/apod/index.html'}")
wget = Kernel.system("wget -q -nd -nc -r -l1 -P#{TMPDIR} --accept jpg,png,gif,jpeg,index.html #{ARGV[0] ? ARGV[0] : 'http://antwrp.gsfc.nasa.gov/apod/index.html'}")
# open the astronomy index.html to get names of images and explanation
index = File.open("#{TMPDIR}/index.html")
st = index.read =~ /<body.*?>/im
index.rewind
en = index.read =~ /<\/body>/im
index.rewind
text = index.read[st...en]

# get the date from the index html page pulled down from the site
re = /([0-9][0-9][0-9][0-9]) (January|February|March|April|May|June|July|August|September|October|November|December) ([0-9]+)/m
md = re.match(text)
year = md[1]
month = month_to_number(md[2])
day = md[3]
date = "#{md[1]} #{md[2]} #{md[3]}"
date_directory = "#{year}-#{month}-#{day}"

# get the high resolution image filename
re = /#{date}.*?<a href="(.*?)">/im
md = re.match(text)
tmp_str = md[1]
re = /.*\/(.*?)$/m
md = re.match(tmp_str)
highres = md[1]

# get the low resolution image filename
re = /#{date}.*?<img src="(.*?)"/im
md = re.match(text)
tmp_str = md[1]
re = /.*\/(.*?)$/m
md = re.match(tmp_str)
lowres = md[1]

# get the explanation
re = /(Explanation:.*?)Tomorrow's picture:/m
md = re.match(text)
explanation = md[1]
explanation = wrap(explanation.gsub(/<.*?>/m, ""), 65)

# generate the desktop wallpaper
image = Magick::ImageList.new("#{TMPDIR}/#{lowres}")
background = Magick::Image.new(SCREEN_WIDTH, SCREEN_HEIGHT) { self.background_color = 'black' }
text = Magick::Draw.new
wallpaper = background.composite(image, Magick::EastGravity, Magick::OverCompositeOp)
text.annotate(wallpaper, (SCREEN_WIDTH - image.columns), SCREEN_HEIGHT, 10, 10, explanation) {
self.gravity = Magick::WestGravity
self.pointsize = 14
self.stroke = 'transparent'
self.fill = '#eeeeee'
self.font_weight = Magick::BoldWeight
}
wallpaper.write("#{TMPDIR}/wallpaper.jpg")

# make the directories for permanent storage
FileUtils.mkdir("#{DESKTOP}/#{date_directory}") unless File.directory?("#{DESKTOP}/#{date_directory}")
FileUtils.mkdir("#{HIGHRES}/#{date_directory}") unless File.directory?("#{HIGHRES}/#{date_directory}")

# copy wallpaper to today's wallpaper location
FileUtils.copy("#{TMPDIR}/wallpaper.jpg", "#{WALLPAPER}")

# copy wallpaper to permanent location
FileUtils.copy("#{TMPDIR}/wallpaper.jpg", "#{DESKTOP}/#{date_directory}/wallpaper.jpg")

# copy highres to its permanent location
FileUtils.copy("#{TMPDIR}/#{highres}", "#{HIGHRES}/#{date_directory}/#{highres}")

# clean up afterwards
#FileUtils.rm("#{TMPDIR}/index.html")
#FileUtils.rm("#{TMPDIR}/#{highres}")
#FileUtils.rm("#{TMPDIR}/#{lowres}")
#FileUtils.rm("#{TMPDIR}/wallpaper.jpg")
#FileUtils.rmdir("#{TMPDIR}")

# set the X background
Kernel.system("xsetbg -quiet -onroot -fullscreen #{WALLPAPER}")

end

.



Relevant Pages

  • Push New Wallpaper To XP Clients
    ... I need a VB script that upon startup, will look for a wallpaper in JPEG ... or if a reboot is required as these machines are rebooted each night. ...
    (microsoft.public.windows.group_policy)
  • RE: How do you change the background on a remote system?
    ... you cant set the wallpaper using this property. ... Hopefully someone else can whip up a script for you. ... or add the reg key setting to your logon script. ... >> Directory) and make the settings change. ...
    (microsoft.public.scripting.vbscript)
  • RE: Script to change desktop wallpaper?
    ... If you know VB or just VB script you may be able to use this in your ... The other way to change wallpapers is to redirect the wallpaper using Group ... -> Active Desktop and then Active Desktop Wallpaper allows you to specify a ... "Tadashi Inayama" wrote: ...
    (microsoft.public.windows.server.general)
  • Re: Gnome 3: change wallpaper via commandline
    ... I need a way to change the wallpaper ... via commandline. ... gconf anymore to store background image information) has stopped ... Cool script though. ...
    (Fedora)
  • [PATCH] tracing: move scripts/trace/power.pl to scripts/tracing/power.pl
    ... -# Free Software Foundation; ... See the GNU General Public License ... -# This script turns a cstate ftrace output into a SVG graphic that shows ...
    (Linux-Kernel)