#!/bin/sh
#
# Import given txt-files into dayone
# Files are generated by IFTTT-service
#
# Author: Stefan Zweifel <https://stefanzweifel.io>

# Modify the following variable to your needs. The folder should only contain log-files
LOGDIR='up-logs/'

###############################
# DO NOT EDIT BELOW THIS LINE #
###############################

cd $LOGDIR;

for D in *; do

    echo "Read file:" $D;

    DATE=$( echo $D | cut -d'-' -f 1;)
    MONTH=$( echo $D | cut -d'_' -f 1;)
    DAY=$( echo $D | cut -d'_' -f 2;)
    YEAR=$( echo $DATE | tail -c 5;)

    # Get fullpath of dayone binary
    COMMAND=$( which dayone;)

    # Add to Dayone
    $COMMAND -d="$MONTH/$DAY/$YEAR" new < $D

    # Remove File from Disk
    rm $D

done

echo "Done!"
#!/bin/sh
#
# Import given txt-files into dayone
# Files are generated by IFTTT-service
#
# Author: Stefan Zweifel <https://stefanzweifel.io>

# Modify the following variable to your needs. The folder should only contain log-files
LOGDIR='up-logs/'

###############################
# DO NOT EDIT BELOW THIS LINE #
###############################

cd $LOGDIR;

for D in *; do

    echo "Read file:" $D;

    DATE=$( echo $D | cut -d'-' -f 1;)
    MONTH=$( echo $D | cut -d'_' -f 1;)
    DAY=$( echo $D | cut -d'_' -f 2;)
    YEAR=$( echo $DATE | tail -c 5;)

    # Get fullpath of dayone binary
    COMMAND=$( which dayone;)

    # Add to Dayone
    RESULT=$( $COMMAND -d="$MONTH/$DAY/$YEAR" new < $D )

    # Check if Import worked as expected
    # Dayone CLI return as message, which begins with "New Entry"
    if [[ $RESULT == New* ]] ;
    then

        echo $RESULT;
        # Remove File from Disk
        rm $D

    else
        echo "Something went wrong.";
    fi

done

echo "Done!"
Check if import was successfull
Check if import was successfull

Don't delete files, if we can't import them.
