summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorEgidioCaprino2016-10-15 21:23:32 +0100
committerEgidioCaprino2016-10-15 21:23:32 +0100
commit0ceb207071ebec9bc35b2fe17e049453d99b0c7c (patch)
tree879235f326f7fdede1241a5d8c2b053b423008b6
downloadaur-0ceb207071ebec9bc35b2fe17e049453d99b0c7c.tar.gz
nasa-pod
-rw-r--r--.SRCINFO16
-rw-r--r--PKGBUILD29
-rw-r--r--nasa-pod.service12
-rwxr-xr-xnasa-pod.sh141
4 files changed, 198 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO
new file mode 100644
index 000000000000..4808e0307674
--- /dev/null
+++ b/.SRCINFO
@@ -0,0 +1,16 @@
+pkgbase = nasa-pod
+ pkgdesc = Systemd service and timer for fetching Nasa's picture of the day and setting it as wallpaper in Gnome.
+ pkgver = 1
+ pkgrel = 1
+ url = https://github.com/EgidioCaprino/nasa-pod
+ arch = x86_64
+ arch = i686
+ license = GPL2
+ depends = wget
+ depends = gconf
+ source = nasa-pod.service
+ source = nasa-pod.sh
+ sha256sums = SKIP
+
+pkgname = nasa-pod
+
diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
index 000000000000..3d41da11c312
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,29 @@
+# Maintainer: Egidio Caprino <egidio.caprino@gmail.com>
+
+pkgname=nasa-pod
+pkgver=1
+pkgrel=1
+pkgdesc='Systemd service and timer for fetching Nasa's picture of the day and setting it as wallpaper in Gnome.'
+license=('MIT')
+arch=('x86_64' 'i686')
+url='https://github.com/EgidioCaprino/nasa-pod'
+depends=('wget' 'gconf')
+makedepends=()
+source=(nasa-pod.sh nasa-pod.service)
+sha256sums=('SKIP')
+
+build() {
+
+}
+
+package() {
+ mkdir -p "$pkgdir/opt/"
+ mkdir -p "$pkgdir/usr/lib/systemd/user/"
+
+ cp "$srcdir/nasa-pod.sh" "$pkgdir/opt/"
+ cp "$srcdir/nasa-pod.service" "$pkgdir/usr/lib/systemd/user/"
+
+ chmod +x "$pkgdir/opt/nasa-pod.sh"
+ systemctl daemon-reload
+}
+
diff --git a/nasa-pod.service b/nasa-pod.service
new file mode 100644
index 000000000000..292300b89664
--- /dev/null
+++ b/nasa-pod.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=Download and set as wallpaper the picture of the day from Nasa.
+Wants=network-online.target
+After=network.target network-online.target
+
+[Service]
+Type=oneshot
+ExecStart=/opt/nasa-pod.sh
+
+[Install]
+WantedBy=default.target
+
diff --git a/nasa-pod.sh b/nasa-pod.sh
new file mode 100755
index 000000000000..55272e879848
--- /dev/null
+++ b/nasa-pod.sh
@@ -0,0 +1,141 @@
+#!/bin/bash
+# Copyright (c) 2011 Josh Schreuder
+# http://www.postteenageliving.com
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+
+# ********************************
+# *** OPTIONS
+# ********************************
+# Set this to 'yes' to save a description (to ~/description.txt) from APOD page
+GET_DESCRIPTION="yes"
+# Set this to the directory you want pictures saved
+PICTURES_DIR=~/Pictures
+# Set this to the directory you want description saved
+DESCRIPTION_DIR=/tmp
+
+# ********************************
+# *** FUNCTIONS
+# ********************************
+function get_page {
+ echo "Downloading page to find image"
+ wget http://apod.nasa.gov/apod/ --quiet -O /tmp/apod.html
+ grep -m 1 jpg /tmp/apod.html | sed -e 's/<//' -e 's/>//' -e 's/.*=//' -e 's/"//g' -e 's/^/http:\/\/apod.nasa.gov\/apod\//' > /tmp/pic_url
+}
+
+function save_description {
+ if [ ${GET_DESCRIPTION} == "yes" ]; then
+ echo "Getting description from page"
+ # Get description
+ if [ -e $DESCRIPTION_DIR/description.txt ]; then
+ rm $DESCRIPTION_DIR/description.txt
+ fi
+
+ if [ ! -e /tmp/apod.html ]; then
+ get_page
+ fi
+
+ echo "Parsing description"
+ sed -n '/<b> Explanation: <\/b>/,/<p> <center>/p' /tmp/apod.html |
+ sed -e :a -e 's/<[^>]*>//g;/</N;//ba' |
+ grep -Ev 'Explanation:' |
+ tr '\n' ' ' |
+ sed 's/ /\n\n/g' |
+ awk 'NF { print $0 "\n" }' |
+ sed 's/^[ \t]*//' |
+ sed 's/[ \t]*$//' > $DESCRIPTION_DIR/description.txt
+ fi
+}
+
+function clean_up {
+ # Clean up
+ echo "Cleaning up temporary files"
+ if [ -e "/tmp/pic_url" ]; then
+ rm /tmp/pic_url
+ fi
+
+ if [ -e "/tmp/apod.html" ]; then
+ rm /tmp/apod.html
+ fi
+}
+
+# ********************************
+# *** MAIN
+# ********************************
+echo "===================="
+echo "== APOD Wallpaper =="
+echo "===================="
+# Set date
+TODAY=$(date +'%Y%m%d')
+
+# If we don't have the image already today
+if [ ! -e ~/Pictures/${TODAY}_apod.jpg ]; then
+ echo "We don't have the picture saved, save it"
+
+ get_page
+
+ # Got the link to the image
+ PICURL=`/bin/cat /tmp/pic_url`
+
+ echo "Picture URL is: ${PICURL}"
+
+ echo "Downloading image"
+ wget --quiet $PICURL -O $PICTURES_DIR/${TODAY}_apod.jpg
+
+ echo "Setting image as wallpaper"
+ gsettings set org.gnome.desktop.background picture-uri file:///$PICTURES_DIR/${TODAY}_apod.jpg
+
+ save_description
+
+# Else if we have it already, check if it's the most updated copy
+else
+ get_page
+
+ # Got the link to the image
+ PICURL=`/bin/cat /tmp/pic_url`
+
+ echo "Picture URL is: ${PICURL}"
+
+ # Get the filesize
+ SITEFILESIZE=$(wget --spider $PICURL 2>&1 | grep Length | awk '{print $2}')
+ FILEFILESIZE=$(stat -c %s $PICTURES_DIR/${TODAY}_apod.jpg)
+
+ # If the picture has been updated
+ if [ $SITEFILESIZE != $FILEFILESIZE ]; then
+ echo "The picture has been updated, getting updated copy"
+ rm $PICTURES_DIR/${TODAY}_apod.jpg
+
+ # Got the link to the image
+ PICURL=`/bin/cat /tmp/pic_url`
+
+ echo "Downloading image"
+ wget --quiet $PICURL -O $PICTURES_DIR/${TODAY}_apod.jpg
+
+ echo "Setting image as wallpaper"
+ gconftool-2 -t string -s /desktop/gnome/background/picture_filename $PICTURES_DIR/${TODAY}_apod.jpg
+
+ save_description
+
+ # If the picture is the same
+ else
+ echo "Picture is the same, finishing up"
+ fi
+fi
+
+clean_up