Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
HOWTO: Set background depending on time, weather, season...
View unanswered posts
View posts from last 24 hours

Goto page 1, 2  Next  
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
SerfurJ
l33t
l33t


Joined: 10 Apr 2004
Posts: 824
Location: Texas

PostPosted: Sun Apr 24, 2005 4:35 pm    Post subject: HOWTO: Set background depending on time, weather, season... Reply with quote

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:
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:
    #!/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:
    chmod 755 ~/bin/onewithnature


  5. Install pymetar.
    Code:
    $ emerge pymetar


  6. At the prompt, type:
    Code:
    $ crontab -e

    and put the following in your crontab:
    Code:
    # 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
Back to top
View user's profile Send private message
alkan
Guru
Guru


Joined: 06 Aug 2004
Posts: 385
Location: kasimlar yaylasi

PostPosted: Sun Apr 24, 2005 5:02 pm    Post subject: Reply with quote

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

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 ......
Back to top
View user's profile Send private message
SerfurJ
l33t
l33t


Joined: 10 Apr 2004
Posts: 824
Location: Texas

PostPosted: Sun Apr 24, 2005 5:50 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
SerfurJ
l33t
l33t


Joined: 10 Apr 2004
Posts: 824
Location: Texas

PostPosted: Wed Apr 27, 2005 2:36 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Digital Storm
Tux's lil' helper
Tux's lil' helper


Joined: 07 Mar 2003
Posts: 116
Location: Toronto, Canada

PostPosted: Wed Apr 27, 2005 4:43 am    Post subject: Reply with quote

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...
Back to top
View user's profile Send private message
SerfurJ
l33t
l33t


Joined: 10 Apr 2004
Posts: 824
Location: Texas

PostPosted: Wed Apr 27, 2005 2:38 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
SerfurJ
l33t
l33t


Joined: 10 Apr 2004
Posts: 824
Location: Texas

PostPosted: Sun May 01, 2005 4:40 pm    Post subject: Reply with quote

i've set up a project webpage at:
http://www.dunsm.org/projects/one-with-nature.html
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 17811

PostPosted: Sun May 01, 2005 5:46 pm    Post subject: Reply with quote

Cool idea. I've been wanting to do something very similar, only with moon phases.
Back to top
View user's profile Send private message
SerfurJ
l33t
l33t


Joined: 10 Apr 2004
Posts: 824
Location: Texas

PostPosted: Sun May 01, 2005 6:15 pm    Post subject: Reply with quote

Quote:
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...
Back to top
View user's profile Send private message
Danuvius
Guru
Guru


Joined: 18 Sep 2004
Posts: 375
Location: Toronto

PostPosted: Mon May 02, 2005 5:56 am    Post subject: Reply with quote

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

Where is that from?
Back to top
View user's profile Send private message
SerfurJ
l33t
l33t


Joined: 10 Apr 2004
Posts: 824
Location: Texas

PostPosted: Mon May 02, 2005 1:01 pm    Post subject: Reply with quote

/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.
Back to top
View user's profile Send private message
Danuvius
Guru
Guru


Joined: 18 Sep 2004
Posts: 375
Location: Toronto

PostPosted: Mon May 02, 2005 2:26 pm    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
alkan
Guru
Guru


Joined: 06 Aug 2004
Posts: 385
Location: kasimlar yaylasi

PostPosted: Mon May 02, 2005 4:56 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Danuvius
Guru
Guru


Joined: 18 Sep 2004
Posts: 375
Location: Toronto

PostPosted: Mon May 02, 2005 5:08 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
SerfurJ
l33t
l33t


Joined: 10 Apr 2004
Posts: 824
Location: Texas

PostPosted: Mon May 02, 2005 7:14 pm    Post subject: Reply with quote

here's a bash script similar to one i saw here for random background setting without fbsetbg:
Code:
#!/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:
Esetroot `randomimage /path/to/images`
Back to top
View user's profile Send private message
knobby
n00b
n00b


Joined: 04 Jul 2005
Posts: 1

PostPosted: Mon Jul 04, 2005 1:19 am    Post subject: Reply with quote

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:

#!/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`
Back to top
View user's profile Send private message
snakattak3
Guru
Guru


Joined: 11 Dec 2002
Posts: 468
Location: Seattle

PostPosted: Mon Jul 04, 2005 3:48 am    Post subject: Reply with quote

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/20030118230915/www.kde-look.org/content/show.php?content=4203
Thats about it though. Nothing else seems to be up anymore, or archived :(
_________________
Ban Reality TV!
Adopt an Unanswered Post
Back to top
View user's profile Send private message
SerfurJ
l33t
l33t


Joined: 10 Apr 2004
Posts: 824
Location: Texas

PostPosted: Mon Jul 04, 2005 2:39 pm    Post subject: Reply with quote

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/20030118230915/www.kde-look.org/content/show.php?content=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/
Back to top
View user's profile Send private message
artificio
Apprentice
Apprentice


Joined: 15 Sep 2004
Posts: 183

PostPosted: Wed Jul 13, 2005 8:52 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
BlackB1rd
Tux's lil' helper
Tux's lil' helper


Joined: 13 Aug 2003
Posts: 131
Location: /Europe/Netherlands/Haarlem

PostPosted: Fri Aug 05, 2005 3:35 pm    Post subject: Reply with quote

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 ;)
Back to top
View user's profile Send private message
Hydraulix
Guru
Guru


Joined: 12 Dec 2003
Posts: 447
Location: Baltimore, Maryland

PostPosted: Sat Aug 06, 2005 10:58 pm    Post subject: Reply with quote

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

If only You and Dead people can read hex, how many people can read hex?
Back to top
View user's profile Send private message
Hydraulix
Guru
Guru


Joined: 12 Dec 2003
Posts: 447
Location: Baltimore, Maryland

PostPosted: Sun Aug 07, 2005 2:29 am    Post subject: Reply with quote

Well I got this error.


Code:

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

If only You and Dead people can read hex, how many people can read hex?
Back to top
View user's profile Send private message
tom56
Guru
Guru


Joined: 27 Apr 2004
Posts: 325
Location: united kingdom

PostPosted: Sun Aug 07, 2005 10:03 pm    Post subject: Reply with quote

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

Code:

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)
Back to top
View user's profile Send private message
japhy
n00b
n00b


Joined: 05 Aug 2005
Posts: 30
Location: Berkeley, CA

PostPosted: Thu Aug 11, 2005 2:49 pm    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
gabe-kai
n00b
n00b


Joined: 03 Sep 2003
Posts: 63
Location: Michigan, USA

PostPosted: Mon Aug 15, 2005 11:59 pm    Post subject: Reply with quote

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

./onewithnature
Code:
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
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum