Created
July 1, 2021 08:47
-
-
Save aydinemre/54f248f64a03f379bcfe9251356675ef to your computer and use it in GitHub Desktop.
Trello Board to csv
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 math | |
import pandas as pd | |
from trello import TrelloClient | |
client = TrelloClient( | |
api_key='', | |
api_secret='', | |
) | |
search_board = '' | |
board = None | |
for b in client.list_boards(): | |
if b.name == search_board: | |
board = b | |
break | |
data = {} | |
for l in board.list_lists(): | |
cards = [] | |
for card in l.list_cards(): | |
cards.append({'name': card.name, 'labels': [label.name for label in card.labels]}) | |
data[l.name] = cards | |
def highlight_greater(df): | |
w = 'white' | |
y = 'yellow' | |
o = 'orange' | |
g = 'green' | |
df1 = pd.DataFrame('', index=df.index, columns=df.columns) | |
def get_mask(row): | |
if isinstance(row, dict): | |
labels = row.get('labels', []) | |
if len(labels) > 0: | |
if 'Done' in labels: | |
return 'background-color: {}'.format(g) | |
elif 'In-Progress' in labels: | |
return 'background-color: {}'.format(y) | |
elif 'Review' in labels: | |
return 'background-color: {}'.format(o) | |
elif 'Backlog' in labels: | |
return 'background-color: {}'.format(w) | |
else: | |
print(labels) | |
else: | |
return 'background-color: {}'.format(w) | |
elif row == '' or math.isnan(row): | |
return 'background-color: {}'.format(w) | |
else: | |
print(row) | |
for col in df.columns: | |
print(col) | |
df1[col] = df[col].apply(get_mask) | |
return df1 | |
def extract_data(df): | |
def get_data(row): | |
if isinstance(row, dict): | |
return row.get('name', '') | |
elif row == '' or math.isnan(row): | |
return '' | |
else: | |
print(row) | |
for col in df.columns: | |
df[col] = df[col].apply(get_data) | |
return df | |
df = pd.DataFrame(dict([(k, pd.Series(v)) for k, v in data.items()])) | |
df.style. \ | |
apply(highlight_greater, axis=None). \ | |
apply(extract_data, axis=None). \ | |
to_excel('df.xlsx', engine='openpyxl', index=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment