Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

trello class

#Trello.py
import requests
from datetime import datetime
from datetime import timedelta


class TrelloClient:

    def __init__(self, user_id, key, secret, token):
        self.user_id = user_id
        self.key = key
        self.secret = secret
        self.token = token
        self.URL = 'https://trello.com/1/'

    def get_board_id(self, board_name):
        """
        ボード名からボードidを特定する
        """
        end_point = f"members/{self.user_id}/boards?key={self.key}&token={self.token}&fields=name"
        json_data = requests.get(self.URL + end_point).json()
        for json in json_data:
            if json['name'] == board_name:
                return json['id']

    def get_board_names(self):
        """
        ボード名のリストを返す
        """
        end_point = f"members/{self.user_id}/boards?key={self.key}&token={self.token}&fields=name"
        json_data = requests.get(self.URL + end_point).json()
        return [json['name'] for json in json_data]

    def get_list_id(self, board_id, list_name):
        """
        ボードidとTrelloリスト名からTrelloリストidを特定して返す
        """
        end_point = f"boards/{board_id}/lists?key={self.key}&token={self.token}&fields=name"
        json_data = requests.get(self.URL + end_point).json()
        for json in json_data:
            if json['name'] == list_name:
                return json['id']

    def get_list_ids_and_names(self, board_id):
        """
        idとnameがタプルになったリストを返す
        """
        end_point = f"boards/{board_id}/lists?key={self.key}&token={self.token}&fields=name"
        json_data = requests.get(self.URL + end_point).json()
        return [(json['id'], json['name']) for json in json_data]

    def add_task(self, list_id, card_name, due_date=None, due_time=None, desc=None):
        """
        カードを特定のリストに追加する
        """
        end_point = "cards"
        if due_date and due_time:
            due = datetime.strptime(due_date + ' ' + due_time, '%Y/%m/%d %H:%M')
            # そのまま登録すると13時間後になる仕様のため
            due = due - timedelta(hours=13)
            due = due.isoformat()
        else:
            due = ""

        query = {
            'key': self.key,
            'token': self.token,
            'idList': list_id,
            'name': card_name,
            'desc': desc,
            'due': due}

        requests.request("POST", self.URL + end_point, params=query)

    def get_cards_in_list(self, list_id):
        """
        Trelloリストの中のカードをjson形式で返す
        """
        end_point = f"lists/{list_id}/cards"
        query = {
            'key': self.key,
            'token': self.token
        }

        response = requests.request(
            "GET",
            self.URL + end_point,
            params=query
        )

        return response.json()
Comment

PREVIOUS NEXT
Code Example
Python :: seleniu get element value and store it in a variable - selenium remember user 
Python :: how to hash out a big paragraph in vs code python 
Python :: ffmpeg python get total frames 
Python :: tkinter file dialog multiple file types 
Python :: Rebinding a list stored in a Flask Session 
Python :: long type python 
Python :: pico 8 pset 
Python :: defaultdict python inport 
Python :: django amzon like app 
Python :: python generator in while loop 
Python :: python loop over lists 
Python :: prime numbers from 1 to 100 in python 
Python :: pandas data frame from part of excel easy 
Python :: vijay 
Python :: python string copy 
Python :: check if a variable is empty python 
Python :: send command dynamo civid 
Python :: python loop chrome 
Python :: 1051 texes uri solution 
Python :: REMINER VIA MAIL 
Python :: Print Multiple Variables 
Python :: python if block 
Python :: threading pass keyword args example 
Python :: postgtres settings.py setup with django 
Python :: Comparing Sets with issubset() Function in python 
Python :: page views count django 
Python :: python async get result 
Python :: operator overloading in python 
Python :: database setup in django aws 
Python :: Implementing Java-style getters and setters in Python 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =