本文整理汇总了Python中trello.TrelloClient.fetch_json方法的典型用法代码示例。如果您正苦于以下问题:Python TrelloClient.fetch_json方法的具体用法?Python TrelloClient.fetch_json怎么用?Python TrelloClient.fetch_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trello.TrelloClient
的用法示例。
在下文中一共展示了TrelloClient.fetch_json方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sync_trello_cards
# 需要导入模块: from trello import TrelloClient [as 别名]
# 或者: from trello.TrelloClient import fetch_json [as 别名]
def sync_trello_cards(self):
if not self.trello_id:
logger.exception("Trello board id for %s not set", self.name)
raise NotSetTrelloBoardID
client = TrelloClient(**TRELLO_KEYS)
tasks = client.fetch_json("boards/{}/cards".format(self.trello_id))
for task_dict in tasks:
last_activity = task_dict.get('dateLastActivity')
task, created = Task.objects.get_or_create(
trello_id=task_dict['id'],
project=self
)
if created or last_activity != task.trello_last_activity:
task.name = task_dict['name']
task.description = task_dict['desc']
task.trello_url = task_dict['shortUrl']
task.trello_last_activity = last_activity
task.save()
logger.info(
"Trello card with id %s and name %s has ben %s",
task_dict['id'],
task_dict['name'],
'created' if created else 'updated'
)
示例2: TrelloPlugin
# 需要导入模块: from trello import TrelloClient [as 别名]
# 或者: from trello.TrelloClient import fetch_json [as 别名]
#.........这里部分代码省略.........
insert_added_object(usr_dict, target_id, attachment_id, attachment_data,
u_id, author, date, course_code, self.platform, self.platform_url,
object_type, shared_displayname=shared_displayname)
#TODO: RP
print 'Added attachment!'
if type is 'addMemberToCard' and usr_dict is not None: #or 'addMemberToBoard':
target_id = data['card']['id']
object_id = data['idMember']
object_data = action['memeber']['username']
object_type = 'Person'
shared_displayname = '%sc/%s' % (self.platform_url, target_id)
insert_added_object(usr_dict, target_id, object_id, object_data, u_id, author, date,
course_code, self.platform, self.platform_url, object_type,
shared_displayname=shared_displayname)
#TODO: RP
print 'Added add member to card!'
if type is 'addChecklistToCard' and usr_dict is not None:
target_id = data['card']['id']
object_id = data['idMember']
object_data = None
checklist_items = None
object_type = 'Collection'
shared_displayname = '%sc/%s' % (self.platform_url, target_id)
#get checklist contents
try:
checklist = self.TrelloCient.fetch_json('/checklists/' + data['checklist']['id'],)
checklist_items = checklist['checkItems']
except Exception:
print 'Could not retrieve checklist..'
#data will be a comma separated list of checklist-item ids (e.g.: 'id1,id2,id3...')
object_data = ','.join([item['id'] for item in checklist_items])
insert_added_object(usr_dict, target_id, object_id, object_data, u_id, author, date,
course_code, self.platform, self.platform_url, object_type,
shared_displayname=shared_displayname)
#TODO: RP
print 'added add checklist to card!'
#print 'is action type an update? %s' % (type in
# ['updateCheckItemStateOnCard', 'updateBoard',
# 'updateCard', 'updateCheckList',
# 'updateList', 'updateMember'])
#Get all 'updated' verbs
if (type in
['updateCheckItemStateOnCard', 'updateBoard',
'updateCard', 'updateCheckList',
'updateList', 'updateMember']):
usr_dict = None
if username_exists(u_id, course_code, self.platform):
usr_dict = get_userdetails(u_id, self.platform)
#many checklist items will be bugged - we require webhooks!
if type == 'updateCheckItemStateOnCard' and usr_dict is not None:
示例3: EClaire
# 需要导入模块: from trello import TrelloClient [as 别名]
# 或者: from trello.TrelloClient import fetch_json [as 别名]
class EClaire(object):
def __init__(self, credentials, boards=None):
self.trello_client = TrelloClient(
api_key=credentials['public_key'],
token=credentials['member_token'],
)
self.boards = boards
def process_boards(self, dry_run=False, notify_fn=None, notify_config=None):
"""
Process each board in self.boards
"""
for name, board_config in self.boards.iteritems():
log.info('Polling %s', name)
processed = self.process_board(board_config, dry_run)
if board_config.get('notify', True) and notify_fn is not None:
for card in processed:
notify_fn(card, **notify_config)
def process_board(self, board_config, dry_run=False):
"""
Process each card in a given board
"""
processed = []
for card in self.fetch_cards(board_id=board_config['id']):
log.info('Printing card "%s"', card.name)
pdf = generate_pdf(card)
if not dry_run:
print_card(pdf, printer_name=board_config['printer'])
self.update_card(card, board_config)
processed.append(card)
return processed
def fetch_cards(self, board_id):
"""
Fetch all candidate cards on a board for processing
"""
data = []
board = self.trello_client.get_board(board_id)
for card in board.all_cards():
if FILTER_LABEL in [l.name for l in card.labels]:
card.fetch_actions()
data.append(card)
return data
def discover_labels(self):
"""
Store object references for special labels
"""
for name, config in self.boards.iteritems():
board = self.trello_client.get_board(config['id'])
labels = {}
for label in board.get_labels(limit=100):
if label.name in SPECIAL_LABELS:
labels[label.name] = label
missing = set(SPECIAL_LABELS) - set(labels.keys())
if missing:
log.fatal(
'Board "%s" is missing the labels %s',
board.name,
' and '.join(missing)
)
log.fatal('Exiting')
sys.exit(1)
config['labels'] = labels
def remove_label(self, card, label):
"""
Remove a lable from a card.
At the time of writing there is no way to remove a label with py-trello
"""
self.trello_client.fetch_json(
'/cards/' + card.id + '/idLabels/' + label.id,
http_method="DELETE"
)
def update_card(self, card, board_config):
"""
Replace PRINTME label with PRINTED
"""
printme_label = board_config['labels']['PRINTME']
printed_label = board_config['labels']['PRINTED']
self.remove_label(card, printme_label)
if printed_label not in card.labels:
card.add_label(printed_label)
def list_boards(self):
"""
Fetch all board IDs from trello & print them out
"""
#.........这里部分代码省略.........
示例4: TrelloList
# 需要导入模块: from trello import TrelloClient [as 别名]
# 或者: from trello.TrelloClient import fetch_json [as 别名]
class TrelloList(object):
"""
Sugar class to work with Trello Lists.
"""
def __init__(self, board_id, list_id, api_key, token=None, **kwargs):
"""
Validate inputs and connect to Trello API.
Exception is thrown if input details are not correct.
:param board_id: Trello board ID where the List is located
:type board_id: ``str``
:param list_id: Trello List ID itself
:type list_id: ``str``
:param api_key: Trello API key
:type api_key: ``str``
:param token: Trello API token
:type token: ``str``
"""
self.board_id = board_id
self.list_id = list_id
self.api_key = api_key
# assume empty string '' as None
self.token = token or None
self.validate()
self._client = TrelloClient(api_key=self.api_key, token=self.token)
self._list = self._client.get_board(self.board_id).get_list(self.list_id)
def validate(self):
"""
Ensure that Trello list details are correct.
Raise an exception if validation failed.
"""
if not self.api_key:
raise ValueError('[TrelloListSensor] "api_key" config value is required!')
assert isinstance(self.api_key, basestring)
if self.token:
assert isinstance(self.token, basestring)
if not self.board_id:
raise ValueError('[TrelloListSensor]: "board_id" config value is required!')
assert isinstance(self.board_id, basestring)
if not self.list_id:
raise ValueError('[TrelloListSensor]: "list_id" config value is required!')
assert isinstance(self.list_id, basestring)
@property
def key_name(self):
"""
Generate unique key name for built-in storage based on config values.
:rtype: ``str``
"""
return '{}.{}.date'.format(self.board_id, self.list_id)
def fetch_actions(self, filter=None, since=None):
"""
Fetch actions for Trello List with possibility to specify filters.
Example API request:
https://api.trello.com/1/lists/{list_id}/actions?filter=createCard&since=2015-09-14T21:45:56.850Z&key={key_id}&token={token_id}
:param filter: Action types to filter, separated by comma or as a sequence.
:type filter: ``str`` or ``list``
:param since: Filter actions since specified date.
:type since: ``str``
:return: Events occurred in Trello list.
:rtype: ``list`` of ``dict``
"""
return self._client.fetch_json(
'/lists/' + self._list.id + '/actions',
query_params={
'filter': filter,
'since': since,
})