Python Forum
Blockspring Trello export to Google Sheet - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Blockspring Trello export to Google Sheet (/thread-17436.html)



Blockspring Trello export to Google Sheet - Shafla - Apr-10-2019

I have a Trello board synced with a google sheet. I want to start adding my own code. Specifically i would like to export each checklist item to its own Cell. Is this possible?

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 = "1NyDlqBmgeTS2Zs8fzjihTulrd5xaJ_FkWNTib_8hVLw"


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()