-
Notifications
You must be signed in to change notification settings - Fork 0
/
trello.py
61 lines (50 loc) · 1.47 KB
/
trello.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#trello.py
#intended to streamline creating ANA load requests to trello
import requests
import json
import configparser, os
cfgFile = "trelloApi.cfg"
config = configparser.RawConfigParser()
config.read(cfgFile)
apikey = config.get('id', 'key')
apitoken = config.get('id', 'token')
def getBoards():
reqUrl = 'https://api.trello.com/1/members/me/boards?fields=name,url'
payload = {'key':apikey, 'token':apitoken}
boards = requests.get(reqUrl, params=payload)
#print boards.text
return boards.json()
def getBoardID(boardJson, reqBoard):
for board in range(len(boards)):
if boards[board]["name"] == reqBoard:
return boards[board]["id"]
elif board == max(range(len(boards))):
return 0
def getBoardLists(boardID):
reqUrl = "https://api.trello.com/1/boards/" + boardID + "/lists?&filter=open&fields=all"
payload = {
'fields': 'name,id',
'card_fields': 'name,id',
'cards': 'all',
'key':apikey,
'token':apitoken
}
lists = requests.get(reqUrl, params=payload)
return lists.json()
def addCard(listId, cardName, cardDesc):
reqUrl = "https://api.trello.com/1/cards"
payload = {
'name': cardName,
'desc': cardDesc,
'idList': listId,
'key':apikey,
'token':apitoken
}
cardAdd = requests.post(reqUrl, params=payload)
return cardAdd.json()
boards = getBoards()
print(json.dumps(boards, indent=4))
print(boards[3]["name"])
#print(getBoardLists(boards[3]["id"]))
print(json.dumps(getBoardLists(boards[3]["id"]), indent=4))
#print(getBoardID(boards, "ANA Media"))