├── README.md ├── Import2DayOne.sh └── Split.sh /README.md: -------------------------------------------------------------------------------- 1 | Split.sh is the first of two scripts that will import a bunch of text files 2 | formated in Markdown as Day One entries. 3 | 4 | In order to work, each file name must start with AAAA-MMDD (wich will be as 5 | the date of the entries) and contain only one entry. So if, like me, you 6 | used to write a day worth of entries in a single file, like this: 7 | 8 | 2012-0816-J-my daily diary.txt: 9 | 10 | ### 17H32 11 | Some text. 12 | 13 | ### 23h41 14 | Some more text. 15 | ![alt text](link to an image) 16 | 17 | Some more text. 18 | 19 | ### some title but no time stamp 20 | Some text, again. 21 | 22 | this script will look for occurences of ## or ### (or none, at the first 23 | line of the file) and, for each one consisting of a time stamp, will create 24 | a new file. (other ### will be added to the previous time stamp). 25 | So the example will look like this after spliting: 26 | 27 | 2012-0816-J-my daily diary1.txt: 28 | 29 | ### 17H32 30 | Some text. 31 | 32 | 2012-0816-J-my daily diary2.txt: 33 | 34 | ### 23h41 35 | Some more text. 36 | 37 | ![alt text](link to an image) 38 | 39 | Some more text. 40 | 41 | ### some title but not a time stamp 42 | Some text, again. 43 | 44 | Each new file will be created in a temporay export folder 45 | ("~/Desktop/output"). This folder *must* exist before running the script. 46 | 47 | The second script, Import2DayOne.sh, will deal with the import process 48 | itself, using Day One CLI. -------------------------------------------------------------------------------- /Import2DayOne.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # http://davidbosman.fr || david@davidbosman.fr || août 2012. 4 | # Feel free to modify and repost. 5 | # 6 | # This script is the second of two that will import a bunch of text files 7 | # formated in Markdown as Day One entries. 8 | # 9 | # In order to work, it requires Day One's CLI: 10 | # http://dayoneapp.com/tools/ 11 | # 12 | # It takes txt files in entry, with the name formated as: 13 | # dont le nom commence par AAAA-MMJJ. 14 | # 15 | # For each file, it'll create a new entry ion Day One, using the file name 16 | # to set the date. 17 | # It'll use the time in the title to det the time. 18 | 19 | for i in * 20 | do 21 | 22 | # format entry time 23 | time=`awk '/^##[#]?[ ]?[0-9][0-9]?[h:]/ {print $2}' "$i"` 24 | 25 | # Check we have a number to defin time 26 | if ! [[ "$time" =~ ^[0-9] ]] 27 | # If not a number 28 | then 29 | # We let Day One deal with the time 30 | TIMEFORMATED="" 31 | else 32 | # We got a time. We're so happy! 33 | # If time is a 3 digits+separator "h" ou ":": 9h10 34 | if [ "${time:1:1}" == "h" ] || [ "${time:1:1}" == ":" ] 35 | then 36 | # we add a 0 before the first digit, to make it four. 37 | HOUR=0${time:0:1} 38 | MIN=${time:2:2} 39 | else 40 | # if it is a 4 digit time + separator "h" ou ":" : 09h27 41 | HOUR=${time:0:2} 42 | MIN=${time:3:2} 43 | fi 44 | # If minutes are not on 2 digits 45 | # Minutes are set to 00 46 | if ! [[ "$MIN" =~ ^[0-9][0-9]$ ]] 47 | then 48 | MIN="00" 49 | fi 50 | # Now we translate all that wonderful stuff in Day One Sprache "hh:mm" 51 | TIMEFORMATED=$HOUR:$MIN 52 | fi 53 | 54 | # Concatenate date and entry time in order to send it to Day One with the text 55 | filename=$i 56 | YEAR=${filename:0:4} 57 | MONTH=${filename:5:2} 58 | DAY=${filename:7:2} 59 | ENTRYDATE=$MONTH/$DAY/$YEAR" "$TIMEFORMATED 60 | 61 | # For each fil in the output folder, the new entry commande create 62 | # a... new entry (clever) at the date and time defined. 63 | dayone -d="$ENTRYDATE" new < "$i" 64 | done -------------------------------------------------------------------------------- /Split.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # http://davidbosman.fr || david@davidbosman.fr || août 2012. 4 | # Feel free to modify and repost. 5 | # 6 | # This script is the first of two that will import a bunch of text files 7 | # formated in Markdown as Day One entries. 8 | # In order to work, each file name must start with AAAA-MMDD (wich will be as 9 | # the date of the entries) and contain only one entry. So if, like me, you 10 | # used to write a day worth of entries in a single file, like this: 11 | # 12 | # 2012-0816-J-my daily diary.txt: 13 | # 14 | # ### 17H32 15 | # Some text. 16 | # 17 | # ### 23h41 18 | # Some more text. 19 | # 20 | # ![alt text](link to an image) 21 | # 22 | # Some more text. 23 | # 24 | # ### some title but no time stamp 25 | # Some text, again. 26 | # 27 | # this script will look for occurences of ## or ### (or none, at the first 28 | # line of the file) and, for each one consisting of a time stamp, will create 29 | # a new file. (other ### will be added to the previous time stamp). 30 | # So the example will look like this after spliting: 31 | # 32 | # 2012-0816-J-my daily diary1.txt: 33 | # 34 | # ### 17H32 35 | # Some text. 36 | # 37 | # 2012-0816-J-my daily diary2.txt: 38 | # 39 | # ### 23h41 40 | # Some more text. 41 | # 42 | # ![alt text](link to an image) 43 | # 44 | # Some more text. 45 | # 46 | # ### some title but not a time stamp 47 | # Some text, again. 48 | # 49 | # Each new file will be created in a temporay export folder 50 | # ("~/Desktop/output"). This folder *must* exist before running the script. 51 | # 52 | # The second script, Import2DayOne.sh, will deal with the import process 53 | # itself, using Day One CLI. 54 | 55 | 56 | for i in * 57 | do 58 | time=`awk '/^##[#]?[ ]?[0-9][0-9]?[h:]/ {print $2}' "$i"` 59 | if [ "$time" != "" ] 60 | then 61 | # CHANGE PATH if you want to. 62 | # Please create the "ouptput" folder before running the script: 63 | perl -n -e "\$p++; if(\$p==1 || /^##[#]?[ ]?[0-9][0-9]?[h:]/) { open FH, \">$HOME/Desktop/output/$i\".++\$n.\".txt\"; } print FH;" "$i" 64 | else 65 | # CHANGE PATH if you want to. 66 | # Please create the "ouptput" folder before running the script: 67 | cp "$i" "$HOME/Desktop/output/$i"; 68 | fi 69 | 70 | done 71 | --------------------------------------------------------------------------------