Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Discussion & Documentation Documentation, Tips & Tricks
  • Search

HOWTO: Set background depending on time, weather, season...

Unofficial documentation for various parts of Gentoo Linux. Note: This is not a support forum.
Post Reply
Advanced search
33 posts
  • 1
  • 2
  • Next
Author
Message
SerfurJ
l33t
l33t
Posts: 824
Joined: Sat Apr 10, 2004 10:25 pm
Location: Texas

HOWTO: Set background depending on time, weather, season...

  • Quote

Post by SerfurJ » Sun Apr 24, 2005 4:35 pm

EDIT: see the project webpage for latest updates.

The following howto shows you how to set your background depending on the time of day and the weather/season. Each day, you'll see a different image in the morning, mid-day, afternoon, sunset, and evening. The images will also reflect the current weather or season depending on the configuration. The images for each time of day are chosen randomly, so no two days will ever have the same set of images.

A typical day might look something like this:
  • Morning
  • Mid-day
  • Afternoon or Winter afternoon
  • Sunset
  • Evening
It's the second best thing to actually being outside!
  1. Download some images to get your collection started, and unpack them somewhere on your harddrive. (Here is my current collection. Click on "free" at the bottom of the page.) You'll also need to find some photos for winter and rainy days.
  2. Put this in ~/bin/onewithnature

    Code: Select all

    #!/usr/bin/python
    
    import pymetar, sys, re, os, time
    
    ## configuration section
    # path to wallpapers
    wallpaperdir = "/path/to/wallpapers/"
    # the closest weather station
    station = "KGLS"
    # background setter (and display)
    bgsetter = "DISPLAY=:0.0 /usr/bin/fbsetbg -r "
    ## end configuration section
    
    rf = pymetar.ReportFetcher(station)
    rep = rf.FetchReport()
    rp = pymetar.ReportParser()
    pr = rp.ParseReport(rep)
    
    pattern = re.compile('.*rain.*')
    rainy = pattern.search(pr.getWeather())
    temp = pr.getTemperatureFahrenheit()
    
    if rainy:
        os.popen(bgsetter + wallpaperdir + 'rainy &>/dev/null')
    elif temp < 40:
        os.popen(bgsetter + wallpaperdir + 'winter &>/dev/null')
    else:
        os.popen(bgsetter + wallpaperdir + sys.argv[1] + ' &>/dev/null')
    
  3. Edit the configuration section:
    • Change the path to match where your image collection is.
    • Set your weather station.
    • Set the background setter. Since I use Fluxbox, I use fbsetbg to set the background, but you can use any background setter that supports random loading of images.
  4. Make ~/bin/onewithnature is executable:

    Code: Select all

    chmod 755 ~/bin/onewithnature
  5. Install pymetar.

    Code: Select all

    $ emerge pymetar
  6. At the prompt, type:

    Code: Select all

    $ crontab -e
    and put the following in your crontab:

    Code: Select all

    # CRONTAB for drei
    #
    #       1)                                              => Minute
    #               2)                                      => Hour
    #                       3)                              => Day
    #                               4)                      => Month
    #                                       5)              => Day of week
    #                                               6)      => Command
    #
    #       1)      2)      3)      4)      5)      6)
    #       |       |       |       |       |       |
    
    ## Different backgrounds to set mood depending on time of day
            0       5       *       *       *       /home/user/bin/onewithnature morning
            0       11      *       *       *       /home/user/bin/onewithnature mid-day
            0       13      *       *       *       /home/user/bin/onewithnature afternoon
            0       19      *       *       *       /home/user/bin/onewithnature sunset
            0       20      *       *       *       /home/user/bin/onewithnature evening
    
  7. Adjust the sunset/evening times depending on your location.
That's it!

If you come across photos that fit in any of the categories, please share them. Also, if you can think of any other categories or schemes, post them here.
Last edited by SerfurJ on Fri May 13, 2005 8:00 pm, edited 6 times in total.
Top
alkan
Guru
Guru
User avatar
Posts: 385
Joined: Fri Aug 06, 2004 6:34 pm
Location: kasimlar yaylasi

  • Quote

Post by alkan » Sun Apr 24, 2005 5:02 pm

here is what i run from cron every 30 minutes to set my kde and fluxbox wall paper randomly.

Code: Select all

DCOPSERVER=`cat /home/user/.DCOPserver_c1_:0 | grep local`
export DCOPSERVER

find /usr/share/pixmaps/ -type f -iname "*.jpg" -o -iname "*.png" > /tmp/wallpapers
NB_LINES=$(expr $(wc -l /tmp/wallpapers | sed -e 's/ *//' | cut -f1 -d " "))
NB_RAND=0
while [ "$NB_RAND" -eq 0 ]
do
NB_RAND=$(expr $RANDOM \% $NB_LINES)
done
WP=`sed -n "${NB_RAND}p;${NB_RAND}q" /tmp/wallpapers`

#set fluxbox wallpaper
DISPLAY=:0.0 /usr/bin/fbsetbg -A $WP
#"#d6d7e7"'


#set kde wallpaper
/usr/kde/3.4/bin/dcop --user user --all-sessions kdesktop KBackgroundIface setWallpaper $WP 4
#/usr/kde/3.4/bin/dcop --user user --all-sessions kdesktop-screen-1 KBackgroundIface setWallpaper $WP 4
by the way, another script downloads a bunch of wall papers every week from a website. I'd rather not give that scrip since it is not really ......
Top
SerfurJ
l33t
l33t
Posts: 824
Joined: Sat Apr 10, 2004 10:25 pm
Location: Texas

  • Quote

Post by SerfurJ » Sun Apr 24, 2005 5:50 pm

thanks.. but this howto isn't really about setting a random wallpaper. it's more about how to set the mood of your desktop depending on the time of day.

if you have relevant images or other ideas, please share.
Top
SerfurJ
l33t
l33t
Posts: 824
Joined: Sat Apr 10, 2004 10:25 pm
Location: Texas

  • Quote

Post by SerfurJ » Wed Apr 27, 2005 2:36 am

i just rewrote the howto. it was previously "HOWTO: Be One with Nature using cron". it should be more thorough and user friendly now.

be sure to post feedback if you try it out.
Top
Digital Storm
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 116
Joined: Fri Mar 07, 2003 3:01 am
Location: Toronto, Canada

  • Quote

Post by Digital Storm » Wed Apr 27, 2005 4:43 am

Very cool, I'll have to set it up once I'm back to using Gentoo...

Although it would be cool to find a nice location and set up a camera to snap photos every 30 mins...Then have your background change with the time of the day...It would obviously take time to find a nice spot and take the photos but it would be cool...
Top
SerfurJ
l33t
l33t
Posts: 824
Joined: Sat Apr 10, 2004 10:25 pm
Location: Texas

  • Quote

Post by SerfurJ » Wed Apr 27, 2005 2:38 pm

Digital Storm wrote:Very cool, I'll have to set it up once I'm back to using Gentoo...
thanks. it's not dependent on gentoo, but you need a linux/unix system.
Digital Storm wrote:Although it would be cool to find a nice location and set up a camera to snap photos every 30 mins...Then have your background change with the time of the day...It would obviously take time to find a nice spot and take the photos but it would be cool...
yeah, i thought about taking photos at a scenic location at 7am, 11am, 3pm, 7pm, and 9pm. it would be some work though. i'm about to take a trip to a beautiful area around seattle, washington, so i'll try this out if i have time.
Top
SerfurJ
l33t
l33t
Posts: 824
Joined: Sat Apr 10, 2004 10:25 pm
Location: Texas

  • Quote

Post by SerfurJ » Sun May 01, 2005 4:40 pm

i've set up a project webpage at:
http://www.dunsm.org/projects/one-with-nature.html
Top
pjp
Administrator
Administrator
User avatar
Posts: 20668
Joined: Tue Apr 16, 2002 10:35 pm

  • Quote

Post by pjp » Sun May 01, 2005 5:46 pm

Cool idea. I've been wanting to do something very similar, only with moon phases.
Top
SerfurJ
l33t
l33t
Posts: 824
Joined: Sat Apr 10, 2004 10:25 pm
Location: Texas

  • Quote

Post by SerfurJ » Sun May 01, 2005 6:15 pm

I've been wanting to do something very similar, only with moon phases.
good idea, thanks. i added your idea to a configuration schemes section.

now, to get nice moon phase photos...
Top
Danuvius
Guru
Guru
Posts: 375
Joined: Sat Sep 18, 2004 6:55 pm
Location: Toronto

  • Quote

Post by Danuvius » Mon May 02, 2005 5:56 am

I don't have an /usr/bin/fbsetbg

Where is that from?
Magyar Reddit
Top
SerfurJ
l33t
l33t
Posts: 824
Joined: Sat Apr 10, 2004 10:25 pm
Location: Texas

  • Quote

Post by SerfurJ » Mon May 02, 2005 1:01 pm

/usr/bin/fbsetbg is from fluxbox. you can use a different background setter (feh, Esetbg, ...), but i'm not sure which other one can set a background randomly. there's probably a way to incorporate the randomness using a simple bash script.
Top
Danuvius
Guru
Guru
Posts: 375
Joined: Sat Sep 18, 2004 6:55 pm
Location: Toronto

  • Quote

Post by Danuvius » Mon May 02, 2005 2:26 pm

SerfurJ wrote:/usr/bin/fbsetbg is from fluxbox. you can use a different background setter (feh, Esetbg, ...), but i'm not sure which other one can set a background randomly. there's probably a way to incorporate the randomness using a simple bash script.
What is the KDE background changer? And what do I need to emerge to get it?
Magyar Reddit
Top
alkan
Guru
Guru
User avatar
Posts: 385
Joined: Fri Aug 06, 2004 6:34 pm
Location: kasimlar yaylasi

  • Quote

Post by alkan » Mon May 02, 2005 4:56 pm

Danuvius wrote:
SerfurJ wrote:/usr/bin/fbsetbg is from fluxbox. you can use a different background setter (feh, Esetbg, ...), but i'm not sure which other one can set a background randomly. there's probably a way to incorporate the randomness using a simple bash script.
What is the KDE background changer? And what do I need to emerge to get it?
dcop kdesktop KBackgroundIface setWallpaper /path/to/background/image/file 4
Top
Danuvius
Guru
Guru
Posts: 375
Joined: Sat Sep 18, 2004 6:55 pm
Location: Toronto

  • Quote

Post by Danuvius » Mon May 02, 2005 5:08 pm

alkan wrote:
Danuvius wrote:
SerfurJ wrote:/usr/bin/fbsetbg is from fluxbox. you can use a different background setter (feh, Esetbg, ...), but i'm not sure which other one can set a background randomly. there's probably a way to incorporate the randomness using a simple bash script.
What is the KDE background changer? And what do I need to emerge to get it?
dcop kdesktop KBackgroundIface setWallpaper /path/to/background/image/file 4
Doh! That would have been the second thing I would have tried... :lol:

Well... no, actually, I never would have guessed. Thanks. :D
Magyar Reddit
Top
SerfurJ
l33t
l33t
Posts: 824
Joined: Sat Apr 10, 2004 10:25 pm
Location: Texas

  • Quote

Post by SerfurJ » Mon May 02, 2005 7:14 pm

here's a bash script similar to one i saw here for random background setting without fbsetbg:

Code: Select all

#!/bin/bash

BACKGROUND_DIR=$1
FORMAT="*.jpg"

IMGS=`find "$BACKGROUND_DIR" -iname $FORMAT`
N=`echo $IMGS | wc -w`
((N=RANDOM%N))
echo $IMGS | cut -d ' ' -f $N
usage:

Code: Select all

Esetroot `randomimage /path/to/images`
Top
knobby
n00b
n00b
Posts: 1
Joined: Mon Jul 04, 2005 1:10 am

  • Quote

Post by knobby » Mon Jul 04, 2005 1:19 am

SerfurJ,
That script didn't work out too well for me if the filename had spaces in it, which the wallpapers.tar.gz included. :-/

So I took the liberty of changing it around a bit so it would work. This works for me, your mileage may vary.

Code: Select all

#!/bin/bash

BACKGROUND_DIR=$1
FORMAT="*.jpg"

N=`find "$BACKGROUND_DIR" -iname "$FORMAT"|wc -l`
((N=RANDOM%N))
echo `find "$BACKGROUND_DIR" -iname "$FORMAT"|sed -ne $(expr $N + 1)p`
Top
snakattak3
Guru
Guru
User avatar
Posts: 468
Joined: Wed Dec 11, 2002 5:13 am
Location: Seattle

  • Quote

Post by snakattak3 » Mon Jul 04, 2005 3:48 am

Oh man, this reminds me of the Noia wallpaper that used to be up on kde-look.org. There was 24 different wallpapers for each hour of the day. I wish I still had that one to use with this script. Can't seem to find it any more.

[EDIT]
Well, found the page on archive.org
http://web.archive.org/web/200301182309 ... ntent=4203
Thats about it though. Nothing else seems to be up anymore, or archived :(
Ban Reality TV!
Adopt an Unanswered Post
Top
SerfurJ
l33t
l33t
Posts: 824
Joined: Sat Apr 10, 2004 10:25 pm
Location: Texas

  • Quote

Post by SerfurJ » Mon Jul 04, 2005 2:39 pm

thanks knobby.
snakattak3 wrote:Oh man, this reminds me of the Noia wallpaper that used to be up on kde-look.org. There was 24 different wallpapers for each hour of the day. I wish I still had that one to use with this script. Can't seem to find it any more.

[EDIT]
Well, found the page on archive.org
http://web.archive.org/web/200301182309 ... ntent=4203
Thats about it though. Nothing else seems to be up anymore, or archived :(
thanks for the site. same idea, but it looks like they're using illustrations.

here are some time-series photos i took:
http://www.dunsm.org/photos/2005/nature-series/
Top
artificio
Apprentice
Apprentice
Posts: 183
Joined: Wed Sep 15, 2004 9:46 pm

  • Quote

Post by artificio » Wed Jul 13, 2005 8:52 am

It'd be really cool if you had a nice camcorder set outside and rigged to take a frame from that every minute or second or so... although I'm not sure if a camcorder can upload and film at the same time.
Top
BlackB1rd
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 131
Joined: Wed Aug 13, 2003 11:45 am
Location: /Europe/Netherlands/Haarlem

  • Quote

Post by BlackB1rd » Fri Aug 05, 2005 3:35 pm

Thanks, after some modifications I finally got it working with the KDE background changer 8)
One thing: Why do I almost always get a rainy background? Oh wait, weather always sucks in here :x ;)
Top
Hydraulix
Guru
Guru
User avatar
Posts: 447
Joined: Fri Dec 12, 2003 4:28 am

  • Quote

Post by Hydraulix » Sat Aug 06, 2005 10:58 pm

Wow this is great. I'll have to give this a shot when I'm off work.
It is the fate of operating systems to become free.
- Neal Stephenson
Top
Hydraulix
Guru
Guru
User avatar
Posts: 447
Joined: Fri Dec 12, 2003 4:28 am

  • Quote

Post by Hydraulix » Sun Aug 07, 2005 2:29 am

Well I got this error.

Code: Select all

Traceback (most recent call last):
  File "/usr/bin/onewithnature", line 25, in ?
    os.popen(bgsetter + wallpaperdir + sys.argv[1] + ' &>/dev/null')
IndexError: list index out of range
It is the fate of operating systems to become free.
- Neal Stephenson
Top
tom56
Guru
Guru
User avatar
Posts: 325
Joined: Tue Apr 27, 2004 8:39 pm
Location: united kingdom

  • Quote

Post by tom56 » Sun Aug 07, 2005 10:03 pm

If getWeather returns "None", then the script doesn't like it:

Code: Select all

Traceback (most recent call last):
  File "./onewithnature", line 20, in ?
    rainy = pattern.search(pr.getWeather())
TypeError: expected string or buffer
How does one get around this? I don't know enough python to work out how to fix it.
"A million surplus Maggies are willing to bear the yoke; And a woman is only a woman, but a good cigar is a Smoke" -- Rudyard Kipling (on why he chose cigars over his wife)
Top
japhy
n00b
n00b
Posts: 30
Joined: Fri Aug 05, 2005 9:12 am
Location: Berkeley, CA

  • Quote

Post by japhy » Thu Aug 11, 2005 2:49 pm

I found a webcam that has a constantly updated image of the area where i live in decent resolution, as I figure many other people could with a little work. For example, if you live in Berkeley or anywhere near San Francisco: sv.berkeley.edu/view/images/current_view.jpg). I can handle adjusting the cron script to a shorter, consistent interval, but does anyone know how to get the script to read an image from a given URL?
Top
gabe-kai
n00b
n00b
User avatar
Posts: 63
Joined: Wed Sep 03, 2003 5:11 am
Location: Michigan, USA

  • Quote

Post by gabe-kai » Mon Aug 15, 2005 11:59 pm

I am getting a python error when I try to run this script, perhaps someone can help me with it?

./onewithnature

Code: Select all

Traceback (most recent call last):
  File "./onewithnature", line 25, in ?
    os.popen(bgsetter + wallpaperdir + sys.argv[1] + ' &>/dev/null')
IndexError: list index out of range
"People demand freedom of speech to make up for the freedom of thought which they avoid."
- Soren Aabye Kierkegaard
Top
Post Reply

33 posts
  • 1
  • 2
  • Next

Return to “Documentation, Tips & Tricks”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic