Created
September 2, 2015 15:27
-
-
Save ype/0b16bb6b8d246807d1c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| ## -*- Mode: Sh -*- ## | |
| ################################################################################ | |
| ################################################################################ | |
| ## ## | |
| ## daily_bg.sh ## | |
| ## Created: 02-09-2015 ## | |
| ## Author: Anton Strilchuk <[email protected]> ## | |
| ## URL: https://env.sh ## | |
| ## Version: ## | |
| ## Last-Updated: 02-09-2015 ## | |
| ## Update #: 57 ## | |
| ## By: Anton Strilchuk <[email protected]> ## | |
| ## ## | |
| ## Description: ## | |
| ## Fetch image for great wallpaper ## | |
| ## ## | |
| ## ## | |
| ################################################################################ | |
| ################################################################################ | |
| ## | |
| ## Code: | |
| DIR="$HOME/daily_wallpapers" | |
| LINKS="$DIR"/daily_wallpaper_links-$(date --iso=date).txt; | |
| function fetch_wallpapers() { | |
| if ! test -f "$LINKS"; | |
| then | |
| curl -sL "http://ipapers.co/daily-best" \ | |
| | hxpipe \ | |
| | sed -n 's/^Ahref CDATA //p' \ | |
| | grep -Ei 'papers\.co/[a-z]{2}[0-9]{2}' \ | |
| | sed -r 's/\/$/-22-wallpaper.jpg/g' \ | |
| | sed -r 's/\//\/wallpaper\/papers.co-/3p' \ | |
| | sed -r 's/ipapers\.co/papers.co/g' \ | |
| > "$LINKS" | |
| echo "Fetching Wallpapers" | |
| cat "$LINKS"\ | |
| | xargs -P8 -I% \ | |
| curl -# -O % 2>&1 \ | |
| | sed 's/#//g' | |
| else | |
| echo "You've already got wallpapers today?" | |
| fi | |
| } | |
| function main() { | |
| if ! test -d "$DIR" | |
| then | |
| mkdir -p "$DIR"/.old; | |
| cd "$DIR"; | |
| echo "Created ${DIR} directory" | |
| fetch_wallpapers; | |
| else | |
| cd "$DIR" | |
| mv *.{jpg,txt} "$DIR"/.old; | |
| printf "Moved Yesterdays Wallpapers to ${DIR}/.old\n\tthis is helpfully: cd ${DIR}/.old\n"; | |
| fetch_wallpapers; | |
| fi | |
| } | |
| if [[ -x $(which hxpipe) ]]; | |
| then | |
| main | |
| else | |
| printf "\n\033[33;5m\t*****************\n\t!!!DON\'T PANIC!!!\n\t*****************\033[0m\n\nYou need to install html-xml-utils\n\nOSX: brew install html-xml-utils\nLinux: duckduckgo for your pkgmanager\nor compile source: http://www.w3.org/Tools/HTML-XML-utils/\nor eat more beans: https://media.giphy.com/media/yoJC2qvU31lVmTrSmY/giphy.gif\n" | |
| fi | |
| # | |
| # daily_wallpaper.sh ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment