Skip to content

Instantly share code, notes, and snippets.

@salvah22
Last active November 2, 2021 19:21
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 salvah22/b1418cb71e9d51ca332a9d8d7c82bf5a to your computer and use it in GitHub Desktop.
Save salvah22/b1418cb71e9d51ca332a9d8d7c82bf5a to your computer and use it in GitHub Desktop.
"""
Author: Salvador Hernández
Create a txt from all your exported Google Keep notes (from Google Takeout) using the JSON files, with python.
Google Keep is a great on the cloud tool, but it is always nice to backup things locally, with google Takeout
(https://takeout.google.com/settings/takeout) you can download everything from Keep, this will include some HTML files,
JSON files, attachments and other files, it is bulky and those are not very handy sometimes.
The script creates a txt file for each of your valuable google keep notes (using only the .JSON files), with
differing behaviors for texts and lists, I only required the non trashed notes, but this is easily changeable in line 32
title goes to the .txt filename,
first row indicates what kind of note is,
second row is note color,
third row include all labels / tags,
fourth row has last modification date,
fifth row points to attachments, if any,
sixth row indicates if pinned,
seventh row indicates if it is archived,
all rows starting on row 9 are the note contents
"""
import os, pathlib, json, datetime
fp = os.path.join(os.path.dirname(__file__), 'Keep')
l1 = pathlib.Path(fp).glob('*.json')
for f in l1:
''''''
with open(f.as_posix(), 'r') as f1:
test1 = json.load(f1)
if not test1['isTrashed']:
with open(f.as_posix()[:-4] + 'txt', 'w') as f2:
# row 1
if 'listContent' in test1:
f2.write('LIST\n')
elif 'textContent' in test1:
f2.write('TEXT\n')
# row 2
f2.write(test1['color'] + '\n')
# row 3
if 'labels' in test1:
labels = ''
for d in test1['labels']:
labels += d['name'] + ' '
f2.write(labels[:-1] + '\n')
else:
f2.write('\n')
# row 4
f2.write(datetime.datetime.fromtimestamp(test1['userEditedTimestampUsec']
/ 1000000).strftime('%Y-%m-%d %H:%M:%S') + '\n')
# row 5
if 'attachments' in test1:
attachments = ''
for d in test1['attachments']:
attachments += d['filePath'] + ' '
f2.write(attachments[:-1] + '\n')
else:
f2.write('\n')
# row 6
if test1['isPinned']:
f2.write('PINNED\n')
else:
f2.write('\n')
# row 7
if test1['isArchived']:
f2.write('ARCHIVED\n\n')
else:
f2.write('\n\n')
# row 9 and onwards
if 'textContent' in test1:
f2.write(test1['textContent'])
elif 'listContent' in test1:
for d in test1['listContent']:
listItem = ''
if d['isChecked']:
listItem += '☑\t'
else:
listItem += '\t'
listItem += d['text'] + '\n'
f2.write(listItem)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment