复制Trello卡并使用Google表格中的数据更改信息

时间:2019-06-19 16:34:53

标签: python google-sheets-api trello

我在Google表格中有一个电子表格,其中包含2条信息: 名称和说明 如何复制“现有卡”并根据工作表仅更新这两个信息。 详细信息我在工作表中有1000多个行。

访问[链接] https://docs.google.com/spreadsheets/d/12ORhZzD5WI0zcrTtNikixXXA9Dd_sknv8NtEnfqK97E/edit#gid=0

我尝试使用integromat,但这是一种付费工具。

import gmail_app
import google_sheets_app
import trello_app

## STEP 1: SIGN IN WITH GOOGLE SHEETS IN THE SIDEBAR
## STEP 2: PASTE A GOOGLE SHEET'S ID BELOW (FOUND IN ITS URL)
sheet_id = "12ORhZzD5WI0zcrTtNikixXXA9Dd_sknv8NtEnfqK97E"


def export_to_sheets():
    # get all open cards in this board
    board = trello_app.get_current_board()
    cards = board.get_cards(filter="open")

    # export cards to the google sheet
    sheet = google_sheets_app.get_spreadsheet_by_id(sheet_id).get_sheets()[0]
    sheet.write_values(cards)


def import_from_sheets():
    # read the google sheet
    sheet = google_sheets_app.get_spreadsheet_by_id(sheet_id).get_sheets()[0]
    sheet_data = sheet.get_values()

    # for each row in sheet
    for row in sheet_data:
        # look for an ID column, and lookup that card
        card = trello_app.get_card_by_id(row.get("id"))

        # if you find a card, update it with the row
        if card:
            card.set_field(row)
        # if this card doesn't exist, create it
        else:
            li = trello_app.get_list_by_id(row.get("idList"))
            li.create_card(row)

    # when done, pull updated card list into sheets
    export_to_sheets()

0 个答案:

没有答案