Skip to content

Commit

Permalink
fixed Docker and added move to archive flag
Browse files Browse the repository at this point in the history
  • Loading branch information
djsudduth committed Jan 14, 2024
1 parent 14bc030 commit 54db627
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 15 deletions.
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM debian:bullseye
FROM ubuntu:22.04
RUN apt update
RUN apt install -y python-is-python3 python3-pip
RUN apt-get install -y curl
RUN apt-get install ca-certificates
RUN curl -L -o tmp/keep-it-markdown-0.5.3.tar.gz https://github.com/djsudduth/keep-it-markdown/archive/refs/tags/0.5.3.tar.gz
RUN tar -zxvf tmp/keep-it-markdown-0.5.3.tar.gz
RUN pip install -r keep-it-markdown-0.5.3/requirements.txt
RUN curl -L -o tmp/keep-it-markdown-0.5.4.tar.gz https://github.com/djsudduth/keep-it-markdown/archive/refs/tags/0.5.3.tar.gz
RUN tar -zxvf tmp/keep-it-markdown-0.5.4.tar.gz
RUN pip install -r keep-it-markdown-0.5.4/requirements.txt
RUN pip install requests==2.23.0
RUN pip install gpsoauth==1.0.2
RUN pip install keyrings.alt
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ At first launch KIM will create a **settings.cfg** file in the directory where y

**google_userid** = your-google-account-id (allows you to bypass typing in your id)
**output_path** = path to where the output md files are created (if empty it is your install directory). Windows users use forward slashes, e.g. -> c:/md-files/export.

**media_path** = location of the exported media files (images, audio) relative to your output_path. If the output_path is /mdexport and media_path is media/data, the media full path will be /mdexport/media/data. Media paths cannot start with /, mount or drive letter.

(For import settings, see the -i switch below)
Expand Down Expand Up @@ -116,6 +115,13 @@ Joplin tags do not use the hashtag format. They are provided as front matter com
> python kim.py -j
```

#### Move Notes to Archive After Export
**CAUTION! This is the only switch that alters your notes - even if it just an attribute change. Be sure to backup your Keep notes to Google Takeout before using this option!!**
If you have a large number of notes it can be confusing which ones have already been exported. With this switch any exported notes will be moved to the Keep archive. You can enable this feature with
```bash
> python kim.py -m
```

#### Authentication Token Storage
When you run KIM for the first time and log in via your password, it will store your authenticated Google Keep token in your computer's safe storage (macOS - Keychain, Windows Credential Locker and Linux Secret Service or KWallet). You will not need to re-enter your password next time you run KIM.

Expand Down Expand Up @@ -239,3 +245,8 @@ Removed first dash on list notes exported to Logseq with -l switch
## 0.5.3 Recent Changes
Docker image creation and use
Removed captcha note in keep-test.py

## 0.5.4 Recent Changes
Docker image altered to use Ubuntu:22.04 to fix Google auth issues with gkeepapi
Added new flag -m to move exported images to Archive folder
Removed python deprecated imghdr library with pillow module
36 changes: 26 additions & 10 deletions kim.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import keyring
import getpass
import requests
import imghdr
import shutil
import re
import configparser
Expand All @@ -13,6 +12,7 @@
from pathlib import Path
from dataclasses import dataclass
from xmlrpc.client import boolean
from PIL import Image


KEEP_KEYRING_ID = 'google-keep-token'
Expand Down Expand Up @@ -71,6 +71,7 @@ class Options:
text_for_title: boolean
logseq_style: boolean
joplin_frontmatter: boolean
move_to_archive: boolean
import_files: boolean

@dataclass
Expand Down Expand Up @@ -378,16 +379,24 @@ def download_file(self, file_url, file_name, file_path):
def set_file_extensions(self, data_file, file_name, file_path):
dest_path = file_path + file_name

if imghdr.what(data_file) == 'png':
try:
image = Image.open(data_file)
what = image.format.lower()
image.close()
except:
what = ".m4a"


if what == 'png':
media_name = file_name + ".png"
blob_final_path = dest_path + ".png"
elif imghdr.what(data_file) == 'jpeg':
elif what == 'jpeg':
media_name = file_name + ".jpg"
blob_final_path = dest_path + ".jpg"
elif imghdr.what(data_file) == 'gif':
elif what == 'gif':
media_name = file_name + ".gif"
blob_final_path = dest_path + ".gif"
elif imghdr.what(data_file) == 'webp':
elif what == 'webp':
media_name = file_name + ".webp"
blob_final_path = dest_path + ".webp"
else:
Expand Down Expand Up @@ -524,6 +533,9 @@ def keep_query_convert(keep, keepquery, opts):
""
)
)
if opts.move_to_archive:
gnote.archived = True


for note in notes:

Expand Down Expand Up @@ -597,6 +609,9 @@ def keep_query_convert(keep, keepquery, opts):
if opts.overwrite or opts.skip_existing:
NameService().clear_name_list()

if opts.move_to_archive:
keep.keep_sync()

return (count)
except:
print("Error in keep_query_convert()")
Expand Down Expand Up @@ -698,18 +713,19 @@ def ui_welcome_config():
@click.option('-c', is_flag=True, help="Use starting content within note body instead of create date for md filename")
@click.option('-l', is_flag=True, help="Prepend paragraphs with Logseq style bullets")
@click.option('-j', is_flag=True, help="Prepend notes with Joplin front matter tags and dates")
@click.option('-m', is_flag=True, help="Move any exported Keep notes to Archive")
@click.option('-i', is_flag=True, help="Import notes from markdown files EXPERIMENTAL!!")
@click.option('-b', '--search-term', help="Run in batch mode with a specific Keep search term")
@click.option('-t', '--master-token', help="Log in using master keep token")
def main(r, o, a, p, s, c, l, j, i, search_term, master_token):
def main(r, o, a, p, s, c, l, j, m, i, search_term, master_token):

try:

#j = True
opts = Options(o, a, p, s, c, l, j, i)
#m = True
opts = Options(o, a, p, s, c, l, j, m, i)
click.echo("\r\nWelcome to Keep it Markdown or KIM!\r\n")

if i and (r or o or a or s or p or c):
if i and (r or o or a or s or p or c or m):
print ("Importing markdown notes with export options is not compatible -- please use -i only to import")
exit()

Expand All @@ -733,7 +749,7 @@ def main(r, o, a, p, s, c, l, j, i, search_term, master_token):
# raise Exception("Problem with markdown file creation: " + repr(e))


#Version 0.5.2
#Version 0.5.4

if __name__ == '__main__':

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
gkeepapi
keyring
click
pillow

###### Requirements with Version Specifiers worked with Python 3.7.3 ######`
#gkeepapi == 0.13.1
Expand Down

0 comments on commit 54db627

Please sign in to comment.