Pat Lathem 10 months ago
parent
commit
c4b77fd2ca
2 changed files with 14 additions and 12 deletions
  1. 3 1
      cli.py
  2. 11 11
      trello/__init__.py

+ 3 - 1
cli.py

@@ -24,12 +24,14 @@ def boards():
     table = AsciiTable(table_data)
     print(table.table)
 
+
 @click.command()
 @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. ")
+        raise click.UsageError(
+            "Either the board ID (-i) or name (-n) is required. ")
 
     t = Trello()
 

+ 11 - 11
trello/__init__.py

@@ -11,16 +11,18 @@ class Trello(object):
         try:
             self.key = os.environ['TRELLO_KEY']
         except KeyError:
-            raise Exception('Missing environment variable: TRELLO_KEY. Obtain from https://trello.com/app-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. Obtain from https://trello.com/app-key')
+            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)
-
+        self.getauth = "key={key}&token={token}".format(
+            key=self.key, token=self.token)
 
     def boards(self):
         # List all boards
@@ -53,7 +55,7 @@ class Trello(object):
         # Group cards by list
         result = {}
         for c in cards.json():
-            list_name =  lists[c['idList']]
+            list_name = lists[c['idList']]
             card_name = c['name']
             if list_name not in result:
                 result[list_name] = []
@@ -61,22 +63,20 @@ class Trello(object):
 
         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)
-
+        raise Exception("Failed to find a board named " + name)
 
     def request(self, apimethod):
         url = self.url + apimethod + "?" + self.getauth
         # print(url )
         resp = requests.get(url)
         if resp.status_code != 200:
-            raise Exception("Wrong status code for {url}: {code}".format(url=url, code=resp.status_code))
+            raise Exception(
+                "Wrong status code for {url}: {code}".format(
+                    url=url, code=resp.status_code))
         return resp