Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zapierを使って、Github Issue作成をトリガーに、PythonスクリプトからQiita APIを叩いて新規投稿する例 #538

Open
YumaInaura opened this issue Feb 1, 2019 · 0 comments
Labels

Comments

@YumaInaura
Copy link
Owner

YumaInaura commented Feb 1, 2019

Zapierを使って、Github Issue作成をトリガーに、PythonスクリプトからQiita APIを叩いて新規投稿する例

Github issue 作成をトリガーにする

image

Set up Code by Zapier Run Python

input に Github issue の title / description を定義する

image

Qiita token

Qiita > settings > application から取得

https://qiita.com/settings/applications

python script を設定

image

Script

  • tokenはZapierのinputとして入力しておく
  • 公開記事にする場合は private を False に変える
  • タグ連携はまだやっていないので、とりあえずポエムに設定
import requests
import re

hashtags = re.findall(r'#([^\s]+)', input['title'])

# タイトルからハッシュタグを抽出してQiita API 用に整形
qiita_hashtags = []
for hashtag in hashtags:
    qiita_hashtags.append({ "name": hashtag, "versions": ["0.0.1"] })

# タイトルでハッシュタグが見つからなかった時
if not qiita_hashtags:
  qiita_hashtags = [{ "name": "ポエム", "versions": ["0.0.1"] } ]

item = {
    'title': input['title'],
    'body': input['body'],
    "coediting": False,
    'tags': qiita_hashtags,
    'private': False,
    'tweet': True,
}


url = 'https://qiita.com/api/v2/items'
token = input['token']

headers = {
 'Authorization': 'Bearer {}'.format(token),
 'Content-Type': 'application/json',
}

res = requests.post(url, headers=headers, json=item)
output = [res.json()]

トリガーの元の Issue

#538

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant