Browse Source

Quick and dirty search support

Pat Lathem 10 months ago
parent
commit
2b13ff0d9f
2 changed files with 31 additions and 2 deletions
  1. 16 0
      cli.py
  2. 15 2
      trello/__init__.py

+ 16 - 0
cli.py

@@ -1,3 +1,5 @@
+import json
+
 import click
 from terminaltables import AsciiTable
 
@@ -47,7 +49,21 @@ def cards(id, name):
         print()
 
 
+@click.command()
+@click.option('-q', '--query', required=True, type=click.STRING)
+# TODO: type filtering
+@click.option('-t', '--type', required=False, type=click.STRING)
+def search(query, type):
+    t = Trello()
+
+    # TODO: need to build classes for actions, ards, boards, organizations,
+    # members
+    resp = t.search(query)
+    print(json.dumps(resp, sort_keys=True, indent=4))
+
+
 if __name__ == '__main__':
     cli.add_command(boards)
     cli.add_command(cards)
+    cli.add_command(search)
     cli()

+ 15 - 2
trello/__init__.py

@@ -1,4 +1,5 @@
 import os
+import urllib
 
 import requests
 
@@ -71,9 +72,21 @@ class Trello(object):
                 return board["id"]
         raise Exception("Failed to find a board named " + name)
 
+    def search(self, query, type=None):
+        uequery = urllib.parse.quote(query)
+        resp = self.request("search?query=" + uequery)
+
+        # TODO: type filtering
+        # Possible values are 'actions', 'cards', 'boards', 'organizations',
+        # 'members'
+        return resp.json()
+
     def request(self, apimethod):
-        url = self.url + apimethod + "?" + self.getauth
-        # print(url )
+        sep = "?"
+        if "?" in apimethod:
+            sep = "&"
+        url = self.url + apimethod + sep + self.getauth
+
         resp = requests.get(url)
         if resp.status_code != 200:
             raise Exception(