rogeliodh

Script to fetch news with calibre

Jan 4th, 2012
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.52 KB | None | 0 0
  1. #!/bin/bash
  2. # This is free and unencumbered shell script released into the public domain.
  3. #
  4.  
  5. ####################### Begin Customization Section #############################
  6. #
  7. # Name of the recipe to fetch. You can run:
  8. #     ebook-convert --list-recipes
  9. # to look for the correct name. Do not forget the .recipe suffix
  10. RECIPE="La Jornada (Mexico).recipe"
  11. OUTDIR="$HOME/news"
  12.  
  13. # Select your output profile. See http://manual.calibre-ebook.com/cli/ebook-convert-14.html
  14. # for a list. Common choices: kindle, kindle_dx, kindle_fire, kobo, ipad, sony
  15. OUTPROFILE="kindle"
  16.  
  17. # A text file with an email per line. This script will send an email to each one.
  18. # You can set it to "" to not send any email
  19. EMAILSFILE="$HOME/news/emails.txt"
  20.  
  21. # Your SMTP credentials
  22. SMTP="smtp.gmail.com"
  23. PORT="587"
  24. USER="username"
  25. PASSWD="password"
  26.  
  27. # A prefix for the emails' subject. The date will be appended to it.
  28. SUBJECTPREFIX="News: La Jornada"
  29. # A prefix for the emails' content. The date will be appended to it.
  30. CONTENTPREFIX="Attached is the your periodical downloaded by calibre"
  31. # A prefix for generate file. The date will be appended to it.
  32. OUTPUTPREFIX="la_jornada_"
  33. #
  34. ######################## End Customization Section #############################
  35.  
  36. DATEFILE=`date "+%Y_%m_%d"`
  37. DATESTR=`date "+%Y/%m/%d"`
  38. OUTFILE="${OUTDIR}/${OUTPUTPREFIX}${DATEFILE}.mobi"
  39.  
  40. echo "Fetching $RECIPE into $OUTFILE"
  41. ebook-convert "$RECIPE" "$OUTFILE" --output-profile "$OUTPROFILE"
  42.  
  43. # Change the author of the ebook from "calibre" to the current date.
  44. # I do this because sending periodicals to a Kindle Touch is removing
  45. # the periodical format and there is no way to differentiate between
  46. # two editions in the home screen. This way, the date is shown next
  47. # to the title.
  48. # See http://www.amazon.com/forum/kindle/ref=cm_cd_t_rvt_np?_encoding=UTF8&cdForum=Fx1D7SY3BVSESG&cdPage=1&cdThread=Tx1AP36U78ZHQ1I
  49. # and, please, email amazon ([email protected]) asking to add
  50. # a way to keep the peridiocal format when sending through @free.kindle.com
  51. # addresses
  52. echo "Setting date $DATESTR as author in $OUTFILE"
  53. ebook-meta -a "$DATESTR" "$OUTFILE"
  54.  
  55. # email the files
  56. if [ -n "$EMAILSFILE" -a -f "$EMAILSFILE" ]; then
  57.     for TO in `cat $EMAILSFILE`; do
  58.     echo "Sending $OUTFILE to $TO"
  59.     calibre-smtp --attachment "$OUTFILE" --relay "$SMTP" --port "$PORT" --username "$USER" --password "$PASSWD"  --encryption-method TLS --subject "$SUBJECTPREFIX ($DATESTR)" "$FROM" "$TO"  "$CONTENTPREFIX ($DATESTR)"
  60.     done
  61. fi
Advertisement
Add Comment
Please, Sign In to add comment