├── .gitignore ├── INSTALL.py ├── README.md ├── plugin └── trello.vim └── requirements.txt /.gitignore: -------------------------------------------------------------------------------- 1 | scripts/ 2 | trello 3 | 4 | *.pyc 5 | *.swp 6 | *~ 7 | *.sublime* 8 | 9 | -------------------------------------------------------------------------------- /INSTALL.py: -------------------------------------------------------------------------------- 1 | ### Modified version of https://github.com/sarumont/py-trello/blob/master/trello/util.py 2 | 3 | import os 4 | import urlparse 5 | import codecs 6 | import json 7 | 8 | import oauth2 as oauth 9 | 10 | CON_FILE = '.trello-vim' 11 | configs = {'key': None, 'token': None, 'url': False, 'label':False, 'done_cards': False} 12 | 13 | def create_oauth_token(): 14 | """ 15 | Script to obtain an OAuth token from Trello. 16 | 17 | More info on token scope here: 18 | https://trello.com/docs/gettingstarted/#getting-a-token-from-a-user 19 | """ 20 | request_token_url = 'https://trello.com/1/OAuthGetRequestToken' 21 | authorize_url = 'https://trello.com/1/OAuthAuthorizeToken' 22 | access_token_url = 'https://trello.com/1/OAuthGetAccessToken' 23 | 24 | 25 | print "Visit https://trello.com/1/appKey/generate to obtain API keys" + "\n" 26 | expiration = 'never' 27 | scope = 'read' 28 | trello_key = str(raw_input('API KEY >')) 29 | trello_secret = str(raw_input('API SECRET >')) 30 | 31 | consumer = oauth.Consumer(trello_key, trello_secret) 32 | client = oauth.Client(consumer) 33 | 34 | # Step 1: Get a request token. This is a temporary token that is used for 35 | # having the user authorize an access token and to sign the request to obtain 36 | # said access token. 37 | 38 | resp, content = client.request(request_token_url, "GET") 39 | if resp['status'] != '200': 40 | raise Exception("Invalid response %s." % resp['status']) 41 | 42 | request_token = dict(urlparse.parse_qsl(content)) 43 | 44 | print "Request Token:" 45 | print " - oauth_token = %s" % request_token['oauth_token'] 46 | print " - oauth_token_secret = %s" % request_token['oauth_token_secret'] 47 | print 48 | 49 | # Step 2: Redirect to the provider. Since this is a CLI script we do not 50 | # redirect. In a web application you would redirect the user to the URL 51 | # below. 52 | 53 | print "Go to the following link in your browser:" 54 | print "{authorize_url}?oauth_token={oauth_token}&scope={scope}&expiration={expiration}".format( 55 | authorize_url=authorize_url, 56 | oauth_token=request_token['oauth_token'], 57 | expiration=expiration, 58 | scope=scope, 59 | ) 60 | 61 | # After the user has granted access to you, the consumer, the provider will 62 | # redirect you to whatever URL you have told them to redirect to. You can 63 | # usually define this in the oauth_callback argument as well. 64 | accepted = 'n' 65 | while accepted.lower() == 'n': 66 | accepted = raw_input('Have you authorized me? (y/n) ') 67 | oauth_verifier = raw_input('What is the PIN? ') 68 | 69 | # Step 3: Once the consumer has redirected the user back to the oauth_callback 70 | # URL you can request the access token the user has approved. You use the 71 | # request token to sign this request. After this is done you throw away the 72 | # request token and use the access token returned. You should store this 73 | # access token somewhere safe, like a database, for future use. 74 | token = oauth.Token(request_token['oauth_token'], 75 | request_token['oauth_token_secret']) 76 | token.set_verifier(oauth_verifier) 77 | client = oauth.Client(consumer, token) 78 | 79 | resp, content = client.request(access_token_url, "POST") 80 | access_token = dict(urlparse.parse_qsl(content)) 81 | 82 | configs['key'] = trello_key 83 | configs['token'] = access_token['oauth_token'] 84 | show_url = raw_input('Do you want to show card urls?(y/n)') 85 | if show_url.lower() == 'y': 86 | configs['url'] = True 87 | 88 | show_label = raw_input('Do you want to show card labels?(y/n)') 89 | if show_label.lower() == 'y': 90 | configs['label'] = True 91 | 92 | show_done_cards = raw_input('Do you want to show done cards?(y/n)') 93 | if show_done_cards.lower() == 'y': 94 | configs['done_cards'] = True 95 | 96 | f = codecs.open(os.path.expanduser('~') + '/' + CON_FILE, 'wb') 97 | json.dump(configs, f) 98 | 99 | print "Access Token:" 100 | print " - oauth_token = %s" % access_token['oauth_token'] 101 | print 102 | print "Configurations are now saved in .trello-vim file in home directory." 103 | print "You are ready to use the plugin" 104 | 105 | if __name__ == '__main__': 106 | create_oauth_token() -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | A barebone vim plugin to fetch user assigned cards from Trello 2 | 3 | ## Requirements 4 | * Vim compiled with Python 5 | * Trello API keys 6 | 7 | ## Installation 8 | #### Using Vundle 9 | 10 | Append this to .vimrc 11 |
Plugin 'malithsen/trello-vim'
12 |
13 |
14 | Then install in the usual way
15 | :PluginInstall
16 |
17 |
18 | Run INSTALL.py and follow the instructions
19 | python ~/.vim/bundle/trello-vim/INSTALL.py
20 |
21 |
22 | Above step is an one time procedure to set up trello oauth tokens
23 |
24 | ## Usage
25 | Open assigned cards in a new buffer
26 | :Cards
27 |
28 |
29 |
--------------------------------------------------------------------------------
/plugin/trello.vim:
--------------------------------------------------------------------------------
1 | if !has('python')
2 | echo "Error: Requires vim compiled with python"
3 | finish
4 | endif
5 |
6 | function! Cards()
7 |
8 | python << EOF
9 |
10 | import vim
11 | import urllib2
12 | import os
13 | import json
14 | import codecs
15 |
16 | CON_FILE = '.trello-vim'
17 |
18 | f = codecs.open(os.path.expanduser('~') + '/' + CON_FILE)
19 | configs = json.loads(f.read())
20 |
21 | SHOW_CARD_URL = configs['url']
22 | SHOW_LABELS = configs['label']
23 | SHOW_DONE_CARDS = configs['done_cards']
24 |
25 | KEY_TOKEN = {'key': configs['key'], 'token': configs['token']}
26 | CARDS_URL = 'https://trello.com/1/members/my/cards?key={key}&token={token}'.format(**KEY_TOKEN)
27 | LISTS_URL = 'https://trello.com/1/lists/%s?key={key}&token={token}'.format(**KEY_TOKEN)
28 |
29 | try:
30 | request = json.loads(urllib2.urlopen(CARDS_URL).read())
31 | vim.command("vnew trello")
32 | del vim.current.buffer[:]
33 | vim.current.buffer[0] = "Cards assigned to you"
34 | vim.current.buffer.append(35 * "=")
35 |
36 | columns = {}
37 | for card in request:
38 | name = card['name'].encode("UTF-8")
39 | url = card['url'].encode("UTF-8")
40 | column_id = card['idList']
41 | column_name = columns.get(column_id, None)
42 | if not column_name:
43 | COLUMN_URL = LISTS_URL % column_id
44 | column_request = json.loads(urllib2.urlopen(COLUMN_URL).read())
45 | column_name = column_request['name'].encode('UTF-8')
46 | columns.update({column_id: column_name})
47 |
48 | if SHOW_DONE_CARDS or column_name != 'Done':
49 | vim.current.buffer.append("→→ %s" % column_request['name'].encode('UTF-8'))
50 | vim.current.buffer.append("→ %s" % name)
51 | if SHOW_LABELS:
52 | labels = []
53 | for label in card['labels']:
54 | labels.append(label['name'].encode('UTF-8') or label['color'].encode('UTF-8'))
55 | all_labels = ', '.join(labels)
56 | if all_labels:
57 | vim.current.buffer.append("Labels: %s" % all_labels)
58 | if SHOW_CARD_URL:
59 | vim.current.buffer.append("URL: %s" % url)
60 | vim.current.buffer.append(35 * "-")
61 |
62 | except Exception, e:
63 | print e
64 |
65 | EOF
66 |
67 | endfunction
68 |
69 | command! -nargs=0 Cards call Cards()
70 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | oauth2==1.5.211
2 |
3 |
--------------------------------------------------------------------------------