Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… into main
  • Loading branch information
Ctri-The-Third committed Mar 17, 2022
2 parents 3493be1 + 7ed6a45 commit 8cfeeb0
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions trello.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def purge_trello_cards(self,titlePattern = "", descPattern = "", targetLists = [
def fetch_trello_cards(self):
"""returns all visible cards from the board"""
url = "https://api.trello.com/1/boards/%s/cards" % (self.board_id)
params = self._getTrelloParams()
params = self._get_trello_params()
params["filter"] = "visible"
params["customFieldItems"] = "true"

Expand All @@ -83,14 +83,14 @@ def fetch_trello_cards(self):
return cards
def get_trello_card(self,id):
url = "https://api.trello.com/1/cards/%s" % (id)
params = self._getTrelloParams()
params = self._get_trello_params()
r = requests.get(url, params = params)
card = json.loads(r.content)
return card

def create_card(self,title, list_id, description = None, labelID = None, dueTimestamp = None) :

params = self._getTrelloParams()
params = self._get_trello_params()
params["name"] =title

if description is not None:
Expand All @@ -113,7 +113,7 @@ def create_card(self,title, list_id, description = None, labelID = None, dueTim

def update_card( self, card_id, title, description = None):

params = self._getTrelloParams()
params = self._get_trello_params()
params["name"] = title

if description is not None:
Expand All @@ -129,7 +129,7 @@ def update_card( self, card_id, title, description = None):
def create_checklist_on_card(self, cardID, checklistName = "Todo items") -> str:
"create a checklist on an existing card, returns the ID for use."
url = "https://api.trello.com/1/checklists"
params = self._getTrelloParams()
params = self._get_trello_params()
params["idCard"] = cardID
params["name"] = checklistName

Expand All @@ -144,7 +144,7 @@ def create_checklist_on_card(self, cardID, checklistName = "Todo items") -> str:

def add_item_to_checklist(self, checklistID, text):
url = "https://api.trello.com/1/checklists/%s/checkItems" % (checklistID)
params = self._getTrelloParams()
params = self._get_trello_params()
params["pos"] = "bottom"
params["name"] = text
r = requests.post(url,params=params)
Expand All @@ -154,10 +154,18 @@ def add_item_to_checklist(self, checklistID, text):
return


def delete_checklist_item(self,checklist_id, checklist_item_id):
url = "https://api.trello.com/1/checklists/%s/checkItems/%s" % (checklist_id,checklist_id,checklist_item_id)
params = self._get_trello_params()
r = requests.delete(url,params=params)
if r.status_code != 200:
lo.error("ERROR: %s, Couldn't delete trello checklist item %s " % (r.status_code,checklist_item_id))


def _setCustomFieldValue(self, cardID,value, fieldID):
url = "https://api.trello.com/1/card/%s/customField/%s/item" % (cardID,fieldID)
data = json.dumps({"value" : {"text" : "%s"% (value)}})
params = self._getTrelloParams()
params = self._get_trello_params()
headers = {"Content-type": "application/json"}
r = requests.put(url = url, data = data,params = params, headers=headers)
if r.status_code != 200:
Expand All @@ -167,7 +175,7 @@ def _setCustomFieldValue(self, cardID,value, fieldID):

def archiveTrelloCard(self,trelloCardID):
url = "https://api.trello.com/1/card/%s" % (trelloCardID)
params = self._getTrelloParams()
params = self._get_trello_params()
params["closed"] = True
r = requests.put(url,params=params)
if r.status_code != 200:
Expand All @@ -178,7 +186,7 @@ def archiveTrelloCard(self,trelloCardID):
def create_custom_field(self,field_name) -> str:
board_id = self.board_id
url = "https://api.trello.com/1/customFields/"
params = self._getTrelloParams()
params = self._get_trello_params()
data = {
"idModel":board_id,
"modelType":"board",
Expand All @@ -198,7 +206,7 @@ def create_custom_field(self,field_name) -> str:
return ""


def _getTrelloParams(self):
def _get_trello_params(self):
params = {
'key' : self.key,
'token' : self.token
Expand All @@ -209,7 +217,7 @@ def _getTrelloParams(self):
def deleteTrelloCard(self,trelloCardID):

url = "https://api.trello.com/1/card/%s" % (trelloCardID)
r = requests.delete(url, params=self._getTrelloParams() )
r = requests.delete(url, params=self._get_trello_params() )
if r.status_code != 200:
print(r)
print(r.reason)
Expand Down

0 comments on commit 8cfeeb0

Please sign in to comment.