From 742ff31bd832e796c2cf2322e4b576d71b6bd9a7 Mon Sep 17 00:00:00 2001 From: Eli Saado Date: Sun, 1 Apr 2018 21:48:33 +0200 Subject: [PATCH 1/5] (almost?) finish bash port --- download_daemon | 2 +- downloader.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100755 downloader.sh diff --git a/download_daemon b/download_daemon index af99835..a6a7cf9 100755 --- a/download_daemon +++ b/download_daemon @@ -11,7 +11,7 @@ while : ; do # If no, wait 300 secs and check again. [[ `< $HOME/.config/lock_screen.sta` -eq 0 ]] && sleep 300 && continue # Download the new image - $HOME/i3lock-delta/downloader.php + $HOME/i3lock-delta/downloader.sh if [[ $? -eq 0 ]]; then name_photographer="`< /tmp/name_photographer`" diff --git a/downloader.sh b/downloader.sh new file mode 100755 index 0000000..d2db181 --- /dev/null +++ b/downloader.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +# Get the api key +key=$(cat ~/i3lock-delta/api_key) +# Get the queries +queries=$(cat ~/.config/lock_preferences | xargs) +# Construct the base url +url="https://api.unsplash.com/photos/random?client_id=$key&orientation=landscape&featured=false" + +# Check if there are any queries +if [ -n "$queries" ]; then + url="$url&query=$(shuf -n 1 ~/.config/lock_preferences)" +fi + +# make API call and check if curl fails +if ! json=$(curl -s $url); then + exit 1 +fi + +# Get image location from json +image_url=$(echo $json | jq -r ".links.download_location") + +# Download image and check if curl fails +curl $image_url > ~/.rand_bg +if [[ $? -ne 0 ]] ; then exit 1; fi + +# Write author's name to file +user_name=$(echo $json | jq -r ".user.name") +echo "$user_name" > /tmp/name_photographer From d6bcb8f531fbf9497095add3350df7efaa7efa73 Mon Sep 17 00:00:00 2001 From: Ceda EI <19731116+Ceda-EI@users.noreply.github.com> Date: Mon, 2 Apr 2018 01:37:34 +0530 Subject: [PATCH 2/5] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f9be2b2..28bbc28 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ This prorgam downloads a new image from [Unsplash][1]. It checks whether the scr ## Dependencies -+ [PHP][2] - Available in repositories of most popular distributions. -+ [Composer][3] - Available in repositories of most popular distributions. ++ [jq][2] - Needed for parsing JSON. ++ [curl][3] - Available in most software repositories. Also, most probably installed already. + [Imagemagick][4] - Specifically, the `convert` command. + [i3lock-color][5] - Available in AUR (For Arch users). Fork of i3lock with more features. Do not use i3lock since this program utilizes the features of i3lock-color. + [bash][6] - Most probably will be installed already. @@ -49,8 +49,8 @@ The lock screen customization has been made easier using `~/.config/lock_prefere [1]: https://unsplash.com -[2]: https://php.net -[3]: https://getcomposer.org +[2]: https://stedolan.github.io/jq/ +[3]: https://curl.haxx.se [4]: https://imagemagick.org [5]: https://github.com/PandorasFox/i3lock-color [6]: https://www.gnu.org/software/bash/ From 8316582269cebf3c551b40c457e75ba569ffe4c6 Mon Sep 17 00:00:00 2001 From: Ceda EI <19731116+Ceda-EI@users.noreply.github.com> Date: Mon, 2 Apr 2018 01:52:18 +0530 Subject: [PATCH 3/5] Fix downloader.sh. Added another curl to get the URL of the image. --- downloader.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/downloader.sh b/downloader.sh index d2db181..da97d8e 100755 --- a/downloader.sh +++ b/downloader.sh @@ -18,7 +18,10 @@ if ! json=$(curl -s $url); then fi # Get image location from json -image_url=$(echo $json | jq -r ".links.download_location") +image_download_url=$(echo $json | jq -r ".links.download_location") +image_download_url="$image_download_url?client_id=$key" +image_url=$(curl -s $image_download_url | jq -r .url) +if [[ $? -ne 0 ]] ; then exit 1; fi # Download image and check if curl fails curl $image_url > ~/.rand_bg From 52bb6091d4b0575c28c659718da32722e2206ade Mon Sep 17 00:00:00 2001 From: Ceda EI <19731116+Ceda-EI@users.noreply.github.com> Date: Mon, 2 Apr 2018 01:56:25 +0530 Subject: [PATCH 4/5] Update install script. Removed php and composer checks. Added jq and curl checks. Removed library installs. --- install | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/install b/install index 83d2102..80c78bf 100755 --- a/install +++ b/install @@ -17,8 +17,8 @@ function check_exec() { echo -e "${blue}Checking Dependencies $reset" -check_exec php PHP -check_exec composer Composer +check_exec jq jq +check_exec curl curl check_exec i3lock i3lock-color check_exec convert Imagemagick @@ -33,16 +33,6 @@ else echo "OK" fi echo -e "${blue}Checked repository location $reset \n" -echo -e "${blue}Installing Libraries $reset" -sleep 1 -composer install -if [[ $? -ne 0 ]]; then - echo -e "$red Unable to install libraries. Check your internet connection" - echo -e "If the problem persists, open an issue at https://github.com/Ceda-EI/i3lock-delta/issues" - echo -e "$reset" -fi - -echo -e "${blue}Finished Installing Libraries $reset \n" echo -e "${blue}Creating Required Files$reset" From 7f115f3d68caf7ae1b82986c80b87a6aa8f5d324 Mon Sep 17 00:00:00 2001 From: Ceda EI <19731116+Ceda-EI@users.noreply.github.com> Date: Mon, 2 Apr 2018 01:59:07 +0530 Subject: [PATCH 5/5] Delete .gitignore, composer.json, downloader.php --- .gitignore | 2 -- composer.json | 5 ----- downloader.php | 46 ---------------------------------------------- 3 files changed, 53 deletions(-) delete mode 100644 .gitignore delete mode 100644 composer.json delete mode 100755 downloader.php diff --git a/.gitignore b/.gitignore deleted file mode 100644 index d1502b0..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -vendor/ -composer.lock diff --git a/composer.json b/composer.json deleted file mode 100644 index 11acbd8..0000000 --- a/composer.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "require": { - "crewlabs/unsplash": "^2.4" - } -} diff --git a/downloader.php b/downloader.php deleted file mode 100755 index 6639774..0000000 --- a/downloader.php +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env php - file_get_contents(getenv('HOME').'/i3lock-delta/api_key'), - 'utmSource' => 'i3lock-Delta' -]); - -# Get custom search queries -$queries_file_name = getenv('HOME') . '/.config/lock_preferences'; -$queries = file($queries_file_name); - -# Create the random photo limitations -if (count($queries) == 0){ - $filters = [ - 'featured' => false, - 'orientation' => 'landscape' - ]; -} -else { - $filters = [ - 'featured' => false, - 'query' => $queries[rand(0,count($queries) - 1)], - 'orientation' => 'landscape' - ]; -} - -# Get the random photo -$img = Crew\Unsplash\Photo::random($filters); - -# Download the photo -$url = $img->download(); -$output = file_get_contents($url); - -# Write image to a file -$image_filename =getenv('HOME') . '/.rand_bg'; -$image_file = fopen($image_filename, 'w'); -fwrite($image_file, $output); -fclose($image_file); - -# Write author's name to a file -$name_file = fopen('/tmp/name_photographer', 'w'); -fwrite($name_file, $img->{'user'}['name']); -fclose($name_file);