Skip to content

Instantly share code, notes, and snippets.

@rewse
Created March 31, 2024 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rewse/a32475f3aa7ebe24d4c56be84b3560eb to your computer and use it in GitHub Desktop.
Save rewse/a32475f3aa7ebe24d4c56be84b3560eb to your computer and use it in GitHub Desktop.
#!/bin/bash
trap 'my_exit 1' 1 2 3 15
readonly tmpfile='/tmp/conv_googlekeep_omnivore.tmp'
my_exit() {
rm -f $tmpfile*
}
cat - |
jq -r '[.textContent, .userEditedTimestampUsec / 1000, .createdTimestampUsec / 1000, .labels[].name] | @tsv' |
perl -pe 's/^(\S+?)\\n.*?(\t.*)/\1\2/' | # Delete texts from textContent excluding the first URL
perl -pe 's/(\S+\t\S+\t\S+\t)(.+)/\1\"[\2\]"/' > $tmpfile # Add [] to labels
# Split to three files to swap
# Create a file including URL and SUCCEEDED
cat $tmpfile |
awk 'BEGIN{FS="\t"; OFS="\t"} {print $1, "SUCCEEDED"}' > $tmpfile.1
# Create a file including times
cat $tmpfile |
awk 'BEGIN{FS="\t"; OFS="\t"} {print $2, $3}' > $tmpfile.2
# Create a file including labels
cat $tmpfile |
perl -pe 's/.+("\[.+)/\1/' > $tmpfile.3
# Change the position of the labels
cat $tmpfile.1 $tmpfile.3 $tmpfile.2 |
tr '\n\t' ',,' | # Replace line breaks and tabs with commas
sed 's/,$/\n/' # Repleace the last comma with a line break
my_exit 0
@rewse
Copy link
Author

rewse commented Mar 31, 2024

  1. Request to export Google Keep data from Goole Data Export
  2. Get “Export management.zip” after you receive a notification that data is prepared
  3. Extract “Export management.zip.” You will find HTML and JSON files in the folder, Takeout/Keep
  4. Download conv_googlekeep_omnivore.sh and copy it to Takeout/Keep or other
  5. Grant execute permission to conv_googlekeep_omnivore.sh
  6. Input all JSON files into conv_googlekeep_omnivore.sh
  7. Add a header
  8. Drag & drop the completed CSV to Omnivore Library
% cd Takeout/Keep
% chmod 755 conv_googlekeep_omnivore.sh
% for FILE in *.json; do
>   echo "Converting $FILE..." 1>&2
>   cat $FILE | ./conf_googlekeep_omnivore.sh >> converted.csv
> done
% echo 'url,state,labels,saved_at,published_at' > data.csv
% cat converted.csv >> data.csv

The detail is in my blog article, which is written in Japanese.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment