p2k
p2k copied to clipboard
A Rails application that sends articles from your Pocket to Kindle
P2K (Pocket to Kindle)
P2K (Pocket to Kindle) is a Rails application that sends articles from your Pocket to Kindle e-reader.
Currently live at http://p2k.co
Author: Emir Aydin - http://emiraydin.com
Personal Note: This is my first 'official' Rails app, so if you spot any problems or you know a better practice, please let me know.
Setup Instructions
To make this application run, you'll need to add 2 more files that I couldn't put in this repo since they contain sensitive infomation.
1. config/application.yml
This file stores all your application passwords and constants. Get your Pocket API key here: http://getpocket.com/developer/
Create a file named application.yml inside /config folder. It should look something like this:
# config/application.yml
# This file stores all the application constants
defaults: &defaults
POCKET_CONSUMER_KEY: "YOUR_POCKET_API_KEY"
READABILITY_PARSER_KEY: "YOUR_READABILITY_API_KEY"
DIFFBOT_API_KEY: "YOUR_DIFFBOT_API_KEY"
DELIVERY_EMAIL_SMTP: "smtp.mymailprovider.com"
DELIVERY_EMAIL_PORT: portnumber
DELIVERY_EMAIL_ADDRESS: "[email protected]"
DELIVERY_EMAIL_PASSWORD: "passfor-delivery@myapp"
MANDRILL_API_KEY: "YOUR_MANDRILL_API_KEY"
development:
<<: *defaults
APP_PATH: "http://localhost:3000"
POCKET_REDIRECT_URI: "http://localhost:3000/welcome/home"
DATABASE_HOST: "localhost"
DATABASE_USERNAME: "my-db-username"
DATABASE_PASSWORD: "my-db-password"
test:
<<: *defaults
DATABASE_HOST: "localhost"
DATABASE_USERNAME: "my-test-username"
DATABASE_PASSWORD: "my-test-password"
production:
<<: *defaults
APP_PATH: "http://myapp.com"
POCKET_REDIRECT_URI: "http://myapp.com/welcome/home"
DATABASE_HOST: "SOME IP"
DATABASE_USERNAME: "my-db-username"
DATABASE_PASSWORD: "my-db-password"
2. config/secrets.yml
This file contains application secrets for all your Rails environments. You can generate them using rake secret command.
development:
secret_key_base: PUT-SOME-HASH-HERE
test:
secret_key_base: PUT-SOME-HASH-HERE
# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
Dependencies
1. Kindlegen application
We need Kindlegen application to parse our ebook into MOBI format, which will then be delivered to the users. I'm using the Kindlerb gem to download and operate the Kindlegen executable, so please make sure you follow the gem documentation here for setup: https://github.com/emiraydin/kindlerb.
2. ImageMagick for image compression and optimization
This application uses [ImageMagick] (http://www.imagemagick.org/script/binary-releases.php) to optimize and compress images before putting it into a Kindle supported ebook file. You'll need the ImageMagick binaries in order to make the convert command work.
3. Parsing Articles
I'm using Diffbot Article API and Readability Parser API interchangeably to parse articles properly before sending them to Kindle. Make sure you get your API keys and put them in your config/application.yml as shown above.
4. Cron jobs for deliveries
This application uses [whenever] (https://github.com/javan/whenever) gem to run cron jobs for deliveries.
You need to run the command whenever -i inside your application directory in order to update your crontab file and start deliveries.
If you don't want to use whenever gem, you can use Unix cronjobs by typing the command crontab -e and adding the line below:
0 * * * * /home/username/cronjob.sh >> /home/username/logfile.log 2>&1
Your cronjob.sh will look something like this:
#!/bin/bash
# Add Ruby to PATH (necessary for some installations)
export PATH=$PATH:/usr/local/bin
# Run the delivery processor
cd /home/username/app && rails runner -e production "DeliveryProcessor.check"
License

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.