{"id":68,"date":"2014-07-01T10:00:47","date_gmt":"2014-07-01T01:00:47","guid":{"rendered":"http:\/\/www.skyarch.net\/blog\/?p=68"},"modified":"2016-03-08T11:47:17","modified_gmt":"2016-03-08T02:47:17","slug":"backlogapi%e6%9c%89%e5%8a%b9%e6%b4%bb%e7%94%a8-%e5%90%84%e6%8b%85%e5%bd%93%e8%80%85%e3%81%b8%e5%80%8b%e5%88%a5%e3%83%ac%e3%83%9d%e3%83%bc%e3%83%88","status":"publish","type":"post","link":"https:\/\/www.skyarch.net\/blog\/backlogapi%e6%9c%89%e5%8a%b9%e6%b4%bb%e7%94%a8-%e5%90%84%e6%8b%85%e5%bd%93%e8%80%85%e3%81%b8%e5%80%8b%e5%88%a5%e3%83%ac%e3%83%9d%e3%83%bc%e3%83%88\/","title":{"rendered":"BacklogAPI\u6709\u52b9\u6d3b\u7528 -\u5404\u62c5\u5f53\u8005\u3078\u500b\u5225\u30ec\u30dd\u30fc\u30c8-"},"content":{"rendered":"<h1>\u76ee\u7684<\/h1>\n<p>\u4fbf\u5229\u306a\u30d0\u30c3\u30af\u30ed\u30b0\u3067\u3059\u304c\u6700\u8fd1\u30bf\u30b9\u30af\u304c\u305f\u307e\u308a\u6c17\u5473\u306e\u305f\u3081<br \/>\n\u5404\u30bf\u30b9\u30af\u30aa\u30fc\u30ca\u306b\u500b\u5225\u8a73\u7d30\u30ec\u30dd\u30fc\u30c8\u3092\u9001\u4fe1\u3059\u308b<\/p>\n<h1>\u3084\u3063\u3066\u307f\u305f\u4e8b<\/h1>\n<p>\u5404\u62c5\u5f53\u8005\u3078\u7d0d\u671f\u9806\u306b\u500b\u5225\u30ec\u30dd\u30fc\u30c8\u3092\u30e1\u30fc\u30eb\u3059\u308b<\/p>\n<h1>\u9001\u4fe1\u3055\u308c\u308b\u30ec\u30dd\u30fc\u30c8\u30e1\u30fc\u30eb\u30b5\u30f3\u30d7\u30eb<\/h1>\n<p>\u62c5\u5f53\u8005\u306e\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u306b\u81ea\u5206\u304c\u62c5\u5f53\u5206\u306e\u4e0b\u8a18\u30ec\u30dd\u30fc\u30c8\u30e1\u30fc\u30eb\u304c\u9001\u4fe1\u3055\u308c<br \/>\n\u4ee3\u8868\u8005\u306e\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u306b\u306f\u5168\u3066\u306e\u62c5\u5f53\u8005\u5206\u304c\u307e\u3068\u307e\u3063\u3066\u9001\u4fe1\u3055\u308c\u307e\u3059\u3002<\/p>\n<blockquote><p>\n  \u671f\u9650\u65e5\uff1a2014\/06\/24<br \/>\n  [PRJ_NAME-95] \u8ab2\u984c\u540d<br \/>\n  \u72b6\u614b\uff1a\u51e6\u7406\u6e08\u307f \/ \u62c5\u5f53\u8005\uff1aXXX<\/p>\n<p>  2014\/06\/23 14:13:57<br \/>\n  \u6700\u65b0\u30b3\u30e1\u30f3\u30c8\u306e\u5148\u982d100\u6587\u5b57<br \/>\n  https:\/\/space-name.backlog.jp\/view\/PRJ_NAME-95<br \/>\n  ...\n<\/p><\/blockquote>\n<h1>\u30d7\u30ed\u30b0\u30e9\u30e0\u672c\u4f53<\/h1>\n<h2>\u52d5\u4f5c\u78ba\u8a8d\u74b0\u5883<\/h2>\n<ul>\n<li>Python 2.6.6<\/li>\n<li>backlog lib (python)<br \/>\nhttps:\/\/code.google.com\/p\/backloglib\/<\/li>\n<\/ul>\n<h2>\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb<\/h2>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u672c\u4f53\u3068\u540c\u4e00\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u914d\u7f6e\u306e\u4e0a<br \/>\n\u30d5\u30a1\u30a4\u30eb\u540d\u3092 config.ini \u3068\u3057\u3066\u4e0b\u3055\u3044<\/p>\n<pre>\nKIG_I\ntest@example.net\n<\/pre>\n<p>1\u884c\u76ee \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u540d<br \/>\n2\u884c\u76ee \u4ee3\u8868\u8005\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9<\/p>\n<h2>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h2>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n#coding:utf-8\r\n\r\n#####\r\n## FileName:report_mail.py\r\n## Author:Ryo Tanaka\r\n## Version:0.3\r\n## Date:2014\/06\/26\r\n## Usage:.\/report_mail.py\r\n## Summary:\u62c5\u5f53\u8005\u5225\u306bBACKLOG\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u30b5\u30de\u30ea\u3092\u30e1\u30fc\u30eb\u9001\u4fe1\u3057\u307e\u3059\r\n#####\r\n\r\n__author__ = 'tanaka'\r\nimport datetime\r\nimport backloglib\r\nimport smtplib\r\nfrom email.MIMEText import MIMEText\r\nfrom email.Header import Header\r\nfrom email.Utils import formatdate\r\n\r\nconfig_file = &quot;config.ini&quot;\r\n\r\nspacename = &quot;\u30b9\u30da\u30fc\u30b9\u30cd\u30fc\u30e0\u3092\u8a18\u8f09 xxxx.backlog.jp \u306e\u90e8\u5206\u3067\u3059&quot;\r\nusername = &quot;API\u7528\u30e6\u30fc\u30b6\u30cd\u30fc\u30e0\u3092\u8a18\u8f09 API\u30ea\u30af\u30a8\u30b9\u30c8\u306b\u4f7f\u3046\u30e6\u30fc\u30b6\u540d&quot;\r\npassword = &quot;API\u7528\u30e6\u30fc\u30b6\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u8a18\u8f09 API\u30ea\u30af\u30a8\u30b9\u30c8\u306b\u4f7f\u3046\u30e6\u30fc\u30b6\u306e\u30d1\u30b9\u30ef\u30fc\u30c9&quot;\r\n\r\nsmtpsvr = &quot;\u30e1\u30fc\u30eb\u9001\u4fe1\u30b5\u30fc\u30d0\u30a2\u30c9\u30ec\u30b9&quot;\r\nport = 25\r\nfrom_addr = &quot;\u30e1\u30fc\u30eb\u9001\u4fe1\u5143\u30a2\u30c9\u30ec\u30b9\u3092\u8a18\u8f09&quot;\r\n\r\nwhole_report = &quot;&quot;\r\nseparator = &quot;--------------------------------------------------------------------&quot;\r\n\r\n#\r\n# load_config \u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u8aad\u307f\u8fbc\u307f\r\n# @param cnf \u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u540d\r\n#\r\ndef load_config(cnf):\r\n    global line\r\n    try:\r\n        f = open(cnf, 'r')\r\n        line = f.readlines()\r\n        f.close()\r\n    except:\r\n        print cnf + &quot;\u306e\u8aad\u307f\u8fbc\u307f\u306b\u5931\u6557\u3057\u307e\u3057\u305f&quot;\r\n        exit(1)\r\n\r\n#\r\n# create_message MIMEText\u3092\u4f5c\u6210\r\n# @param from_addr \u9001\u4fe1\u5143\u30a2\u30c9\u30ec\u30b9\r\n# @param to_addr \u9001\u4fe1\u5148\u30a2\u30c9\u30ec\u30b9\r\n# @param subject \u4ef6\u540d\r\n# @param body \u30e1\u30fc\u30eb\u672c\u6587\r\n# @param encoding \u6587\u5b57\u30a8\u30f3\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\r\n# @return msg MIMEText\r\n#\r\ndef create_message(from_addr, to_addr, subject, body, encoding):\r\n    msg = MIMEText(body, 'plain', encoding)\r\n    msg&#x5B;'Subject'] = Header(subject, encoding)\r\n    msg&#x5B;'From'] = from_addr\r\n    msg&#x5B;'To'] = to_addr\r\n    msg&#x5B;'Date'] = formatdate(localtime=True)\r\n    msg&#x5B;'X-Priority'] = '1'\r\n    return msg\r\n\r\n#\r\n# send_mail \u30e1\u30fc\u30eb\u9001\u4fe1\r\n# @param from_addr \u9001\u4fe1\u5143\u30a2\u30c9\u30ec\u30b9\r\n# @param to_addr \u9001\u4fe1\u5148\u30a2\u30c9\u30ec\u30b9\r\n# @param msg \u9001\u4fe1\u3059\u308bMIMEText\r\n#\r\ndef send_mail(from_addr, to_addr, msg):\r\n    smtp = smtplib.SMTP(smtpsvr, port)\r\n    smtp.sendmail(from_addr, &#x5B;to_addr], msg.as_string())\r\n    smtp.close()\r\n\r\n#\r\n# cut_comment \u30b3\u30e1\u30f3\u30c8\u6574\u5f62\r\n# @param come \u30b3\u30e1\u30f3\u30c8\r\n# @return come \u6574\u5f62\u3057\u305f\u30b3\u30e1\u30f3\u30c8\r\n#\r\ndef cut_comment(come):\r\n    come = come&#x5B;0:100]\r\n    come = come.replace('\\n', '')\r\n    come = come.replace('\\r', '')\r\n    come = come.replace('\\r\\n', '')\r\n    return come\r\n\r\n#\r\n# make_report \u5831\u544a\u30ec\u30dd\u30fc\u30c8\u4f5c\u6210\r\n# @param due \u671f\u9650\u65e5\r\n# @param key \u8ab2\u984c\u30ad\u30fc\r\n# @param summary \u8ab2\u984c\u306e\u6982\u8981\r\n# @param assigner \u62c5\u5f53\u8005\r\n# @param url \u8ab2\u984cURL\r\n# @param time \u6642\u523b\r\n# @param comment \u30b3\u30e1\u30f3\u30c8\r\n# @return rep \u69cb\u7bc9\u3055\u308c\u305f\u30ec\u30dd\u30fc\u30c8\r\n#\r\ndef make_report(due, key, summary, status, assigner, url, time, comment):\r\n    global separator\r\n    rep = u&quot;\u671f\u9650\u65e5\uff1a&quot; + due + &quot;\\n&quot;  + \\\r\n        &quot;&#x5B;&quot; + key + &quot;] &quot; + summary + &quot;\\n&quot; + \\\r\n        u&quot;\u72b6\u614b\uff1a&quot; + status + u&quot; \/ \u62c5\u5f53\u8005\uff1a&quot; + assigner + &quot;\\n&quot; + &quot;\\n&quot; + \\\r\n        time + &quot;\\n&quot; + \\\r\n        comment + &quot;\\n&quot; + \\\r\n        url + &quot;\\n&quot; + &quot;\\n&quot; + \\\r\n        separator + &quot;\\n&quot;\r\n    return rep\r\n\r\n#\r\n# convert_time \u6642\u523b\u6574\u5f62\r\n# @param str \u65e5\u4ed8\u6587\u5b57\u5217(YYYYmmddHHMMSS)\r\n# @return t_str \u6574\u5f62\u6e08\u307f\u65e5\u4ed8\u6587\u5b57\u5217(YYYY\/mm\/dd HH:MM:SS)\r\n#\r\ndef convert_time(str):\r\n    time = datetime.datetime.strptime(str, &quot;%Y%m%d%H%M%S&quot;)\r\n    t_str = time.strftime(&quot;%Y\/%m\/%d %H:%M:%S&quot;)\r\n    return t_str\r\n\r\n#\r\n# convert_date \u6642\u523b\u6574\u5f62\r\n# @param str \u65e5\u4ed8\u6587\u5b57\u5217(YYYYmmdd)\r\n# @return t_str \u6574\u5f62\u6e08\u307f\u65e5\u4ed8\u6587\u5b57\u5217(YYYY\/mm\/dd)\r\n#\r\ndef convert_date(str):\r\n    time = datetime.datetime.strptime(str, &quot;%Y%m%d&quot;)\r\n    t_str = time.strftime(&quot;%Y\/%m\/%d&quot;)\r\n    return t_str\r\n\r\n#\r\n# set_blank \u7a7a\u767d\u57cb\u3081\r\n#\r\ndef set_blank():\r\n    global comment\r\n    global time_str\r\n    comment = &quot;&quot;\r\n    time_str = &quot;&quot;\r\n\r\n# #### #\r\n# MAIN #\r\n# #### #\r\nif __name__ == &quot;__main__&quot; :\r\n    load_config(config_file)\r\n    projects = line&#x5B;0].strip()\r\n    chief_addr = line&#x5B;1].strip()\r\n\r\n    backlog = backloglib.Backlog(spacename, username, password)\r\n    backlog_admin = backloglib.BacklogAdmin(spacename, username, password)\r\n\r\n    project = backlog.get_project(projects)\r\n    allusers = backlog_admin.get_users()\r\n\r\n    report_subject = &quot;\u3010BACKLOG\u6b8b\u30bf\u30b9\u30af\u3011&quot; + project.key + &quot;\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u672a\u5b8c\u4e86\u306e\u30bf\u30b9\u30af\u3092\u5831\u544a\u3057\u307e\u3059&quot;\r\n\r\n    mail_addr = &#x5B;0] * (len(allusers) - 1)\r\n\r\n    for cnt in range(len(allusers) - 1):\r\n        mail_addr&#x5B;cnt] = allusers&#x5B;cnt].mail_address\r\n\r\n    for prj_index in range(len(allusers) - 1):\r\n        issues = backlog.find_issue({\r\n            'projectId':project.id,\r\n            'statusId':&#x5B;1,2,3],\r\n            'assignerId':allusers&#x5B;prj_index].id,\r\n            'sort':&quot;DUE_DATE&quot;,\r\n            'order':True\r\n        })\r\n\r\n        if len(issues) &lt; 1:\r\n            continue\r\n\r\n        report = &#x5B;0] * (len(issues) - 1)\r\n\r\n        for issue_index in range(len(issues) - 1):\r\n            issue = backlog.get_issue(issues&#x5B;issue_index].id)\r\n            comments = backlog.get_comments(issues&#x5B;issue_index].id)\r\n\r\n            if len(comments) &lt; 1:\r\n                set_blank()\r\n            else:\r\n                try:\r\n                    comment = comments&#x5B;-1].content # \u6700\u65b0\u306e\u30b3\u30e1\u30f3\u30c8\u3092\u53d6\u5f97\r\n                    time_str = convert_time(comments&#x5B;-1].created_on) # \u6642\u523b\u3092\u6574\u5f62\r\n                except:\r\n                    set_blank()\r\n\r\n            comment = cut_comment(comment)\r\n\r\n            if len(comment) &lt; 1:\r\n                comment = u&quot;\u30b3\u30e1\u30f3\u30c8\u304c\u5b58\u5728\u3057\u307e\u305b\u3093\u3067\u3057\u305f&quot;\r\n\r\n            if len(issue.due_date) &lt; 1:\r\n                due_date = u&quot;\u306a\u3057&quot;\r\n            else:\r\n                due_date = convert_date(issue.due_date)\r\n\r\n            rep_section = make_report(due_date, issue.key, issue.summary, issue.status.name, issue.assigner.name, issue.url, time_str, comment)\r\n            report&#x5B;issue_index] = rep_section.encode('utf-8')\r\n            report_msg = &quot;&quot;.join(map(str, report)) # report\u914d\u5217\u3092\u7d50\u5408\r\n            issue_index += 1\r\n\r\n        try:\r\n            to_addr = mail_addr&#x5B;prj_index]\r\n            body_msg = create_message(from_addr, to_addr, report_subject, report_msg, 'utf-8')\r\n            whole_report += report_msg\r\n            send_mail(from_addr, to_addr, body_msg)\r\n        except:\r\n            prj_index += 1\r\n            continue\r\n\r\n        prj_index += 1\r\n\r\nwhole_msg = create_message(from_addr, chief_addr, report_subject, whole_report, 'utf-8')\r\nsend_mail(from_addr, chief_addr, whole_msg)\r\nexit(0)\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u7684 \u4fbf\u5229\u306a\u30d0\u30c3\u30af\u30ed\u30b0\u3067\u3059\u304c\u6700\u8fd1\u30bf\u30b9\u30af\u304c\u305f\u307e\u308a\u6c17\u5473\u306e\u305f\u3081 \u5404\u30bf\u30b9\u30af\u30aa\u30fc\u30ca\u306b\u500b\u5225\u8a73\u7d30\u30ec\u30dd\u30fc\u30c8\u3092\u9001\u4fe1\u3059\u308b \u3084\u3063\u3066\u307f\u305f\u4e8b \u5404\u62c5\u5f53\u8005\u3078\u7d0d\u671f\u9806\u306b\u500b\u5225\u30ec\u30dd\u30fc\u30c8\u3092\u30e1\u30fc\u30eb\u3059\u308b \u9001\u4fe1\u3055\u308c\u308b\u30ec\u30dd\u30fc\u30c8\u30e1\u30fc\u30eb\u30b5\u30f3\u30d7\u30eb \u62c5\u5f53\u8005\u306e\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u306b\u81ea&#8230;<\/p>\n","protected":false},"author":2,"featured_media":72,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"ja","_original_post":"68","footnotes":""},"categories":[9],"tags":[39,13,65],"class_list":{"0":"post-68","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-dev","8":"tag-api","9":"tag-backlog","10":"tag-python","11":"ja"},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/68","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/comments?post=68"}],"version-history":[{"count":14,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/68\/revisions"}],"predecessor-version":[{"id":2936,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/68\/revisions\/2936"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/media\/72"}],"wp:attachment":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/media?parent=68"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/categories?post=68"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/tags?post=68"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}