Created
April 29, 2012 13:53
-
-
Save repomaa/2550545 to your computer and use it in GitHub Desktop.
Fetches news from calibre recipes and sends them to your kindle. Cronjobbable.
This file contains 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
#!/bin/sh | |
# ---------------------------------------------------------------------------- | |
# Written by Joakim Reinert <http://digital-adventures.de> | |
# (c) 2012 Joakim Reinert under GNU GPL v3.0+ | |
# Last updated on: Apr/29/2012 by Joakim Reinert | |
# ---------------------------------------------------------------------------- | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
# Requirements: calibre, Xvfb and zip or p7zip | |
# Usage: | |
# 1. Create a new directory under your home directory and copy this file inside. | |
# 2. IMPORTANT: chmod 700 fetchnews4kindle.sh | |
# because your smtp password is stored in plain text | |
# 3. Create a new directory in the one you created before and call it recipes | |
# 4. Copy the recipes for all the news you want to fetch into that folder | |
# 5. Set the variables below | |
# 6. Test the script and if it works | |
# 7. run crontab -e and schedule the execution of the script | |
############################################################################### | |
kindle_mail=yourusername@kindle.com | |
from_mail=yourusername@yourdomain.com | |
smtp_user=yourusername | |
smtp_password=yourpassword | |
smtp_server=your.smtp.server | |
#Change if necessary | |
smtp_port=465 | |
#TLS,SSL or NONE | |
#you shouldn't use NONE here | |
smtp_encryption=SSL | |
############################################################################### | |
mail_string="calibre-smtp -r $smtp_server --port=$smtp_port -u $smtp_user -p $smtp_password -e $smtp_encryption -s \"News\" " | |
zip_file="news_`date +%F`.zip" | |
compress_command="zip $zip_file mobi/*.mobi" | |
if [ "`which zip`" == "" ]; then | |
echo "zip not installed! Trying p7zip..." | |
if [ "`which 7z`" == "" ]; then | |
echo "Neither zip nor p7zip installed! Exiting." | |
exit 1 | |
else | |
compress_command="7z a -tzip $zip_file mobi/*.mobi" | |
fi | |
fi | |
if [ ! -d ~/calibre\ news ]; then | |
mkdir ~/calibre \news | |
fi | |
cd ~/calibre\ news | |
if [ ! -d mobi ]; then | |
mkdir mobi | |
fi | |
if [ ! -d recipes ]; then | |
mkdir recipes | |
fi | |
Xvfb :100 -ac & | |
display_bak=$DISPLAY | |
export DISPLAY=:100.0 | |
empty=1 | |
for file in recipes/*.recipe; do | |
basename=${file##*/} | |
ebook-convert "$file" mobi/${basename%.*}.mobi | |
empty=0 | |
done | |
rm news*.zip | |
zip_file="news_`date +%F`.zip" | |
zip $zip_file mobi/*.mobi | |
mail_string="$mail_string -a $zip_file $from_mail $kindle_mail News" | |
killall Xvfb | |
export DISPLAY=$display_bak | |
if [ $empty == 1 ]; then | |
echo "No recipes to fetch!" | |
exit 1 | |
fi | |
$mail_string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment