Skip to content

Article Fetcher

Actions
Fetch articles from Zenn and Qiita
v0.9.4
Latest
By mk2
Star (2)

Article Fetcher

  • ZennQiitaから指定したユーザー ID の記事を取得する Github Action

使い方

前日の記事を取得する例

Zenn/Qiita のアカウントと名前を記載した json ファイルを作成

  • zenn-members.json
[
  {
    "id": "mk2",
    "name": "mk2"
  }
]
  • qiita-members.json
[
  {
    "id": "mk2",
    "name": "mk2"
  }
]

通知するためのスクリプトを用意

  • 例:notify.mjsというファイルを作成
npm i form-data got
import FormData from 'form-data';
import fs from 'fs';
import got from 'got';
import path from 'path';

const url = 'https://...';

async function main() {
  const dirname = path.dirname(new URL(import.meta.url).pathname);
  const data = await fs.promises.readFile(path.resolve(dirname, './articles.json'));
  const articles = JSON.parse(data);
  console.log(articles);
  for (const a of articles) {
    try {
      const body = new FormData();
      body.append('source', `${a.authorName} ${a.title} ${a.url} ${a.url}`);
      body.append('format', 'html');
      await got.post(url, { body });
    } catch (e) {
      console.error(e);
    }
  }
}

main();

GitHub アクションのワークフローを設定

  • 例:.github/workflows/notify.yamlというファイルを作成
name: Notify Zenn/Qiita Posts

on:
  workflow_dispatch:
  schedule:
    - cron: '00 3 * * *'

jobs:
  notify-job:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/setup-node@v2
        with:
          node-version: '14'
      - name: zenn/qiitaのユーザーIDリストの設定
        id: id-list-json
        run: |
          zenn=$(echo $(cat ./zenn-members.json))
          echo "::set-output name=zenn::$zenn"
          qiita=$(echo $(cat ./qiita-members.json))
          echo "::set-output name=qiita::$qiita"
      - uses: mk2/article-fetcher
        with:
          zenn: ${{ steps.id-list-json.outputs.zenn }}
          qiita: ${{ steps.id-list-json.outputs.qiita }}
          fromDaysAgo: 1
          qiitaAccessToken: ${{ secrets.QIITA_ACCESS_TOKEN }}
      - run: |
          node notify.mjs

開発環境

  • Node 12.x
  • Yarn v2

Article Fetcher is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.

About

Fetch articles from Zenn and Qiita
v0.9.4
Latest
By mk2

Article Fetcher is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.