Last active
June 5, 2019 04:05
-
-
Save bzcorn/a00c7a38dd93761521e2aea87e154aa5 to your computer and use it in GitHub Desktop.
This takes exported mingle card data and pushes it to trello
This file contains hidden or 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
| ''' | |
| 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Getting this error. Any ideas @bzcorn