Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new flags for show cards and added show comments #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ share/*
build/*
dist/*
*egg-info*
.env
81 changes: 48 additions & 33 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
gtd.py
Mello
=======

A Fast Command-line Interface for Trello
---------------------------------------

This is a command-line tool that enables you to add, sort, and review cards on Trello rapidly. It is designed to reduce the amount of friction between your thoughts and your TODO list, especially if you never leave the terminal.

The project is named "gtd.py" because it was initially built as a tool for me to maintain a Trello board using the GTD_ task tracking method. I've been actively using this tool for GTD since the first commit; if you're trying to use GTD with Trello this is the tool for you.
Installation
------------

When installing, make sure to use pip3 if you your machine defaults to python2.7
1. Install via pip
`pip3 install mello`

1.1 (Optional) Add python3 bin to PATH if you haven't already done so

2. Setup OAuth credentials
`mello reconfigure`


Usage
-----

Displaying Unresponded Comments
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The ``show unresponded`` command will return all comments that mention your username that you have not responded to yet.

Displaying Cards
^^^^^^^^^^^^^^^^

Expand All @@ -20,24 +35,24 @@ The ``show`` command will return all the cards which match your supplied argumen
::

# Show cards from the list "Inbox" matching a regular expression on their titles
$ gtd show cards -l Inbox -m 'https?'
$ mello show cards -l Inbox -m 'https?'

# Show cards which have no tags but have due dates, in pretty-printed JSON format
$ gtd show cards --no-tags --has-due -j
$ mello show cards --no-tags --has-due -j


``grep`` faithfully implements some flags from the venerable utility, including -c, -i, and -e! An invocation of this command is similar to a longer invocation of ``show``: ``gtd grep 'some_pattern'`` is equivalent to ``gtd show cards -m 'some_pattern'``.
``grep`` faithfully implements some flags from the venerable utility, including -c, -i, and -e! An invocation of this command is similar to a longer invocation of ``show``: ``mello grep 'some_pattern'`` is equivalent to ``mello show cards -m 'some_pattern'``.

::

# Filter all cards based on a regex
$ gtd grep 'http.*amazon'
$ mello grep 'http.*amazon'

# or multiple regexes!
$ gtd grep -e '[Jj]ob' -e 'career' -e '[oO]pportunity?'
$ mello grep -e '[Jj]ob' -e 'career' -e '[oO]pportunity?'

# Use other popular grep flags!
$ gtd grep -ci 'meeting'
$ mello grep -ci 'meeting'

Creating Things
^^^^^^^^^^^^^^^^
Expand All @@ -53,13 +68,13 @@ The command you'll probably use most frequently is ``add card``. Here are some c
::

# Add a new card with title "foo"
$ gtd add card foo
$ mello add card foo

# Specify a description with the card title
$ gtd add card foo -m 'Description for my new card'
$ mello add card foo -m 'Description for my new card'

# Open $EDITOR so you can write the card title
$ gtd add card
$ mello add card

The other subcommands for ``add`` (``add list`` and ``add tag``) are self-explanatory.

Expand All @@ -71,13 +86,13 @@ The ``delete`` subcommand allows you to get rid of lists & cards. By default, ca
::

# Archive all cards whose titles match this regular expression
$ gtd delete cards -m 'on T(hurs|ues)day'
$ mello delete cards -m 'on T(hurs|ues)day'

# Delete without intervention all cards containing the string "testblah"
$ gtd delete cards --noninteractive --force -m 'testblah'
$ mello delete cards --noninteractive --force -m 'testblah'

# Delete the list named "Temporary work"
$ gtd delete list "Temporary work"
$ mello delete list "Temporary work"


Manipulating Cards in Bulk
Expand All @@ -88,52 +103,52 @@ Frequently it's useful to move a whole bunch of cards at once, tag cards that ma
::

# Tag all cards that have no tags
$ gtd batch tag --no-tags
$ mello batch tag --no-tags

# Find all cards with a URL in their title and move those URLs into their attachments
$ gtd batch attach
$ mello batch attach

# Move all cards in your "Inbox" list
$ gtd batch move -l Inbox
$ mello batch move -l Inbox

# Set the due dates for all cards in a list containing the substring "Week"
$ gtd batch due -l Week
$ mello batch due -l Week

# Change the due date for all cards that have one already
$ gtd batch due --has-due
$ mello batch due --has-due


Bringing It all Together
^^^^^^^^^^^^^^^^^^^^^^^^

What if you don't know what kind of action you want to take on a card before you invoke ``gtd``? Well, we provide a nice menu for you to work on each card in turn. The menu is kinda REPL-like so if you're a terminal power user (truly, why would you use this tool unless you're already a terminal power-user) it'll feel familiar. The menu is built using ``python-prompt-toolkit`` so it has nice tab-completion on every command available within it. You can type ``help`` at any time to view all the commands available within the REPL.
What if you don't know what kind of action you want to take on a card before you invoke ``mello``? Well, we provide a nice menu for you to work on each card in turn. The menu is kinda REPL-like so if you're a terminal power user (truly, why would you use this tool unless you're already a terminal power-user) it'll feel familiar. The menu is built using ``python-prompt-toolkit`` so it has nice tab-completion on every command available within it. You can type ``help`` at any time to view all the commands available within the REPL.

Seeing is believing, so until I record a terminal session of me using it I'd highly encourage you to play around with this menu. It does some detection on the title of your card and will prompt you to move links out into attachments if appropriate. If the card doesn't have any tags yet, it'll prompt you to add some.

::

# Work through cards in the "Inbox" list one at a time
$ gtd review -l Inbox
$ mello review -l Inbox

# Review only cards from the "Today" list that have due dates
$ gtd review -l Today --has-due
$ mello review -l Today --has-due


Setup
------

::

$ pip install gtd.py
$ gtd onboard
$ pip install mello.py
$ mello onboard

The ``onboard`` command will assist you through the process of getting a Trello API key for use with this program and putting it in the correct file. This will happen automatically if you run a command that requires authentication without having your API keys set.

If you'd like to enable automatic bash completion for gtd.py, add the following line to your ~/.bashrc:
If you'd like to enable automatic bash completion for mello.py, add the following line to your ~/.bashrc:

::

eval "$(_GTD_COMPLETE=source gtd)"
eval "$(_GTD_COMPLETE=source mello)"

This relies on ``click``'s internal bash completion engine, so it does not work on other shells like ``sh``, ``csh``, or ``zsh``.

Expand All @@ -156,18 +171,18 @@ There are other optional settings you can define inside your yaml configuration

board: "Name of the Trello board you want to work with (case sensitive)"
color: True # Do you want to show ANSI colors in the terminal?
banner: True # Do you want to see the "gtd.py" banner on each program run?
banner: True # Do you want to see the "mello.py" banner on each program run?


All of these can be overridden on the command-line with the ``-b``, ``--no-color``, and ``--no-banner`` flags.

This configuration file can be put in a variety of locations within your home folder. The ``onboard`` command will help you with platform detection, putting the configuration file where appropriate given your operating system. When running, ``gtd``` will check all possible locations out of this list:
This configuration file can be put in a variety of locations within your home folder. The ``onboard`` command will help you with platform detection, putting the configuration file where appropriate given your operating system. When running, ``mello``` will check all possible locations out of this list:

* ``~/.gtd.yaml``
* ``~/.config/gtd/gtd.yaml``
* ``~/Library/Application Support/gtd/gtd.yaml``
* ``~/.local/etc/gtd.yaml``
* ``~/.local/etc/gtd/gtd.yaml``
* ``~/.mello.yaml``
* ``~/.config/mello/mello.yaml``
* ``~/Library/Application Support/mello/mello.yaml``
* ``~/.local/etc/mello.yaml``
* ``~/.local/etc/mello/mello.yaml``

Notes
------
Expand Down
93 changes: 84 additions & 9 deletions gtd.py → mello.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import requests
import readline # noqa
import webbrowser
from datetime import datetime
from requests_oauthlib import OAuth1Session
from requests_oauthlib.oauth1_session import TokenRequestDenied
from todo.input import prompt_for_confirmation, BoardTool, CardTool
Expand All @@ -29,6 +30,9 @@ def filtering_command(f):
f = click.option('-l', '--listname', help='Only show cards from this list', default=None)(f)
f = click.option('--attachments', is_flag=True, help='Only show cards which have attachments', default=None)(f)
f = click.option('--has-due', is_flag=True, help='Only show cards which have due dates', default=None)(f)
f = click.option('-a', '--assigned', is_flag=True, help='Only show cards assigned to you')(f)
f = click.option('-c', '--completed', is_flag=True, help='Only show cards assigned and completed by you')(f)
f = click.option('--include_closed', is_flag=True, help='Include archived cards', default=None)(f)
return f


Expand Down Expand Up @@ -197,9 +201,9 @@ def onboard(no_open, output_path=None):
# show {{{


@cli.group(short_help='Display cards, tags, or lists on this board')
@cli.group(short_help='Display cards, tags, comments or lists on this board')
def show():
'''Display cards, tags, or lists on this board.'''
'''Display cards, tags, comments or lists on this board.'''
pass


Expand All @@ -209,7 +213,7 @@ def show():
@pass_config
def show_lists(config, json, show_all):
'''Display all lists on this board'''
_, board = BoardTool.start(config)
_, board, _ = BoardTool.start(config)
display = Display(config.color)
if config.banner and not json:
display.banner()
Expand All @@ -218,12 +222,79 @@ def show_lists(config, json, show_all):
display.show_raw(list_names, use_json=json)


def get_mentions_from_text(text):
trello_username_re = re.compile(r'@([A-Za-z0-9_]+)')
return trello_username_re.findall(text)

def has_replied_to_comment(connection, original_comment_text, creator_username, mentioned_username, card_id):
current_card = connection.trello.get_card(card_id)
comments = current_card.fetch_comments(force=True)
has_response = False
selected_comment_i = None

for i, comment in enumerate(comments):
# If creator of previous comment is mentoined in comment text and
# previously mentioned username is creator of this comment, we have
# found reply to original comment
comment_text = comment["data"]["text"]
usernames_in_comment = get_mentions_from_text(comment["data"]["text"])

if mentioned_username in usernames_in_comment:
has_response = True
if original_comment_text == comment_text:
selected_comment_i = i
break

if selected_comment_i is not None and has_response is True:
return True
return False

def get_unresponded_comments(connection, current_user):
notifications = connection.trello.fetch_json('/members/me/notifications',
query_params={'filter': ",".join(['mentionedOnCard'])})

unresponded_comments = []
for notif in notifications:
comment_creator = notif["memberCreator"]
comment_text = notif["data"]["text"]
comment_card = notif["data"]["card"]
comment_board = notif["data"]["board"]
comment_date = datetime.strptime(notif["date"], "%Y-%m-%dT%H:%M:%S.%fZ")

if not has_replied_to_comment(connection, comment_text, current_user.username, comment_creator['username'], comment_card['id']):
unresponded_comments.append({
"creator": comment_creator,
"text": comment_text,
"card": comment_card,
"board": comment_board,
"date": comment_date,
"id": notif["id"]
})

date_str = "{:%b %d, %Y}".format(comment_date)

return unresponded_comments


@show.command('unresponded')
@json_option
@pass_config
def show_unresponded(config, json):
'''Display all unresponded comments for current account'''
connection, _, current_user = BoardTool.start(config)
display = Display(config.color)
if config.banner and not json:
display.banner()
comments = get_unresponded_comments(connection, current_user)
display.show_comments(comments, use_json=json)


@show.command('tags')
@json_option
@pass_config
def show_tags(config, json):
'''Display all tags on this board'''
_, board = BoardTool.start(config)
_, board, _ = BoardTool.start(config)
display = Display(config.color)
if config.banner and not json:
display.banner()
Expand All @@ -236,25 +307,29 @@ def show_tags(config, json):
@json_option
@click.option('--tsv', is_flag=True, default=False, help='Output as tab-separated values')
@pass_config
def show_cards(config, json, tsv, tags, no_tags, match, listname, attachments, has_due):
def show_cards(config, json, tsv, tags, no_tags, match, listname, attachments, has_due, assigned, completed, include_closed):
'''Display cards
The show command prints a table of all the cards with fields that will fit on the terminal you're using.
You can change this formatting by passing one of --tsv or --json, which will output as a tab-separated value sheet or JSON.
This command along with the batch & review commands share a flexible argument scheme for getting card information.
Mutually exclusive arguments include -t/--tags & --no-tags along with -j/--json & --tsv
'''
_, board = BoardTool.start(config)
_, board, current_user = BoardTool.start(config)
display = Display(config.color)
if config.banner and not json:
display.banner()
cards = BoardTool.filter_cards(
board,
tags=tags,
no_tags=no_tags,
current_user=current_user,
title_regex=match,
list_regex=listname,
has_attachments=attachments,
has_due_date=has_due
has_due_date=has_due,
assigned=assigned,
completed=completed,
include_closed=include_closed
)
display.show_cards(cards, use_json=json, tsv=tsv)

Expand All @@ -276,7 +351,7 @@ def delete():
def delete_lists(config, name, noninteractive):
'''Delete lists containing the substring <name>
'''
_, board = BoardTool.start(config)
_, board, _ = BoardTool.start(config)
lists = [l for l in board.get_lists('open') if name in l.name]
if noninteractive:
[l.set_closed() for l in lists]
Expand All @@ -295,7 +370,7 @@ def delete_lists(config, name, noninteractive):
def delete_cards(config, force, noninteractive, tags, no_tags, match, listname, attachments, has_due):
'''Delete a set of cards specified
'''
_, board = BoardTool.start(config)
_, board, _ = BoardTool.start(config)
display = Display(config.color)
if config.banner and not json:
display.banner()
Expand Down
14 changes: 7 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@
readme_contents = f.read()

setup(
name='gtd.py',
name='mello',
description='A Fast Command-line Interface for Trello',
long_description=readme_contents,
version=__version__,
install_requires=reqs,
packages=['todo'],
py_modules=['gtd'],
py_modules=['mello'],
entry_points={
'console_scripts': [
'gtd = gtd:main'
'mello = mello:main'
]
},
python_requires='>=3',
author = 'James Luck',
author_email = '[email protected]',
author = 'David Baldwynn',
author_email = '[email protected]',
license='BSD 3-clause',
url = 'https://github.com/delucks/gtd.py',
download_url = 'https://github.com/delucks/gtd.py/tarball/{}'.format(__version__),
url = 'https://github.com/whitef0x0/gtd.py',
download_url = 'https://github.com/whitef0x0/gtd.py/tarball/{}'.format(__version__),
keywords = ['productivity', 'cli', 'trello', 'gtd', 'getting things done'],
classifiers = [
'Development Status :: 4 - Beta',
Expand Down
Loading