Last active
March 15, 2016 09:30
-
-
Save noblejasper/e7d8aa780875d27ef7a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import requests, datetime | |
import simplejson as json | |
SPACENAME = "xxxxxx" | |
APIKEY = "xxxxxxxxxxxxxxxxxxxxxxx" | |
PROJECT_NAME = u"xxx" | |
FIX_TEXT = u"完了" | |
USER_NAME = u"xxxxxxxxxxxx" | |
def create_url(path): | |
return "https://{}.backlog.jp{}?apiKey={}".format(SPACENAME, path, APIKEY) | |
def get_teg_project_id(): | |
url = create_url("/api/v2/projects") | |
projects = requests.get(url).json() | |
project = [p for p in projects if p.get("projectKey") == PROJECT_NAME][0] | |
project_id = project['id'] | |
return project_id | |
def get_nofix_status_ids(): | |
url = create_url("/api/v2/statuses") | |
statuses = requests.get(url).json() | |
ids = [str(status['id']) for status in statuses if status['name'] != FIX_TEXT] | |
return ids | |
def get_assignee_id(): | |
url = create_url("/api/v2/users") | |
users = requests.get(url).json() | |
id = [str(user['id']) for user in users if user['name'] == USER_NAME][0] | |
return id | |
def get_issues(project_id, notfix_status_ids, assigner_id): | |
url = create_url("/api/v2/issues") | |
params = dict( | |
sort="startDate", | |
order="asc", | |
count=100, | |
) | |
for index, id in enumerate(notfix_status_ids): | |
params['statusId[{}]'.format(index)] = id | |
params["projectId[0]"] = project_id | |
params["assigneeId[0]"] = assigner_id | |
r = requests.get(url, params=params) | |
data_list = r.json(); | |
for data in data_list: | |
data['startDate'] = datetime.datetime.strptime(data['startDate'], "%Y-%m-%dT%H:%M:%SZ") | |
data['dueDate'] = datetime.datetime.strptime(data['dueDate'], "%Y-%m-%dT%H:%M:%SZ") | |
return data_list | |
teg_project_id = get_teg_project_id() | |
notfix_status_ids = get_nofix_status_ids() | |
assignee_id = get_assignee_id() | |
issues = get_issues(teg_project_id, notfix_status_ids, assignee_id) | |
now = datetime.datetime.now() | |
FORMAT_TEXT=u'=HYPERLINK("https://tyrus.backlog.jp/view/{issueKey}", "{issueKey}")\t{summary}' | |
print "[TODAY]" | |
for issue in issues: | |
if issue['startDate'] >= now: | |
continue | |
print FORMAT_TEXT.format(**issue).encode('utf-8') | |
print "[TOMORROW]" | |
tommorow = now + datetime.timedelta(days=1) | |
for issue in issues: | |
if issue['startDate'] >= tommorow or issue['startDate'] <= now: | |
continue | |
print FORMAT_TEXT.format(**issue).encode('utf-8') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment