操作
使用Python的REST API¶
以下是可用于使用Python的REST API的库列表
Python-Redmine:¶
Python-Redmine是一个支持Redmine REST API 100%功能的库。它提供了一个简单但强大的Pythonic API,灵感来自知名的Django ORM,并且经过彻底测试。示例
>>> from redminelib import Redmine
>>> redmine = Redmine('http://demo.redmine.org', username='foo', password='bar')
>>> project = redmine.project.get('vacation')
>>> project.id
30404
>>> project.identifier
'vacation'
>>> project.created_on
datetime.datetime(2013, 12, 31, 13, 27, 47)
>>> project.issues
<redminelib.resultsets.ResourceSet object with Issue resources>
>>> project.issues[0]
<redminelib.resources.Issue #34441 "Vacation">
>>> dir(project.issues[0])
['assigned_to', 'author', 'created_on', 'description', 'done_ratio',
'due_date', 'estimated_hours', 'id', 'priority', 'project', 'relations',
'start_date', 'status', 'subject', 'time_entries', 'tracker', 'updated_on']
>>> project.issues[0].subject
'Vacation'
>>> project.issues[0].time_entries
<redminelib.resultsets.ResourceSet object with TimeEntry resources>
PyRedmineWS示例:¶
假设Eric生病了,已经休息了几天。您需要遍历名为Parrot的项目,并将分配给Eric的任何到期日期延长两周。
dateutil库包含一个名为relativedelta的方便方法,用于计算相对日期。
# Import the Redmine class
from redmine import Redmine
from dateutil.relativedelta import relativedelta
server = Redmine('http://my-server.com', username='Me', password='seakrit')
project = server.projects['parrot']
# Find Eric in the user data
for u in server.users:
if u.firstname == 'Eric' and u.lastname == 'Idle':
user = u
break
else:
raise Exception("Didn't find Eric Idle in the user dateabase")
# Extend issues in project assigned to user by two weeks
for issue in project.issues(assigned_to_id=user.id):
if issue.due_date is not None:
issue.due_date += relativedelta(weeks=+2)
issue.save('Giving Eric more time to complete - he was out ill')
PyActiveResource示例:¶
# Importing pyactiveresource
from pyactiveresource.activeresource import ActiveResource
class Issue(ActiveResource):
_site = 'http://redmine.foo.org'
_user = 'username'
_password = 'password'
# Get issues
issues = Issue.find()
# Get a specific issue, from its id
issue = Issue.find(1345)
# Issue attributes
# Updating an attribute
PyRed示例:待定¶
由Max Tepkeev更新,7年前·超过7年前 · 18次修订