Last active
May 28, 2019 13:12
-
-
Save roman-karpovich/7cd25385e50c27c44091b4a3c00f2fd6 to your computer and use it in GitHub Desktop.
Archive old trello cards from specific list
This file contains 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
import requests | |
# get your key on https://trello.com/app-key | |
key = 'your dev key' | |
login_url = 'https://trello.com/1/authorize?key={key}&name=my_app&expiration=30days&response_type=token&scope=read,write'.format(key=key) | |
print(login_url) | |
# goto login_url and get your token | |
token = 'auth token' | |
# get board id from url: https://trello.com/b/<board_id>/<board_slug> | |
board_id = 'board id' | |
# get board lists: | |
# https://trello.com/1/boards/{board_id}/lists/ | |
lists = {l['id']: l['name'] for l in requests.get('https://trello.com/1/boards/{board_id}/lists/?key={key}&token={token}'.format(board_id=board_id, key=key, token=token)).json()} | |
print(lists) | |
archive_before = '2017-03-01' | |
list_id = 'list id' | |
archive_url = 'https://trello.com/1/cards/{}/closed?token={token}&key={key}&value=true' | |
old_cards = requests.get( | |
'https://trello.com/1/lists/{list_id}/cards/?before={archive_before}&token={token}&key={key}'.format( | |
list_id=list_id, archive_before=archive_before, key=key, token=token | |
) | |
).json() | |
for i, card in enumerate(old_cards): | |
requests.put(archive_url.format(card['id'], token=token, key=key)) | |
print('{}%'.format(float(i)/len(old_cards)*100)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment