Browse Source

Add support for displaying cards.
Add support for looking up cards by board name.

Pat Lathem 10 months ago
parent
commit
7b6cdecf46
5 changed files with 82 additions and 129 deletions
  1. 1 3
      Pipfile
  2. 2 94
      Pipfile.lock
  3. 34 0
      README.md
  4. 16 5
      cli.py
  5. 29 27
      trello/__init__.py

+ 1 - 3
Pipfile

@@ -5,12 +5,10 @@ name = "pypi"
 
 [packages]
 requests = "*"
-click = "*"
 terminaltables = "*"
+click = "*"
 
 [dev-packages]
-pylint = "*"
-"autopep8" = "*"
 
 [requires]
 python_version = "3.7"

+ 2 - 94
Pipfile.lock

@@ -1,7 +1,7 @@
 {
     "_meta": {
         "hash": {
-            "sha256": "357555d06ff3885e80b0317b3cdf10dfef525f9b98b5b5a0604d15a64a107215"
+            "sha256": "07acea859e8bcebeb506599a7f3ed7331dcde7287661172ffc1babb91d047ed2"
         },
         "pipfile-spec": 6,
         "requires": {
@@ -68,97 +68,5 @@
             "version": "==1.24"
         }
     },
-    "develop": {
-        "astroid": {
-            "hashes": [
-                "sha256:292fa429e69d60e4161e7612cb7cc8fa3609e2e309f80c224d93a76d5e7b58be",
-                "sha256:c7013d119ec95eb626f7a2011f0b63d0c9a095df9ad06d8507b37084eada1a8d"
-            ],
-            "version": "==2.0.4"
-        },
-        "autopep8": {
-            "hashes": [
-                "sha256:1b8d42ebba751a91090d3adb5c06840b1151d71ed43e1c7a9ed6911bfe8ebe6c"
-            ],
-            "index": "pypi",
-            "version": "==1.4.2"
-        },
-        "isort": {
-            "hashes": [
-                "sha256:1153601da39a25b14ddc54955dbbacbb6b2d19135386699e2ad58517953b34af",
-                "sha256:b9c40e9750f3d77e6e4d441d8b0266cf555e7cdabdcff33c4fd06366ca761ef8",
-                "sha256:ec9ef8f4a9bc6f71eec99e1806bfa2de401650d996c59330782b89a5555c1497"
-            ],
-            "version": "==4.3.4"
-        },
-        "lazy-object-proxy": {
-            "hashes": [
-                "sha256:0ce34342b419bd8f018e6666bfef729aec3edf62345a53b537a4dcc115746a33",
-                "sha256:1b668120716eb7ee21d8a38815e5eb3bb8211117d9a90b0f8e21722c0758cc39",
-                "sha256:209615b0fe4624d79e50220ce3310ca1a9445fd8e6d3572a896e7f9146bbf019",
-                "sha256:27bf62cb2b1a2068d443ff7097ee33393f8483b570b475db8ebf7e1cba64f088",
-                "sha256:27ea6fd1c02dcc78172a82fc37fcc0992a94e4cecf53cb6d73f11749825bd98b",
-                "sha256:2c1b21b44ac9beb0fc848d3993924147ba45c4ebc24be19825e57aabbe74a99e",
-                "sha256:2df72ab12046a3496a92476020a1a0abf78b2a7db9ff4dc2036b8dd980203ae6",
-                "sha256:320ffd3de9699d3892048baee45ebfbbf9388a7d65d832d7e580243ade426d2b",
-                "sha256:50e3b9a464d5d08cc5227413db0d1c4707b6172e4d4d915c1c70e4de0bbff1f5",
-                "sha256:5276db7ff62bb7b52f77f1f51ed58850e315154249aceb42e7f4c611f0f847ff",
-                "sha256:61a6cf00dcb1a7f0c773ed4acc509cb636af2d6337a08f362413c76b2b47a8dd",
-                "sha256:6ae6c4cb59f199d8827c5a07546b2ab7e85d262acaccaacd49b62f53f7c456f7",
-                "sha256:7661d401d60d8bf15bb5da39e4dd72f5d764c5aff5a86ef52a042506e3e970ff",
-                "sha256:7bd527f36a605c914efca5d3d014170b2cb184723e423d26b1fb2fd9108e264d",
-                "sha256:7cb54db3535c8686ea12e9535eb087d32421184eacc6939ef15ef50f83a5e7e2",
-                "sha256:7f3a2d740291f7f2c111d86a1c4851b70fb000a6c8883a59660d95ad57b9df35",
-                "sha256:81304b7d8e9c824d058087dcb89144842c8e0dea6d281c031f59f0acf66963d4",
-                "sha256:933947e8b4fbe617a51528b09851685138b49d511af0b6c0da2539115d6d4514",
-                "sha256:94223d7f060301b3a8c09c9b3bc3294b56b2188e7d8179c762a1cda72c979252",
-                "sha256:ab3ca49afcb47058393b0122428358d2fbe0408cf99f1b58b295cfeb4ed39109",
-                "sha256:bd6292f565ca46dee4e737ebcc20742e3b5be2b01556dafe169f6c65d088875f",
-                "sha256:cb924aa3e4a3fb644d0c463cad5bc2572649a6a3f68a7f8e4fbe44aaa6d77e4c",
-                "sha256:d0fc7a286feac9077ec52a927fc9fe8fe2fabab95426722be4c953c9a8bede92",
-                "sha256:ddc34786490a6e4ec0a855d401034cbd1242ef186c20d79d2166d6a4bd449577",
-                "sha256:e34b155e36fa9da7e1b7c738ed7767fc9491a62ec6af70fe9da4a057759edc2d",
-                "sha256:e5b9e8f6bda48460b7b143c3821b21b452cb3a835e6bbd5dd33aa0c8d3f5137d",
-                "sha256:e81ebf6c5ee9684be8f2c87563880f93eedd56dd2b6146d8a725b50b7e5adb0f",
-                "sha256:eb91be369f945f10d3a49f5f9be8b3d0b93a4c2be8f8a5b83b0571b8123e0a7a",
-                "sha256:f460d1ceb0e4a5dcb2a652db0904224f367c9b3c1470d5a7683c0480e582468b"
-            ],
-            "version": "==1.3.1"
-        },
-        "mccabe": {
-            "hashes": [
-                "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42",
-                "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"
-            ],
-            "version": "==0.6.1"
-        },
-        "pycodestyle": {
-            "hashes": [
-                "sha256:cbc619d09254895b0d12c2c691e237b2e91e9b2ecf5e84c26b35400f93dcfb83",
-                "sha256:cbfca99bd594a10f674d0cd97a3d802a1fdef635d4361e1a2658de47ed261e3a"
-            ],
-            "version": "==2.4.0"
-        },
-        "pylint": {
-            "hashes": [
-                "sha256:1d6d3622c94b4887115fe5204982eee66fdd8a951cf98635ee5caee6ec98c3ec",
-                "sha256:31142f764d2a7cd41df5196f9933b12b7ee55e73ef12204b648ad7e556c119fb"
-            ],
-            "index": "pypi",
-            "version": "==2.1.1"
-        },
-        "six": {
-            "hashes": [
-                "sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9",
-                "sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb"
-            ],
-            "version": "==1.11.0"
-        },
-        "wrapt": {
-            "hashes": [
-                "sha256:d4d560d479f2c21e1b5443bbd15fe7ec4b37fe7e53d335d3b9b0a7b1226fe3c6"
-            ],
-            "version": "==1.10.11"
-        }
-    }
+    "develop": {}
 }

+ 34 - 0
README.md

@@ -15,6 +15,8 @@ Successfully tagged trello-cli:latest
 * TRELLO_KEY
 * TRELLO_TOKEN
 
+Obtain these from https://trello.com/app-key if you don't have them.
+
 ### Run in Docker
 
 ```bash
@@ -31,3 +33,35 @@ $ docker run --rm -it -e "TRELLO_KEY=$TRELLO_KEY" -e "TRELLO_TOKEN=$TRELLO_TOKEN
 | Work Projects     | https://trello.com/b/uqyQmgc2/work-projects     |
 +-------------------+-------------------------------------------------+
 ```
+
+### Run with pipenv
+
+```bash
+# TODO
+ python cli.py cards -n "Welcome Board"
+         Basics
+ * Welcome to Trello!
+ * This is a card.
+ * Click on a card to see what's behind it.
+ * You can attach pictures and files...
+ * ... any kind of hyperlink ...
+ * ... or checklists.
+
+         Intermediate
+ * Invite your team to this board using the Add Members button
+ * Drag people onto a card to indicate that they're responsible for it.
+ * Use color-coded labels for organization
+ * You can change the board background.
+ * Make as many lists as you need!
+ * Try dragging cards anywhere.
+ * Finished with a card? Archive it.
+
+         Advanced
+ * Use as many boards as you want!
+ * Want tips, usage examples, or API info?
+ * Want to use keyboard shortcuts? We have them!
+ * Get the apps for iOS, Android, and Windows 8!
+ * Want updates on new features?
+ * Need help?
+ ```
+

+ 16 - 5
cli.py

@@ -1,5 +1,4 @@
 import click
-import requests
 from terminaltables import AsciiTable
 
 from trello import Trello
@@ -26,12 +25,24 @@ def boards():
     print(table.table)
 
 @click.command()
-@click.option('-i', '--boardid', required=True, type=click.STRING)
-def cards(boardid):
+@click.option('-i', '--id', required=False, type=click.STRING)
+@click.option('-n', '--name', required=False, type=click.STRING)
+def cards(id, name):
+    if id is None and name is None:
+        raise click.UsageError("Either the board ID (-i) or name (-n) is required. ")
+
     t = Trello()
-    cards = t.cards(boardid)
 
-    print(cards)
+    if name is not None:
+        id = t.lookupBoard(name)
+
+    cards = t.cards(id)
+
+    for listy in cards:
+        print("\t", listy)
+        for c in cards[listy]:
+            print(" *", c)
+        print()
 
 
 if __name__ == '__main__':

+ 29 - 27
trello/__init__.py

@@ -11,12 +11,12 @@ class Trello(object):
         try:
             self.key = os.environ['TRELLO_KEY']
         except KeyError:
-            raise Exception('Missing environment variable: TRELLO_KEY')
+            raise Exception('Missing environment variable: TRELLO_KEY. Obtain from https://trello.com/app-key')
 
         try:
             self.token = os.environ['TRELLO_TOKEN']
         except KeyError:
-            raise Exception('Missing environment variable: TRELLO_TOKEN')
+            raise Exception('Missing environment variable: TRELLO_TOKEN. Obtain from https://trello.com/app-key')
 
         self.url = "https://api.trello.com/1/"
         self.getauth = "key={key}&token={token}".format(key=self.key, token=self.token)
@@ -24,7 +24,6 @@ class Trello(object):
 
     def boards(self):
         # List all boards
-
         resp = self.request("members/me/boards")
         return resp.json()
 
@@ -40,35 +39,38 @@ class Trello(object):
                 list_dict[l['id']] = l['name']
         # print(lists.json())
 
-        return lists
+        return list_dict
 
     def cards(self, boardid):
         # Display the content of a board
 
         # Get lists
-        lists = self.request("boards/{boardid}/lists".format(boardid=boardid))
-        list_dict = {}
-
-        # TODO: move this logic out of this function
-        # # Create dict to lookup list name by ID
-        # for l in lists.json():
-        #     if not l['closed']:
-        #         list_dict[l['id']] = l['name']
-        # print(lists.json())
-
-        # # Get cards
-        # cards = self.request("boards/{boardid}/cards".format(boardid=boardid))
-
-        # # Group cards by list
-        # result = {}
-        # for c in cards.json():
-        #     list_name =  list_dict[c['idList']]
-        #     card_name = c['name']
-        #     if list_name not in result:
-        #         result[list_name] = []
-        #     result[list_name].append([list_name, card_name] )
-
-        # return result
+        lists = self.lists(boardid)
+
+        # Get cards
+        cards = self.request("boards/{boardid}/cards".format(boardid=boardid))
+
+        # Group cards by list
+        result = {}
+        for c in cards.json():
+            list_name =  lists[c['idList']]
+            card_name = c['name']
+            if list_name not in result:
+                result[list_name] = []
+            result[list_name].append(card_name)
+
+        return result
+
+
+    def lookupBoard(self, name):
+        # TODO: check if there is an API call that already does this
+        boards = self.boards()
+        for board in boards:
+            if board["name"] == name:
+                return board["id"]
+        # TODO: handle this a little better
+        return False
+        print(boards)
 
 
     def request(self, apimethod):