Skip to content

Instantly share code, notes, and snippets.

@bzcorn
Last active June 5, 2019 04:05
Show Gist options
  • Select an option

  • Save bzcorn/a00c7a38dd93761521e2aea87e154aa5 to your computer and use it in GitHub Desktop.

Select an option

Save bzcorn/a00c7a38dd93761521e2aea87e154aa5 to your computer and use it in GitHub Desktop.
This takes exported mingle card data and pushes it to trello
'''
MIT License
Copyright (c) 2019 Ben Cornelius
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
'''
"""
Basic Instructions
0) Get Trello API keys and install py-trello
1) import the cards from CSV into python
2) setup your variables
3) create your conversion dict for Created by > Trello Members
4) run it
"""
from trello import TrelloClient
import csv
# Fill in these variables
client = TrelloClient(
api_key=,
api_secret=,
)
csv_file_name = ''
filter_list = []
filter_status = []
board_name = ''
#conversion dict
conversion = {
'mingle_user_1': 'trello_equivalent_1',
'mingle_user_n': 'trello_equivalent_n',
}
# Script begins
def get_boards(client):
d = {}
boards = client.list_boards()
for board in boards:
d[board.name] = client.get_board(board.id)
return d
def add_card(list, card_name, description='',assign=[]):
list.add_card(
card_name,
desc=description,
labels=None,
due="null",
source=None,
position=None,
assign=assign
)
def get_trello_lists_as_dict(board):
trello_lists = {}
for trello_list in board.open_lists():
trello_lists[trello_list.name] = trello_list
return trello_lists
def get_member_object(client, member_name):
for member in client.list_organizations()[0].get_members():
if member_name == member.full_name:
return member
def add_to_board(client, csv, board, names={}):
trello_lists = get_trello_lists_as_dict(board)
for row in csv:
card_name = row['Name']
desc = "Origin was Mingle card #{}. Created on {}.".format(
row['Number'],
row['Moved to Backlog on']
)
if len(names) > 0:
full_name = names[row['Created by']]
trello_member = get_member_object(client, full_name)
add_card(
trello_lists[row['Status']],
card_name,
description=desc,
assign=[trello_member]
)
def main():
csv = []
with open(csv_file_name, newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if row['Created by'] in filter_list:
pass
elif row['Status'] in filter_status:
print (row['Status'])
pass
else:
csv.append(row)
mingle_users = []
for row in l:
if row['Created by'] not in mingle_users:
mingle_users.append(row['Created by'])
board = get_boards(client)[board_name]
add_to_board(client, csv, board, names=conversion)
if __name__ == "__main__":
main()
@Breeze773
Copy link
Copy Markdown

Breeze773 commented Jun 5, 2019

Getting this error. Any ideas @bzcorn

File "mingleToTrello.py", line 129, in main
    reader = csv.DictReader(csvfile)
AttributeError: 'list' object has no attribute 'DictReader'```

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