Results 1 to 6 of 6

Thread: Bash script to auto-download wallpapers without RSS

  1. #1
    Join Date
    Sep 2008
    Beans
    23

    Bash script to auto-download wallpapers without RSS

    So abduzeedo.com posts a sick new wallpaper every week and I thought it'd be neat to have a script that goes and gets it and sets it as the current wallpaper for a week's time. I don't really know what the best way to do this would be. Here's some info that might help out:


    Thanks for any code!

  2. #2
    Join Date
    Feb 2007
    Beans
    4,045
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Bash script to auto-download wallpapers without RSS

    I liked those images, and the idea, so I made a script to do it.

    I noticed that http://www.abductit.com/files/wallpapers gave a standard directory listing. So the script reads that listing, sorted by last modified, and grabs the last one, which will most likely be the latest weekly. Then it downloads the image of wanted size to /usr/local/share/backgrounds/Weekly abduzeedo.jpg.

    Obviously, you'll have to set /usr/local/share/backgrounds/Weekly abduzeedo.jpg as your wallpaper. When a new one gets downloaded, it should be detected automatically.

    Code:
    #!/bin/bash
    
    size=1280R
    dest="/usr/local/share/backgrounds/Weekly abduzeedo.jpg"
    
    mkdir -p "${dest%/*}" || exit
    
    read -r _ baseurl < <(lynx -listonly -dump 'http://www.abductit.com/files/wallpapers/?C=M;O=A' | tail -1) &&
    wget -q "$baseurl/wp_$size.jpg" -O "$dest"
    Copy it to /etc/cron.weekly/weeklywall (or some other name you prefer, but do NOT add an extension) and make it executable. It will then be run by anacron once a week, and during boot (if it was more than a week since last it was run).

    Oh and the script uses lynx to parse the html, but lynx is not installed by default, so you'll need to install it apt://lynx-cur.

  3. #3
    Join Date
    Sep 2009
    Location
    Freiburg/Germany
    Beans
    1,112
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: Bash script to auto-download wallpapers without RSS

    lynx has a greate keystroke recording feature that comes handy with thinks like that:

    Save the following as e.g. abduzeedo.lynx
    Code:
    set INFOSECSr=:0
    set MESSAGESECS=0
    set ALERTSECS=3
    set REPLAYSECS=0
    
    key /
    key W
    key a
    key l
    key l
    key p
    key a
    key p
    key e
    key r
    key <space>
    key o
    key f
    key <space>
    key t
    key h
    key e
    key <space>
    key w
    key e
    key e
    key k
    key ^J
    key ^J
    key Down Arrow
    key /
    key R
    key e
    key s
    key o
    key l
    key u
    key t
    key i
    key o
    key n
    key s
    key ^J
    key Down Arrow
    key d
    key ^J
    key ^U
    key ~
    key /
    key w
    key a
    key l
    key l
    key p
    key a
    key p
    key e
    key r
    key .
    key j
    key p
    key g
    key ^J
    key q
    key ^J
    Then
    Code:
    lynx -cmd_script abduzeedo.lynx   http://abduzeedo.com/tags/wallpaper
    saves the current Wallpaper of the Week in the highest resolution available as ~/wallpaper.jpg
    ClassicMenu Indicator - classic GNOME menu for Unity
    Unsettings - configuration program for the Unity
    Privacy Indicator - easily switch privacy settings in Unity
    Arronax - create and modify app starters

  4. #4
    Join Date
    Jun 2006
    Beans
    108

    Re: Bash script to auto-download wallpapers without RSS

    Quote Originally Posted by geirha View Post
    ...
    Code:
    read -r _ baseurl < <(lynx -listonly -dump 'http://www.abductit.com/files/wallpapers/?C=M;O=A' | tail -1) &&
    wget -q "$baseurl/wp_$size.jpg" -O "$dest"
    ...
    I understand this is attempting to put the results of the lynx and tail commands into the variable baseurl, but I'm not experienced with the context of read -r _
    And how does the < < separated by whitespace redirect?

  5. #5
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Bash script to auto-download wallpapers without RSS

    Quote Originally Posted by itismike View Post
    I understand this is attempting to put the results of the lynx and tail commands into the variable baseurl, but I'm not experienced with the context of read -r _
    And how does the < < separated by whitespace redirect?
    _ is a variable name, just like baseurl. Some people use it as a "junk variable" to ignore fields (See BashFAQ 001 for an example).

    The first < is a redirection and

    <(list) is a process substitution: http://mywiki.wooledge.org/ProcessSubstitution

  6. #6
    Join Date
    Jun 2006
    Beans
    108

    Re: Bash script to auto-download wallpapers without RSS

    Thanks for the clarification, sisco311. That explains why I was getting null values after adding -nonumbers to the lynx command. Here's what I'm using to set my background to the Experimental Aircraft Association's monthly wallpaper:
    Code:
    #!/bin/bash
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    size=1680
    dest="/usr/local/share/backgrounds/wallpaperEAA.jpg"
    read -r baseurl < <(lynx -nonumbers -listonly -dump 'http://www.eaa.org/wallpaper/' | grep -i `date +%B%g` | grep $size) &&
    wget -q "$baseurl" -O "$dest"
    Each wallpaper is uniquely-named, but follows a monthyr format: http://www.eaa.org/wallpaper/images/february13/skiplane_wallpaper1440w.jpg so I'm parsing it with grep to find the correct month and resolution for my screen.

    Save it without an extension to: /etc/cron.monthly to launch monthly.

    I dual-boot, so here's the same solution for Mac OS X:
    http://stackoverflow.com/questions/4...61053#14861053
    Last edited by itismike; February 15th, 2013 at 02:04 PM. Reason: Add path variable & link for OS X solution

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •