Instantly share code, notes, and snippets.
Created
February 6, 2016 16:03
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save jaimergp/3845d1ac98f9c67e7f5b to your computer and use it in GitHub Desktop.
Trello Series board banners with TVDB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Set banner headings to your Trello Series board automatically" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"You'll need to install two Python packages, available with pip: \n", | |
"* [py-trello](https://github.com/sarumont/py-trello)\n", | |
"* [tvdb_api](https://github.com/dbr/tvdb_api)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"from trello import TrelloClient\n", | |
"from tvdb_api import Tvdb" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"First, get your api keys and authorize your user:\n", | |
"* `api_key` and `api_secret` are listed in this [Trello page](https://trello.com/app-key)\n", | |
"* `token` and `token_secret` must be retrieved for your user via OAuth. Read [here](https://github.com/sarumont/py-trello#getting-your-trello-oauth-token)\n", | |
"\n", | |
"Last, specify the name of your series board. This script assumes that your cards are named like this: `TV Series title S01E02` or `Upcoming series S01`. I mean, it will split the last *word* out of the name and probably won't work if you don't follow my convention." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"api_key = \"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\"\n", | |
"api_secret = \"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\"\n", | |
"token = \"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\"\n", | |
"token_secret = \"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\"\n", | |
"series_board_name = 'Series'" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Now, the actual script." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"client = TrelloClient(api_key, api_secret, token, token_secret)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"series = [b for b in client.list_boards() if b.name.decode('utf-8') == series_board_name][0]\n", | |
"cards = series.all_cards()\n", | |
"names = [c.name.decode('utf-8') for c in cards]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"tvdb = Tvdb(banners=True)\n", | |
"results = [tvdb.search(' '.join(n.split()[:-1]))[0] for n in names]\n", | |
"banners = [\"http://thetvdb.com/banners/{}\".format(r['banner']) for r in results]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"for card, banner in zip(cards, banners):\n", | |
" card.attach(url=banner)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Final result:\n", | |
"\n", | |
"" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.5.1" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding: utf-8 | |
# Set banner headings to your Trello Series board automatically | |
# You'll need to install two Python packages, available with pip: | |
# * [py-trello](https://github.com/sarumont/py-trello) | |
# * [tvdb_api](https://github.com/dbr/tvdb_api) | |
from trello import TrelloClient | |
from tvdb_api import Tvdb | |
# First, get your api keys and authorize your user: | |
# * `api_key` and `api_secret` are listed in this [Trello page](https://trello.com/app-key) | |
# * `token` and `token_secret` must be retrieved for your user via OAuth. | |
# Read [here](https://github.com/sarumont/py-trello#getting-your-trello-oauth-token) | |
# | |
# Last, specify the name of your series board. This script assumes that your cards are named | |
# like this: `TV Series title S01E02` or `Upcoming series S01`. I mean, it will split the last | |
# *word* out of the name and probably won't work if you don't follow my convention. | |
api_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | |
api_secret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | |
token = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | |
token_secret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | |
series_board_name = 'Series' | |
############################################################################################## | |
# Now, the actual code. | |
client = TrelloClient(api_key, api_secret, token, token_secret) | |
series = [b for b in client.list_boards() if b.name.decode('utf-8') == series_board_name][0] | |
cards = series.all_cards() | |
names = [c.name.decode('utf-8') for c in cards] | |
tvdb = Tvdb(banners=True) | |
results = [tvdb.search(' '.join(n.split()[:-1]))[0] for n in names] | |
banners = ["http://thetvdb.com/banners/{}".format(r['banner']) for r in results] | |
for card, banner in zip(cards, banners): | |
card.attach(url=banner) | |
# Final result: | |
# | |
#  |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment