Skip to content

Instantly share code, notes, and snippets.

@p53ud0k0d3
Created September 21, 2018 07:26
Show Gist options
  • Select an option

  • Save p53ud0k0d3/df9c1bd7b01c3abe211904ef03a13105 to your computer and use it in GitHub Desktop.

Select an option

Save p53ud0k0d3/df9c1bd7b01c3abe211904ef03a13105 to your computer and use it in GitHub Desktop.
from trello import TrelloClient
import requests
API_KEY = ""
API_SECRET = ""
TOKEN = ""
BOARD_NO = 0
LIST_NO = 10
client = TrelloClient(
api_key=API_KEY,
api_secret=API_SECRET,
token=TOKEN
)
board = client.list_boards()[BOARD_NO]
list_id = board.list_lists()[LIST_NO].id
my_list = board.get_list(list_id)
cards = my_list.list_cards()
attachments = []
for card in cards:
attachments.append(card.get_attachments()[0].url)
for url in attachments:
filename = url.split('/')[-1]
r = requests.get(url, allow_redirects=True)
open(filename, 'wb').write(r.content)
@Ppang0405

Copy link
Copy Markdown

for today, 2023, Idk why the attachment URL does not have the file extension, but this workaround worked for me.

from trello import TrelloClient
import requests


API_KEY = ""
API_SECRET = ""
TOKEN = ""

BOARD_NO = 0
LIST_NO = 10

client = TrelloClient(
    api_key=API_KEY,
    api_secret=API_SECRET,
    token=TOKEN
)

board = client.list_boards()[BOARD_NO]
list_id = board.list_lists()[LIST_NO].id
my_list = board.get_list(list_id)
cards = my_list.list_cards()
attachments = []
for card in cards:
    attachments.append(card.get_attachments()[0].url)

for url in attachments:
    filename = url.split('/')[-1]
    r = requests.get(url, allow_redirects=True)
    open(f"{filename}.jpeg", 'wb').write(r.content)
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment