More Related Content Similar to 入門書を読み終わったらなにしよう? 〜Python と WebAPI の使い方から学ぶ次の一歩〜 / next-step-python-programing (20) More from Kei IWASAKI (9) 入門書を読み終わったらなにしよう? 〜Python と WebAPI の使い方から学ぶ次の一歩〜 / next-step-python-programing23. まずは Web API が使えないかを確認する
API と言ってもいろいろ。簡単に使えるものもある
Webサービスは API が提供されていることも多い
今回のパターンも API が使える
GitHub API v3 | GitHub Developer Guide
Slack Web API | Slack
23
43. import slackpy
from github import Github
GITHUB_TOKEN = '********************'
SLACK_WEBHOOK = 'https://hooks.slack.com/services/******/*******/********'
GITHUB_REPOSITORY = 'laughk/py3-django-tutorial'
gh = Github(GITHUB_TOKEN)
repository = gh.get_repo(GITHUB_REPOSITORY)
pull_request_info = []
for pr in repository.get_pulls(state='all'):
pull_request_info.append({'title': pr.title, 'url': pr.url})
slack_messages = ""
for info in pull_request_info:
slack_messages += '{0} {1}n'.format(info["title"], info["url"])
slack = slackpy.SlackLogger(SLACK_WEBHOOK)
slack.info(slack_messages)
44. # Github から Pull Request 情報を取得
gh = Github(GITHUB_TOKEN)
repository = gh.get_repo(GITHUB_REPOSITORY)
pull_request_info = []
for pr in repository.get_pulls(state='all'):
pull_request_info.append({'title': pr.title, 'url': pr.url})
# Github から取得した情報の形成
slack_messages = ""
for info in pull_request_info:
slack_messages += '{0} {1}n'.format(info["title"], info["url"])
# Slack へ通知
slack = slackpy.SlackLogger(SLACK_WEBHOOK)
slack.info(slack_messages)