Skip to content

Instantly share code, notes, and snippets.

@csmaniottojr
Last active January 5, 2021 19:36
Show Gist options
  • Save csmaniottojr/6e679143d16007490b0617f35d678f9c to your computer and use it in GitHub Desktop.
Save csmaniottojr/6e679143d16007490b0617f35d678f9c to your computer and use it in GitHub Desktop.
Order cards from a Trello list
import requests
import operator
params = {"token": "", "key": ""}
id_list = ""
cards = requests.get(
"https://api.trello.com/1/lists/{}/cards".format(id_list), params=params
).json()
order_by_asc = True
# sort by due date in ascending order
cards_sorted = sorted(cards, key=operator.itemgetter("due"), reverse=not order_by_asc)
pos = "bottom" if order_by_asc else "top"
for card in cards_sorted:
requests.put(
"https://api.trello.com/1/cards/{}".format(card["id"]),
params=params,
data={"pos": pos},
).json()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment