sarumont / py-trello

Python API wrapper around Trello's API
BSD 3-Clause "New" or "Revised" License
946 stars 330 forks source link

Usage Examples #181

Open roman-ku opened 7 years ago

roman-ku commented 7 years ago

How do I operate this thing? Would be nice to have some quick usage examples for common tasks.

Mymoza commented 7 years ago

I agree! Where are you in the process? I got my key/tokens working. Still need to figure out if my GET request is working well or not. lol @roman-ku

roman-ku commented 7 years ago

So through some trial and error, I made it do what I want.

To figure out what you can do try this:

from pprint import pprint as pp
pp(dir(client))

That will give you a list of possibles methods, and you can go from there.

Another thing is to look at the files in /test and in /trello and the official trello API itself.

Here is the script I hacked together, maybe that can also help: https://gist.github.com/roman-ku/749125c854e30351112ccad8f2175687

@Mymoza

Mymoza commented 7 years ago

@roman-ku thanks! Did you manage to get the tests working? I get

$ python -m unittest discover

Ran 0 tests in 0.000s

OK

:(

roman-ku commented 7 years ago

Yep! Hopefully that was helpful.

Sorry, nope I didn't. But then again I didn't try since I wasn't modifying the source, and had no need to run any tests. Hopefully you can figure it out, good luck!

@Mymoza

berezovskyi commented 7 years ago

I have just finished writing a simple script exporting the titles of all cards of the starred boards to Markdown, feel free to (re)use it:

from trello import TrelloClient

# https://trello.com/app-key
TRELLO_API_KEY = ""
# https://trello.com/app-key at the very bottom
TRELLO_API_SECRET = ""

# export TRELLO_API_KEY="" && export TRELLO_API_SECRET="" && python utils.py
TRELLO_OAUTH = ""
# enter the PIN from the page from the step before
TRELLO_OAUTH_SECRET = ""

def main():
    client = TrelloClient(
        api_key=TRELLO_API_KEY,
        api_secret=TRELLO_API_SECRET,
        token=TRELLO_OAUTH,
        token_secret=TRELLO_OAUTH_SECRET
    )

    boards = client.list_boards(board_filter='starred')

    for b in boards:
        print("\n# {}\n\n".format(b.name))
        print_board(b)

def print_board(board):
    lists = board.list_lists()
    for l in lists:
        print("\n## {}\n".format(l.name))
        print_list(l)

def print_list(lst):
    cards = lst.list_cards()
    for c in cards:
        print("* {}".format(c.name))

if __name__ == '__main__':
    main()

The MIT License (MIT)

Copyright (c) 2017 Andrew Berezovskyi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

superghm commented 6 years ago

Thank you @berezovskyi !

akakiev commented 6 years ago

I want to return/print all trello cards that have been done, another words all trello cards from one "List Done" list but not from all lists in board. How can I do that ?

mbbroberg commented 5 years ago

Your post was a godsend @berezovskyi. I was able to get running using it, forking the source code, and running the python/util.py command as described to get my token and token secret set up.

Thank you! :pray: