def form(form_id, label, title): trel = Trello() conf = Confluence() """ makes form options is a dict? possible dec num of params? """ # headers: is label neccesary? form = '<form id="{}">'.format(form_id) label = '<label for="{}">{}</label>'.format(label, title) # generalize below using "for options in options_list" resp = trel.get_a_on_b(a='lists', b='boards', b_id=board_id) lists = { l['name'] : l['id'] for l in resp } html += select('trello', 'trelloList', lists) spaces = conf.get_spaces() html += select('confluence', 'confSpace', spaces) html += button('submit', 'mod-primary', 'Create Page!') # close form html += '</form>' html += '<script src="{}"></script>'.format('./js/modal.js') pprint(html) return html
def process_trello_token_conv(self, bot, update, user_data): logger.info("Got to process_trello_token") trello_token = update.message.text.strip() trello = Trello(trello_token) starred_boards = trello.get_starred_boards() if starred_boards is None: update.message.reply_text( "Sorry, the token looks invalid. " "Restart the process using /setup and then " "choose a new, valid one.\nEND." ) return ConversationHandler.END user_data["trello_token"] = trello_token update.message.reply_text( "Token validated successfully. Please choose, among these, your preferred board for " "ideas collection. There are listed only starred boards. " "If it's not among them, star your preferred board, and then restart the process.", reply_markup=ReplyKeyboardMarkup( [ [ '{name} ({part_id})'.format(name=x['name'], part_id=x['id'][:4]) for k, x in starred_boards.items() ], ['/cancel'] ], one_time_keyboard=True, ), ) return _CONV_STATE_SETUP_BOARD
def process_trello_board_conv(self, bot, update, user_data): logger.info("Got to process_trello_board") trello_token = user_data["trello_token"] chosen_board_name = update.message.text.split("(")[0].strip() chosen_board_id = update.message.text.split("(")[1].replace(")", "") trello = Trello(trello_token) starred_boards = trello.get_starred_boards() if starred_boards is None: return self.error(update, user_data, "invalid trello token") candidate_boards = [v for k, v in starred_boards.items() if chosen_board_id in k] final_board = None for candidate_board in candidate_boards: if candidate_board['name'] == chosen_board_name: final_board = candidate_board break if final_board is None: return self.error(update, user_data, "No valid board found") else: chosen_board_id = final_board['id'] chosen_board_name = final_board['name'] board_lists = trello.get_board_lists(chosen_board_id) if board_lists is None: return self.error(update, {}, "Trello token expired. Restart doing /setup and " "then saving your stuff again.") inbox_list_id = None for k, l in board_lists.items(): if l['name'] == DEFAULT_LIST_NAME: inbox_list_id = l['id'] break else: if len(board_lists.items()) > 0: inbox_list_id = [v for k, v in board_lists.items()][0]['id'] self.setup_user(tg_id=update.message.from_user.id, trello_token=trello_token, chosen_board_id=chosen_board_id, chosen_board_name=chosen_board_name, inbox_list_id=inbox_list_id) update.message.reply_text("Setup completed. You can now fully use the bot.") return ConversationHandler.END
def get_mock_trello(trello_config): api_client = ApiClient() api_client.get = mock_get([{ "id": "5eeb648682bb2c685cc659f0", "name": NOT_STARTED, "closed": False, "pos": 1, "softLimit": None, "idBoard": "5eeb6486ebbfa66d2e519922", "subscribed": False }, { "id": "5eeb648623bb2c685cc659f0", "name": IN_PROGRESS, "closed": False, "pos": 2, "softLimit": None, "idBoard": "5eeb6486ebbfa66d2e519922", "subscribed": False }, { "id": "5eeb6486cae807625c9f0819", "name": COMPLETED, "closed": False, "pos": 3, "softLimit": None, "idBoard": "5eeb6486ebbfa66d2e519922", "subscribed": False }]) trello = Trello(trello_config, api_client) return trello, api_client, trello_config
def main(): api_key = "YOUR_API_KEY_HERE" token = "YOUR_TOKEN_HERE" board_id = "BOARD_ID_HERE" list_name = "LIST_NAME_HERE" xlsx_file_path = "data.xlsx" label_name = "LABEL_NAME_HERE" MyTrello = Trello(api_key, token) B = MyTrello.GetBoardById(board_id) TodoList = B.GetListByName(list_name) wb = load_workbook(xlsx_file_path) sheet = wb.active max_row = sheet.max_row label = B.GetLabelByName(label_name) for i in range(2, max_row + 1): # iterate over all columns print(i) question = sheet.cell(row=i, column=1).value Card = MyTrello.new('Card', question, TodoList) comment = sheet.cell(row=i, column=2).value # Test if comment is empty if comment is not None: Card.SetDesc(comment) priority = sheet.cell(row=i, column=3).value difficulty = sheet.cell(row=i, column=4).value Card.AddLabel(label)
def test_app(): trello_config = Config(".env").trello_config trello = Trello(trello_config, ApiClient()).create_test_board() application = app.create_app({}, trello) thread = Thread(target=lambda: application.run(use_reloader=False)) thread.daemon = True thread.start() # I really feel like this shouldn't be necessary, but otherwise selenium makes requests before flask has started time.sleep(1) yield app thread.join(1) trello.delete_board()
def append_card(self, update, content, card_name, list_name=None, list_id=None, content_type='text'): if (list_name is None) & (list_id is None): raise Exception("No list provided!") trello = Trello(self._USER_SETUPS[self.get_tg_id(update)]['trello_token']) if list_id is not None: list_name = DEFAULT_LIST_NAME else: board_lists = trello.get_board_lists(self._USER_SETUPS[self.get_tg_id(update)]['board_id']) if board_lists is None: return self.error(update, {}, "Trello token expired. Restart doing /setup and " "then saving your stuff again.") if list_name[0] == "_": list_name = list_name[1:] # Check if it already exists for k, l in board_lists.items(): if l['name'] == list_name: list_id = l['id'] break else: # NEW LIST! list_id = trello.create_list_in_board(list_name, self._USER_SETUPS[self.get_tg_id(update)]['board_id']) else: for k, l in board_lists.items(): if l['name'] == list_name: list_id = l['id'] break else: return self.error(update, {}, "No list found matching your choice. Restart please.") result = trello.create_card_in_list(list_id, card_name, content, content_type) logger.info("Done! Created card with ID: {}".format(result)) update.message.reply_text("Done! Put the {} into #{} as *{}".format(content_type, list_name, card_name))
class TrelloTestCase(unittest.TestCase): """Trello Api tester""" TEST_TOKEN = "36b68eef1b52420e5731962cdb0bef1e8f152874b10f6036ed30bd9f117dc2fe" TEST_BOARD_ID = "54d10ee46bd364a1e6f063ea" TEST_CARD_ID = "54d10f4c8777eefd6328ad43" def setUp(self): self.trello = Trello(TrelloTestCase.TEST_TOKEN) def test01_getRecords_unit(self): self.trello.make_call = Mock() self.trello.make_call.return_value.json.return_value = { 'record': 'some record' } print("User Records:") pprint.pprint(self.trello.get_records()) assert self.trello.record == {'record': 'some record'} # def test02_getAllBoards_unit(self): # print("User Boards:") # mock = Mock() # #self.trello.get_all_boards = Mock(return_value={"boards":"Got boards!"}) # pprint.pprint(self.trello.get_all_boards(mock)) # mock.requests.get.assert_called_with() # #assert self.trello.boards == {"boards":"Got boards!"} # # # def test03_getAllBoards_integrate(self): # print("User Boards:") # pprint.pprint(self.trello.get_all_boards()) # def test03_getBoard(self): # print("User Test Board:") # pprint.pprint(self.trello.get_board(TrelloTestCase.TEST_BOARD_ID)) # def test04_getAllCards(self): print("Cards:") pprint.pprint(self.trello.get_all_cards())
def process_anything_text(bot, update, user_data): if not app.is_user_setup(update): update.message.reply_text("You are not authenticated yet. Use /setup please.") user_data.clear() return content = update.message.text content_type = 'text' if len(update.message.entities) > 0: if update.message.entities[0].type == 'url': content_type = 'url' user_data['_content'] = content user_data['_content_type'] = content_type user_data['_card_name'] = str(content)[:DEFAULT_CARD_NAME_LEN] if content_type != 'url' else content trello = Trello(app._USER_SETUPS[app.get_tg_id(update)]['trello_token']) board_lists = trello.get_board_lists(app._USER_SETUPS[app.get_tg_id(update)]['board_id']) if board_lists is None: board_lists = [] update.message.reply_text( "Where do you want to save it?", reply_markup=ReplyKeyboardMarkup( [ [ '#{list_name}'.format(list_name=l['name']) for k, l in board_lists.items() ], ['/cancel'] ], one_time_keyboard=True, ), ) return _CONV_STATE_CHOOSE_LIST
def link(): config_yaml = open("config.yaml", "r") config = yaml.load(config_yaml) config_yaml.close() trello_board = config["trello_board"] git = Git(config["git_username"], config["git_email"], config["git_password"]) trello = Trello(config["trello_key"], config["trello_token"]) #first get all issues from the github repo shared_topics = {} issues = git.getIssues("Brewmaster") issue_titles = [] for issue in issues: issue_titles.append(issue["title"]) #get all cards from trello board card_names = [] cards = trello.getCards(trello_board) for card in cards: card_names.append(card["name"]) for label in card["labels"]: if GIT == label["name"]: if not card["name"] in issue_titles: label_list = [] for label in card["labels"]: if not label["name"] == GIT: label_list.append(label["name"]) title = card["name"] body = card["desc"] response = git.raiseIssue("Brewmaster", title, body, labels=label_list) comments = trello.getCardComments(card["id"]) for comment in comments: body = comment["data"]["text"] git.comment("Brewmaster", response["number"], body) else: shared_topics[str(card["name"])] = [card] lists = trello.getLists(config["trello_board"]) labels = trello.getLabels(config["trello_board"]) for issue in issues: if not issue["title"] in card_names: #add issue as a trello card #label it name = issue["title"] desc = issue["body"] label_list = [] for label in issue["labels"]: label_list.append(label["name"]) label_ids = [] for label in labels: if label["name"].lower() in label_list: label_ids.append(label["id"]) if label["name"] == GIT: label_ids.append(label["id"]) list_name = None if issue["state"] == "open": if issue["comments"] > 0: list_name = "Doing" else: list_name = "To Do" else: list_name = "Done" list_id = None for list in lists: if list["name"] == list_name: list_id = list["id"] response = trello.addCard(name, desc, list_id, label_ids) #add all comments as trello card comments comments = git.getIssueComments("Brewmaster", str(issue["number"])) for comment in comments: body = comment["body"] trello.comment(response["id"], body) else: shared_topics[issue["title"]].append(issue) """ next check if each issue/card in the dictionary are synced if not, then adjust the older version to match the most recently updated version Check update times: card["dateLastActivity"], issue["updated_at"] Formatted: 2015-09-27T00:12:32.556Z 2015-09-26T21:52:01Z """ for key in shared_topics.keys(): #both on Zulu time issue = shared_topics[key][1] card = shared_topics[key][0] issue_time = issue["updated_at"] card_time = card["dateLastActivity"] issue_time = datetime.strptime(issue_time,"%Y-%m-%dT%H:%M:%SZ") card_time = datetime.strptime(card_time,"%Y-%m-%dT%H:%M:%S.%fZ") if issue_time > card_time: sync(git, trello, issue, card, "issue", config) elif card_time > issue_time: sync(git, trello, issue, card, "card", config)
} # Get the options parser = ArgumentParser(description='Manage Josue''s Trello cards') parser.add_argument('-d', '--directory', default='.', help='Directory to check for files (default is the current directory)') parser.add_argument('-l', '--language', default='es', help='Language to be used for the card (default = "es")') parser.add_argument('NAME', help='The card name') args = parser.parse_args() directory = args.directory language = args.language.upper() name = args.NAME # Get the card description if not path.exists(directory): exit('No se encontró el directorio {}'.format(directory)) files = '\n'.join(['- ' + f for f in listdir(directory)]) description = '{}:\n{}'.format(LABELS[language], files) # Create the card configFile = '{}/.config/trllmgr/josue.yml'.format(str(Path.home())) config = safe_load(open(configFile)) listId = config['board']['lists'][language] trll = Trello(config['security']['key'], config['security']['token']) response = trll.addCard(listId, name, description).json() print(response)
def main(list_id, space_id): trel = Trello() conf = Confluence() page = trel.format_page(list_id) # html pageData conf.create_page(page, space_key) # creates page print('\n\n\n page.py script is done!!! \n\n\n') # TEST
def main(): colorama.init() parser = argparse.ArgumentParser(description='Convert Trello list to web page.') parser.add_argument('--board', metavar='BOARD', type=str, help='Trello board', required=True) group = parser.add_mutually_exclusive_group(required=True) group.add_argument('--list', action='store_true', help='show Trello lists') group.add_argument('--convert', metavar='LIST', type=str, help='convert Trello list') args = parser.parse_args() trello = Trello("443c66695279580563e6aee40eed2811") # Read or generate token try: trello.set_token(open(".token", "r").read()) trello.user_get("me") except Exception as e: print("Go to", trello.get_token_url("trello-to-html"), "and authorize the application. After you have" "authorized the application you'll be given a token. Copy and paste that here", "\n") trello.set_token(input("Enter your token: ")) open(".token", "w").write(trello.get_token()) # List Trello lists if args.list: trello_lists = trello.boards_get_list_open(args.board) for trello_list in trello_lists: print(trello_list["name"]) return 0 # Convert Trello list elif args.convert is not None: trello_lists = trello.boards_get_list_open(args.board) for trello_list in trello_lists: if trello_list["name"] == args.convert: print("Converting", trello_list["name"]) trello_list = trello.list_get_cards(trello_list["id"]) generate(trello_list) return 0 else: print("No such list") return 1 return 0
import sys from trello import Trello if __name__ == '__main__': try: obj = Trello() obj.login() obj.build_team() obj.create_new_board() obj.init_tasks() obj.rand_drag_all_cards() except Exception as e: print(f'{e.__class__.__name__}: {e}') sys.exit(1)
if __name__ == '__main__': args = parse_args() config = configparser.ConfigParser() config.read(args.config) # load URL list file urls = [] with open(args.input_path) as f: for line in f: url = line.strip() if url == '': continue urls.append(url) # parse web pages webpages = [] for url in urls: webpages.append(Webpage.factory(url)) time.sleep(CRAWL_TIME_INTERVAL) trello = Trello(config['trello']['api_key'], config['trello']['api_token'], config['trello']['t_list_id'] ) # put data into Trello for q in webpages: trello.create_card(q.title, q.url)
def setUp(self): self.trello = Trello(TrelloTestCase.TEST_TOKEN)
# Planning Board Lists # {u'pos': 16384, u'idBoard': u'34sdw9576fee44f982b0009ec', u'id': u'34sd9576fee44f982b0009ed', u'closed': False, u'name': u'Next Up'} # {u'pos': 32768, u'idBoard': u'34sdw9576fee44f982b0009ec', u'id': u'34sd9576fee44f982b0009ee', u'closed': False, u'name': u'Spec'} # {u'pos': 49152, u'idBoard': u'34sdw9576fee44f982b0009ec', u'id': u'34sd9576fee44f982b0009ef', u'closed': False, u'name': u'Design'} # {u'pos': 115712, u'idBoard': u'34sdw9576fee44f982b0009ec', u'id': u'34sd95be04bf835957000b42', u'closed': False, u'name': u'Ready'} # Current development Board Lists # {u'pos': 9216, u'idBoard': u'34sdw427a6320f450000d4d', u'id': u'34sdw935eae09f8c03200048e', u'closed': False, u'name': u'Next Up'} # {u'pos': 16384, u'idBoard': u'34sdw427a6320f450000d4d', u'id': u'34sdw93427a6320f450000d4e', u'closed': False, u'name': u'In Progress'} # {u'pos': 32768, u'idBoard': u'34sdw427a6320f450000d4d', u'id': u'34sdw93427a6320f450000d4f', u'closed': False, u'name': u'QA'} # {u'pos': 49152, u'idBoard': u'34sdw427a6320f450000d4d', u'id': u'34sdw93427a6320f450000d50', u'closed': False, u'name': u'Launchpad'} # {u'pos': 115712, u'idBoard': u'34sdw427a6320f450000d4d', u'id': u'34sdw938e4571979847000d64', u'closed': False, u'name': u'Live'} pivotal = Pivotal() trello = Trello() # unscheduled 32162031 movements = { 'icebox_bugs': {'target': bugs_inbox_id, 'filters': {'filter': 'type:bug state:unscheduled'}}, 'icebox_features': {'target': planning_nextup_id, 'filters': {'filter': 'type:feature,chore state:unscheduled', 'limit': '10', 'offset': '76'}}, 'current_nextup': {'target': current_nextup_id, 'filters': {'filter': 'state:unstarted', 'limit': '30', 'offset': '10'}}, 'current_inprogress': {'target': current_inprogress_id, 'filters': {'filter': 'state:started'}}, 'current_qa': {'target': current_qa_id, 'filters': {'filter': 'state:finished'}}, 'current_live': {'target': current_live_id, 'filters': {'filter': 'state:delivered', 'limit': '30', 'offset': '7'}}, 'current_inprogress2': {'target': current_inprogress_id, 'filters': {'filter': 'state:rejected'}}, # 'icebox_features': {'target': planning_nextup_id, 'filters': {'filter': 'id:43068683,41430591,33693103,33691827,32161881,37317209'}} # 'icebox_bugs': {'target': bugs_inbox_id, 'filters': {'filter': 'id:41753701,38746909'}} }
# main script to make Conf page from Trello list from trello import Trello from confluence import Confluence if __name__ == "__main__": t = Trello() conf = Confluence() conf.create_page(t.mmain()) print('main sript done!')
def main(): colorama.init() parser = argparse.ArgumentParser( description='Convert Trello list to web page.') parser.add_argument('--board', metavar='BOARD', type=str, help='Trello board', required=True) group = parser.add_mutually_exclusive_group(required=True) group.add_argument('--list', action='store_true', help='show Trello lists') group.add_argument('--convert', metavar='LIST', type=str, help='convert Trello list') args = parser.parse_args() trello = Trello("443c66695279580563e6aee40eed2811") # Read or generate token try: trello.set_token(open(".token", "r").read()) trello.user_get("me") except Exception as e: print( "Go to", trello.get_token_url("trello-to-html"), "and authorize the application. After you have" "authorized the application you'll be given a token. Copy and paste that here", "\n") trello.set_token(input("Enter your token: ")) open(".token", "w").write(trello.get_token()) # List Trello lists if args.list: trello_lists = trello.boards_get_list_open(args.board) for trello_list in trello_lists: print(trello_list["name"]) return 0 # Convert Trello list elif args.convert is not None: trello_lists = trello.boards_get_list_open(args.board) for trello_list in trello_lists: if trello_list["name"] == args.convert: print("Converting", trello_list["name"]) trello_list = trello.list_get_cards(trello_list["id"]) generate(trello_list) return 0 else: print("No such list") return 1 return 0
import requests as r import json as j from trello import Trello from zendesk import Zendesk trl = Trello() zd = Zendesk() def create_ticket_card(id): tk = zd.get_ticket(id) ticket_name = f"{id} - {tk['ticket']['subject']}" ticket_desc = tk['ticket']['description'] response = trl.create_card(ticket_name, ticket_desc) if response == r.codes.ok: print(f'Card do ticket {id} criado com sucesso.')
from flask import Flask, render_template, request, redirect, url_for from config import Config from trello import Trello from status import COMPLETED, IN_PROGRESS from view_model import ViewModel from api_client import ApiClient config = Config('.env') trello = Trello(config.trello_config, ApiClient()) def create_app(script_info, trello=trello): app = Flask(__name__) # Allowing POST so we don't need frontend JS @app.route('/item/<id>/mark-completed', methods=['PUT', 'POST']) def mark_completed(id): trello.set_status(id, COMPLETED) return redirect('/') @app.route('/item/<id>/start-item', methods=['PUT', 'POST']) def start_item(id): trello.set_status(id, IN_PROGRESS) return redirect('/') @app.route('/item/<id>/delete', methods=['DELETE', 'POST']) def delete(id): item = trello.delete_item(id) return redirect('/') @app.route('/item/add', methods=['POST']) def add_item():