View Single Post
Old 08-21-2020, 12:12 AM   #1
biffhero
Junior Member
biffhero began at the beginning.
 
Posts: 8
Karma: 10
Join Date: Aug 2020
Device: kobo libre h20
News export to Kobo with templates

I subscribe to 120+ news sites, so after four days, there are 500 articles in one directory.

If I want to read articles from today before moving on to yesterday's news, I have to scroll and scroll and scroll. You get the picture. :-)

I fought with templates for a couple of hours today, before giving up and writing a shell script. This is what I wrote:

Code:
#!/bin/bash

#
# take care of the news files in the kobo directory
#

NEWSPATH="/media/rob/KOBOeReader/News/"

function findNewsDir() {
    path=${1}
    if [[ -e "${path}" ]]
    then
        REPLY="yes"
    else
        REPLY="no"
    fi
}

function main() {
    # newsDir=findNewsDir ${NEWSPATH}
    findNewsDir ${NEWSPATH}
    if [[ ${REPLY} == "yes" ]]
    then
        echo "Found the news directory"
        echo "It is ${NEWSPATH}"
        echo "getting dates now"
        for date in $(ls "${NEWSPATH}" | rev | cut -f 3- -d "." | cut -f 1 -d "_" | rev | sort -u)
        do
            {
                echo "Date : ${date}"
                if [[ ! -e "${NEWSPATH}${date}" ]]
                then
                    echo "date dir for ${date} does not exist"
                    printf "making directory - %s" "${NEWSPATH}${date}/"
                    mkdir "${NEWSPATH}${date}/"
                fi

                echo "date dir for ${date} exists"
                OLDIFS="${IFS}"
                IFS=$'\n'
                for article in $(ls "${NEWSPATH}" | grep ${date}.kepub.epub$)
                do
                    {
                        printf "article - %s\n" "${article}"
                        echo "I want to move article : \"${article}\""
                        echo "to"
                        echo "${NEWSPATH}${date}/"
                        echo
                        mv "${NEWSPATH}${article}" "${NEWSPATH}${date}/"
                    }
                done
                IFS="${OLDIFS}"
            }
        done
    else
        echo "Cannot find the news directory, exiting"
        exit 1
    fi
}

main
I'm sure there is a better way, but I don't know what it is, and I can't get a template to do it. I have made two columns out of information I found on other posts, or on stackoverflow, or something.

1. news_date : {date:'test($,
strcat(format_date($,'yyyy'), '_',format_date($,'MM'), '_',format_date($,'dd')),
'')'}

2. test_date : {authors:contains(calibre, {#news_date},)}

I figured I would use a device template that had /{#test_date} in it, but that never seemed to work. I'm guessing at this point that there is different code paths for exporting News/ articles and other things.

Thanks,
Rob
biffhero is offline   Reply With Quote