-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Notes commands Issue #5: Create note.
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,4 @@ def cli(ctx, debug, auth): | |
|
||
|
||
import google_keep_tasks.items | ||
import google_keep_tasks.notes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import click | ||
import gkeepapi | ||
|
||
from google_keep_tasks.exceptions import InvalidColor | ||
from google_keep_tasks.management import cli | ||
|
||
|
||
def add_color(note, color): | ||
if not color: | ||
return | ||
color = color.title() | ||
if color and not hasattr(gkeepapi.node.ColorValue, color): | ||
raise InvalidColor(color) | ||
note.color = getattr(gkeepapi.node.ColorValue, color) | ||
|
||
|
||
def find_or_create_label(keep, label_name): | ||
label = keep.findLabel(label_name) | ||
if not label: | ||
label = keep.createLabel(label_name) | ||
return label | ||
|
||
|
||
def add_labels(keep, note, labels): | ||
if not labels: | ||
return | ||
for label in labels: | ||
note.labels.add(find_or_create_label(keep, label)) | ||
|
||
|
||
def comma_separated(ctx, param, value): | ||
return value.split(',') if value else [] | ||
|
||
|
||
@cli.command('add-note') | ||
@click.option('--color', default='') | ||
@click.option('--labels', default='', callback=comma_separated) | ||
@click.argument('title') | ||
@click.argument('text') | ||
@click.pass_context | ||
def add_note(ctx, color, labels, title, text): | ||
keep = ctx.obj['keep'] | ||
gnote = keep.createNote(title, text) | ||
add_color(gnote, color) | ||
add_labels(keep, gnote, labels) | ||
keep.sync() |