Skip to content

Commit 5ad3af8

Browse files
committed
Merge pull request #1 from ed-flanagan/master
It is wonderful outside, we are in the middle of the Steam Summer sale, and you are spending your time rewriting a bunch of code that I wrote as a one-off project 9 months ago that no one (including me) even uses? ಠ_ಠ Get it together Ed.
2 parents 69a921f + e1e8e25 commit 5ad3af8

File tree

6 files changed

+75
-15
lines changed

6 files changed

+75
-15
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
bingimg
2+
=======
3+
4+
scrapes the bing image of the day in bash

archive/MTShasta.jpg

-171 KB
Binary file not shown.

archive/MagnificentTreeFrog.jpg

-168 KB
Binary file not shown.

archive/OkanaganPears.jpg

-175 KB
Binary file not shown.

bingimg.sh

+62-15
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,67 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

3-
cd ~/bingimg
3+
help_msg() {
4+
echo "Usage: $0 [-h] [-a dir] [-d path] [-n name]"
5+
echo "Options:"
6+
echo " -a <dir> archive picture in given directory"
7+
echo " -d <path> destination of picture (default's current directory)"
8+
echo " -h display this message"
9+
echo " -n <name> choose name for picture"
10+
}
411

5-
wget -q www.bing.com
6-
BINGPIC="$(cat index.html | grep g_img={url: | sed -e s/.*g_img={url:\'// | sed 's/\.jpg.*//')"
7-
ADDRESS="www.bing.com"
8-
ADDRESS+=$BINGPIC
9-
ADDRESS+=".jpg"
10-
#echo $ADDRESS
11-
wget -q $ADDRESS
12+
while getopts ":a:d:hn:" opt; do
13+
case $opt in
14+
a)
15+
ARCHIVE=$OPTARG
16+
if [[ ! $ARCHIVE =~ ^.*\/$ ]]; then
17+
ARCHIVE=$ARCHIVE"/"
18+
fi
19+
if [ ! -d "$ARCHIVE" ]; then
20+
echo "No such directory: $ARCHIVE"
21+
exit 1
22+
fi
23+
;;
24+
d)
25+
DEST="$OPTARG"
26+
if [[ ! $DEST =~ ^.*\/$ ]]; then
27+
DEST=$DEST"/"
28+
fi
29+
if [ ! -d "$DEST" ]; then
30+
echo "No such directory: $DEST"
31+
exit 1
32+
fi
33+
;;
34+
h)
35+
help_msg
36+
exit 0
37+
;;
1238

13-
FILE=$(echo $ADDRESS | cut -d '/' -f 5)
14-
DEST=$(echo $FILE | cut -d '_' -f 1)
15-
DEST+=".jpg"
39+
n)
40+
FILE=$OPTARG
41+
;;
42+
\?)
43+
echo "Invalid option -$opt" >&2
44+
help_msg
45+
exit 1
46+
;;
47+
:)
48+
echo "Option -$opt requires an argument" >&2
49+
help_msg
50+
exit 1
51+
;;
52+
esac
53+
done
1654

17-
rm index.html
18-
mv $FILE archive/$DEST
55+
URL="www.bing.com"
56+
ADDRESS=$URL$(curl -s $URL | grep g_img={url: | sed -e s/.*g_img={url:\'// | sed 's/\.jpg.*//')".jpg"
57+
NAME=$(echo $ADDRESS | awk -F/ '{print $(NF)}' | cut -d _ -f 1)".jpg"
1958

20-
cp archive/$DEST /var/www/bing.jpg
59+
curl -so $DEST$NAME $ADDRESS
60+
61+
if [ -n "$ARCHIVE" ]; then
62+
cp $DEST$NAME $ARCHIVE
63+
fi
64+
65+
if [ -n "$FILE" ]; then
66+
mv $DEST$NAME $DEST$FILE
67+
fi

classic_bingimg.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
URL="www.bing.com"
4+
ADDRESS=$URL$(curl -s $URL | grep g_img={url: | sed -e s/.*g_img={url:\'// | sed 's/\.jpg.*//')".jpg"
5+
NAME=$(echo $ADDRESS | awk -F/ '{print $(NF)}' | cut -d _ -f 1)".jpg"
6+
7+
curl -so archive/$NAME $ADDRESS
8+
9+
cp archive/$NAME /var/www/bing.jpg

0 commit comments

Comments
 (0)