Learn how to create Python File to Convert a Blog into an ePub Book

in #utopian-io6 years ago (edited)

Contribution to the Open Source Project: Calibre


calibrehome2.jpg

Github Repository:

https://github.com/kovidgoyal/calibre

Learn how to create a Python File for the Calibre software to Turn a Blog into an ePub Book

What Will I Learn?

5 Major Concepts:

  • Learn how to use "my prepared template" as your base to create your own Python File for a Blog
  • Learn how to customize your own Python programming file for a particular blog
  • Learn how to get the RSS feeds from the blog for the programming codes
  • Learn how to create the .Recipe file extension & store into your Calibre Software
  • Learn how to Convert a blog into an ePub Book with Calibre using the Fetch News Widget

Requirements

  1. System Requirements: Install Calibre Software 3.23 (updated on May 4, 2018)
  2. OS Support:
  • Windows (Vista, 7, 8 and 10)
  • Linux (32-bit and 64-bit Intel
  • Mac OS X (10.9 Mavericks and higher)

Read the Calibre page and download their software onto your computer.
After download, click execute and start using this software following today's tutorial.

Resources about Calibre:

Difficulty

Intermediate to Advanced

A. Description

There are some great blogs that we subscribe to on the net. What if I tell you that you can turn your favorite blog into an eBook to read offline? This is too good to be true, isn't it?

Some of the blogs that we subscribe to have great content. If we know how to turn these blogs into eBooks, our personal Library will have great resources.

EBooks with a Table of Content on the side makes it very easy for us to navigate as everything is hyperlinked with HTML in our eBook. This is where Calibre shines because we can create eBooks easily using this software.

Since we are dealing with downloading blogs from websites, we are required to create Python program files to execute this task.

Today's tutorial involves more technical points regarding 'Python coding", but I have made the tutorial simple enough by creating a ready-prepared template for you to use. From my template, I will guide you through the steps to create a new Blog Python file without the need of learning programming at all. After I show you where you can make the changes accordingly on the template, you can then upload the new Python file into the Calibre Software to turn a blog into an eBook.

B. Some Advanced Concepts You need to Understand

Calibre software has a feature that holds Python Codes to 1617 news websites of about 50 countries with 30 languages. Some popular sites like CNN, Times, NY Times are coded with Python Templates that are called 'Recipes'. Therefore 1617 Python Recipes are already built into the Calibre system.

BuiltInRecipes.jpg


  • These Recipes are programmed with Python languages so that the Calibre software can schedule these web sites to run automatically to download the news for you so that you can turn the news site into ePub Books.

  • These Python Codes are actually a set of instructions written and prepared by the project owner and the team. They are codings and commands with a set of variables such as URLs to give Calibre enough information to download the content from the net.

  • We will take the first example of the News Hola (Spanish News). When you click on the above 'built in Recipe' for Hola, the Script for the Python code will come up like this:

HolaExample.jpg

  • The above are Python codes that are programmed into the Calibre software so that you can download the Hola News from the Hola News website when you click on the Hola Tab.

  • The three arrows show you the command lines in Python coding language to instruct the software to download the news.

I have taken some time to explain to you the entire concept behind the "Fetch News" Widget.

C. Transfer this Concept to download blogs

  • While the Calibre software has the 'Fetch News" features for 1617 news sites, it does not have a widget to 'Fetch Blogs'.

  • But the idea should work the same, since all blogs and websites are HTML based. If we can download news websites with these Python Files, we should be able to write new Python files to download blogs.

  • Almost any RSS feed can be converted into an eBook also, therefore all we need to do is to search for the RSS feed URL of a blog to put into the Python File to execute the download.

  • With the above information, we can create these Python files to turn a Blog to an ePub Book providing there is RSS feeds on the blog.


D. Calibre has a feature: Create NEW RECIPE

There is a feature within the Calibre software that allows programmers to create Python files to upload onto the Calibre software to execute more difficult tasks.

newrecipe.jpg

The New Recipe Tab tells us that we can actually create our own Python files.

This is where the flexibility of Calibre software shines. If we have programming skills, we can actually extend Calibre to higher functions to execute more tasks.

When we have created these new Python files, we can actually submit them to the Calibre Open Source Github Repository site.

E. Python Code Files need to have .Recipe extension

  1. Since this video tutorial is not about learning Python Coding, you do not really need to know how to write commands and programming lines in this tutorial.

  2. I have prepared a "Template" with all the Python commands lines for you to use so that you don't need to write the programming codes yourself yet be able to execute the higher function of downloading blogs.

  3. In this video tutorial, you can use my Ready made Template with .Recipe File to create your own Recipe File with the correct Python Codes so as to be able to turn a blog into an ePub book.

  4. I will zero in on the few places in the commanding lines where you can just replace the codes for your specific blog you wish to download.

F. Extra Resource: Download my "Rosa Template" Python File from Gist Github

  1. You can see my Source Code to create your Recipe File
  2. https://gist.github.com/rosatravels/e51d603003db5a1e59bd6a882dbb3d22
  3. Download my template at the right upper hand corner: Download Zip
  4. Unzip and use the RosaTemplate.Recipe file to create your new Recipe file
  5. You must use .Recipe extension files for Calibre to execute the task.

Step 1: Load my Python File (RosaTemplate.Recipe) into Calibre

a. Go to Fetch News Widget
b. Add or Edit a Custom new source

The following screen will pop up for you to load my Python File Template:

template3.jpg

  • This is the area that you are going to load my "RosaTemplate.Recipe" .
  • Click to Upload recipe from computer
  • After my template is uploaded, you can then use my template to create your Blog Python File from there.

Step 2: Understand Python Codes in the RosaTemplate.Recipe File

You will see the programming codes showing up in this format:

template1.jpg

  • This is Python Coding with lots of indentation, and they are very important, so don't change any of these spacings.
  • Fortunately, there are only 14 lines so it is very easy for you to follow
  • I will divide this Python Codes into 3 Sections to explain to you what you need to do.
  • Even though you don't know Python programming language, you should be able to follow easily with my directed instructions.

Step 3: Create your Python File of a Blog from my Template

The First Section


#!/usr/bin/env python2
# vim:fileencoding=utf-8
from __future__ import unicode_literals, division, absolute_import, print_function
from calibre.web.feeds.news import BasicNewsRecipe

The most important command line is:

from calibre.web.feeds.news import BasicNewsRecipe

Calibre software will generate ebooks from web feeds with this command.
There is nothing you need to change here.


The Second Section

Title and the Number of articles

class AdvancedUserRecipe1525856516(BasicNewsRecipe):
    title          = 'Rosa Template'
    oldest_article = 7
    max_articles_per_feed = 100
    auto_cleanup   = True

In this section, you need to change 3 things:

  • Change "Rosa Template" to "Name of your Blog you wish to download"
  • oldest_article = 7 (Change 7 to your number)
  • max_articles_per_feed = 100 (Key in the number of articles you want)

The Third Section

Key in the sub titles + RSS feed URL of the Blog

    feeds          = [
        ('Learn Piano With Rosa', 'http://learnpianowithrosa.com/'),
    ]

Keep all the indentation there and don't change them.

In this section, you need to change 2 things:



Video Tutorial - Create a Python File to Convert a Blog into an ePub Book

In this Video, I will give a demo of how I generate an ePub Book of a specific Blog

  • Since you are learning about Calibre, you might as well turn their blog into an ePub Book as they contain a lot of "Calibre tips and tricks".
  • What they show you on the Blog, I don't teach because you can easily get the material from their blog.
  • This blog will be a good resource for your eLibrary.
  • In my demo, we will turn Calibre Blog (http://blog.calibre-ebook.com/) into an ePub Book.

The Following Steps will be shown in the Video:

  1. Learn how to create a Calibre Blog Python File using my Template
  2. Learn how to make the necessary changes to create CalibreBlog.Recipe File
  3. Learn how to get the RSS feed from the Calibre Blog
  4. Learn how to use the CalibreBlog.Recipe to generate an ePUB Book
  5. Understand that the concept behind downloading blogs is the same as downloading news as websites are all HTML based.

Proof of Work: Calibre Blog Turned into a ePUB Book

You can download the Calibre Blog ePub Book from my Github Site:

==> Download Calibre Blog ePub Book


Curriculum:

Please follow the Series of Videos on Calibre:

Thank you for your time and kind attention,

Rosa

@rosatravels


Hope you like reading this post!

谢谢你的阅读!希望你喜欢。

Sort:  

Excellent Video Tutorial, Rosa. This is a very useful tool for users of Calibre. Thank you for your great work.

Your use of text and graphic over-lays in your tutorial is very effective.

The pace of your voice is also very effective. You take your time in presenting items. Other content creators can improve their contributions by imitating your speaking pace.

Other Open Source applications have processes that allow users can create and/or customize with their own code. I think that end-users could benefit from more tutorials like this.

Your contribution has been evaluated according to Utopian rules and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post,Click here


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thanks @buckydurddle for reviewing my contribution. I am following your great example set before us. Great to be in this video tutorial team to contribute in this area that I had forgotten for months.

Hey @rosatravels
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Contributing on Utopian
Learn how to contribute on our website or by watching this tutorial on Youtube.

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Thank you @uotpian-io, you rock :)

Congratulations! This post has been upvoted from the communal account, @minnowsupport, by rosatravels from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, theprophet0, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows. Please find us at the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.

If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP.
Be sure to leave at least 50SP undelegated on your account.

Coin Marketplace

STEEM 0.35
TRX 0.12
JST 0.040
BTC 70733.96
ETH 3563.16
USDT 1.00
SBD 4.76