Skip to content

Instantly share code, notes, and snippets.

@JFK
Last active September 17, 2019 05:43
Show Gist options
  • Save JFK/96a9fb49b9624a452377f3617ed0001e to your computer and use it in GitHub Desktop.
Save JFK/96a9fb49b9624a452377f3617ed0001e to your computer and use it in GitHub Desktop.
initial setup event script
import argparse
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from trello import TrelloClient
CARD_NAME = "カード名"
LABEL = "ラベル"
CHECKLIST_TITLE = "チェックリストタイトル"
CHECKLIST_ITEMS = "チェックリスト"
def trello_card_resource():
scope = [
"https://spreadsheets.google.com/feeds",
"https://www.googleapis.com/auth/drive",
]
credentials = ServiceAccountCredentials.from_json_keyfile_name("key.json", scope)
gc = gspread.authorize(credentials)
return gc.open("PyCon Kyushu Trelloタスク管理シート").sheet1
def main(args):
# How to get API Key
# https://trello.com/app-key
trello_client = TrelloClient(api_key=args.key, token=args.token)
# ボードの準備
board = trello_client.add_board(args.event_year, permission_level="private")
# リストの準備
for x in ["課題", "実施中", "完了", "保留"]:
board.add_list(x)
# カードを追加するリスト「課題」を取得
kadai_list = board.list_lists()[0]
# 登録する情報を取得する
gws = trello_card_resource()
for record in gws.get_all_records():
n = record[CARD_NAME].strip()
l = record[LABEL].strip()
c = record[CHECKLIST_TITLE].strip()
i = record[CHECKLIST_ITEMS].strip()
# カードを追加する
if n:
card = kadai_list.add_card(n)
# チェックリストの追加
if c:
items = i.split(",")
if items:
card.add_checklist(c, items)
# ラベルの追加
if l:
for x in l.split(","):
l_c, l_n = x.split(":")
label_id = board.add_label(l_n, l_c)
card.add_label(label_id)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="イベント準備スクリプト")
parser.add_argument('-k', '--key', type=str, required=True)
parser.add_argument('-t', '--token', type=str, required=True)
parser.add_argument('-e', '--event-year', type=int, required=True)
args = parser.parse_args()
main(args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment