Skip to content

Instantly share code, notes, and snippets.

@sliceofbytes
Created February 14, 2018 22:16
Show Gist options
  • Star 27 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save sliceofbytes/f5eab8911c761ff6760362beb17e6477 to your computer and use it in GitHub Desktop.
Save sliceofbytes/f5eab8911c761ff6760362beb17e6477 to your computer and use it in GitHub Desktop.
Add Text Files as Google Keep Notes
#Import a directory of text files as google keep notes.
#Text Filename is used for the title of the note.
import gkeepapi, os
username = 'username@gmail.com'
password = 'your app password'
keep = gkeepapi.Keep()
success = keep.login(username,password)
dir_path = os.path.dirname(os.path.realpath(__file__))
for fn in os.listdir(dir_path):
if os.path.isfile(fn) and fn.endswith('.txt'):
with open(fn, 'r') as mf:
data=mf.read()
keep.createNote(fn.replace('.txt',''), data)
keep.sync();
@mootensai
Copy link

You could try to increase time.sleep value

@IonceM
Copy link

IonceM commented Jul 31, 2021

You could try to increase time.sleep value

Well, the issue is already at the login. I added the time sleep value later on to my skript, but since I can't do anything....I guess i will wait till my account is released from the usage limit

@IonceM
Copy link

IonceM commented Jul 31, 2021

You could try to increase time.sleep value

Well, the issue is already at the login. I added the time sleep value later on to my skript, but since I can't do anything....I guess i will wait till my account is released from the usage limit

I found a blog where it states that the reset occurs after 24h. So waiting seems fine.
https://support.cloudm.io/hc/en-us/articles/360009862299-Reaching-or-exceeding-Google-API-quotas

@tiabenson
Copy link

tiabenson commented Aug 10, 2021

Thank you! Worked for me without having to change anything.

I am a complete newb.. i am just trying to take all of my txt notes on my windows machine and add them to google keep.. just moved over from mac to windows..

how and where do i add that code

@joshhboss put your text and python files in the same directory, then run the .py file. You may have to pip install gkeepapi.

@WiliTest
Copy link

it works with python 3.9 kiwiz/gkeepapi#81

@Mactastic1-5
Copy link

Mactastic1-5 commented Nov 27, 2021

# This script needs to be in the same folder as the text files!

import time
import gkeepapi, os

username = '<username>' # Type your email address here
password = '<password>' # Use your app password here

keep = gkeepapi.Keep()
success = keep.login(username,password)
dir_path = os.path.dirname(os.path.realpath(__file__))
for fn in os.listdir(dir_path):
	if os.path.isfile(os.path.join(dir_path, fn)) and fn.endswith('.txt'):
		with open(os.path.join(dir_path, fn), 'r', encoding='utf-8', errors='ignore') as mf:
			data=mf.read()
			print(keep.createNote(fn.replace('.txt',''), data))
			print(keep.sync())
			time.sleep(5)

I tried it on Windows Subsystem for Linux through Ubuntu, and it doesn't authenticate. I tried many of the suggestions, and the outcome was the same. It works on macOS. Maybe if I installed Python 3 natively with Chocolatey, it would work.

@tu-design
Copy link

tu-design commented Mar 9, 2022

I was facing two errors: 1) Notes not copying due to ascii 2) Notes not copying due to encoding, you can solve them as follows if you have any different encode of text files (here: UTF8) and also added a print option for logs to check which file gives the error.

import gkeepapi, os
username = 'username@gmail.com'
password = 'app password'

keep = gkeepapi.Keep()
success = keep.login(username,password)
dir_path = os.path.dirname(os.path.realpath(__file__))
for fn in os.listdir(dir_path):
	print(fn)
	if os.path.isfile(fn) and fn.endswith('.txt'):
		with open(fn, encoding="utf8") as mf:
			data=mf.read()
			keep.createNote(fn.replace('.txt',''), data)
			keep.sync();

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