Skip to content

Commit

Permalink
Merge pull request #98 from nakkaa/release_v1.0.4
Browse files Browse the repository at this point in the history
Release v1.0.4
  • Loading branch information
nakkaa authored Jun 5, 2020
2 parents 4f910d5 + dc51615 commit f43ccb3
Show file tree
Hide file tree
Showing 28 changed files with 305 additions and 80 deletions.
65 changes: 62 additions & 3 deletions .github/workflows/pr-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,74 @@ jobs:
python -m pip install --upgrade pip
pip install pipenv
pipenv install --dev
- name: Set .env
run: |
cp .env.example .env
- name: Test
run: |
pipenv run python -m unittest
# 型ヒントのチェックを行う
pr-type-hint:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]

steps:
- uses: actions/checkout@v2
- name: pipenv cache
uses: actions/cache@v1
with:
key: ${{ runner.os }}-${{ matrix.python-version }}-pipenv-${{ hashFiles('**/Pipfile.lock') }}
path: ~/.cache/pipenv
restore-keys: |
${{ runner.os }}-${{ matrix.python-version }}-pipenv-
- name: pip cache
uses: actions/cache@v1
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/Pipfile.lock') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pipenv
pipenv install --dev
- name: Check type hints
run: |
pipenv run mypy .
# 差分があるPythonファイルを取得する
pr-check-python-files-with-diff:
runs-on: ubuntu-latest

outputs:
files: ${{steps.check-python-files-with-diff.outputs.files}}

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Check Python file with diff
id: check-python-files-with-diff
run: |
git fetch --no-tags --prune --depth=1 origin ${GITHUB_HEAD_REF}
git fetch --no-tags --prune --depth=1 origin ${GITHUB_BASE_REF}
echo "::set-output name=files::$(git diff origin/${GITHUB_BASE_REF}..origin/${GITHUB_HEAD_REF} --diff-filter=AM --name-only -- '*.py' | tr '\n' ' ')"
# lintを行い、結果をPRにコメントとして表示する。
# ここではチェックは落ちない
pr-lint:
runs-on: ubuntu-latest
needs: pr-check-python-files-with-diff
# Pythonファイルが差分に含まれていない場合はスキップ
if: needs.pr-check-python-files-with-diff.outputs.files != ''
strategy:
matrix:
python-version: [3.8]
Expand Down Expand Up @@ -151,9 +211,7 @@ jobs:
- name: Lint files
id: lint
run: |
git fetch --no-tags --prune --depth=1 origin ${GITHUB_HEAD_REF}
git fetch --no-tags --prune --depth=1 origin ${GITHUB_BASE_REF}
result=$(pipenv run pylint --rcfile=./.pylintrc $(git diff origin/${GITHUB_BASE_REF}..origin/${GITHUB_HEAD_REF} --diff-filter=AM --name-only -- '*.py') 2>&1) || true
result=$(pipenv run pylint --rcfile=./.pylintrc ${{needs.pr-check-python-files-with-diff.outputs.files}} 2>&1) || true
result="${result//'%'/'%25'}"
result="${result//$'\n'/'%0A'}"
result="${result//$'\r'/'%0D'}"
Expand All @@ -162,6 +220,7 @@ jobs:
continue-on-error: true
# lint結果をコメントに残す
- name: Lint Comment
if: steps.lint.outputs.result != ''
uses: actions/[email protected]
with:
github-token: ${{secrets.GITHUB_TOKEN}}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
__pycache__/
.vscode/
setup/pgsql-data
.mypy_cache/
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ signature-mutators=
expected-line-ending-format=

# Regexp for a line that is allowed to be longer than the limit.
ignore-long-lines=^\s*(# )?<?https?://\S+>?$
ignore-long-lines=^\s*((# )?<?https?://\S+>?|(from .* )?import .*)$

# Number of spaces of indent required inside a hanging or continued line.
indent-after-paren=4
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
* `Removed` 削除された機能について。
* `Fixed` バグ修正について。

## v1.0.4 - 2020-06-06
### Changed
* DockerのpostgresqlもSSLに対応しました。(#66)
* Readmeに機能説明とTokenを発行する手順ページのリンクを追加しました。(#78)
* 天気コマンドを入力したときに全角スペースでも反応するように修正しました。(#80)

### Removed
* `amesh kyoto` コマンドは削除されました。(#83)


## v1.0.3 - 2020-05-23
### Added
* Botのアイコン画像を同梱しました。(#46)
Expand Down
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ requests = "==2.23.0"
slackbot = "==0.5.6"
Pillow = ">=7.1.2"
pg8000 = "==1.15.2"
mypy = "*"

[requires]
python_version = "3.8"
82 changes: 71 additions & 11 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 28 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
# 鳩bot
# 鳩bot - 愛嬌のあるSlack Bot
![](https://github.com/nakkaa/hato-bot/workflows/pr-test/badge.svg) [![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=nakkaa/hato-bot)](https://dependabot.com)

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)

- 愛嬌のあるSlack用botです。
- `天気 <地名>` で天気予報を教えてくれます。
- `amesh` で東京近郊の雨雲情報を教えてくれます。
- `>< 文字列` で文字列を「突然の死」吹き出しで整形してくれます。
鳩botではこんなことができます。

- 全国の天気予報 ... `天気 東京` で東京の天気予報を表示します。
- 東京近郊の雨雲情報 ... `amesh` で東京の雨雲情報を画像で表示します。
- 最新の地震情報 ... `eq` で最新の地震情報を3件表示します。
- パワーワードの登録、表示 ... `text` で登録したパワーワードを表示します。
- 突然の死吹き出しで整形 ... `>< 文字列` で文字列を「突然の死」吹き出しで整形します。

![](https://github.com/nakkaa/hato-age-bot/blob/images/hato1.png)

# 鳩botを動かす

鳩botを動かす方法は主に2種類あります。
簡単でおすすめなHerokuで動かす方法と自分のPC上で動かす方法です。
前者については、[Herokuで動かす手順](https://github.com/nakkaa/hato-bot/wiki/Heroku%E3%81%A7%E5%8B%95%E3%81%8B%E3%81%99%E6%89%8B%E9%A0%86) を参照してください。
ここでは後者の自分のPC上で動かす方法を説明します。

## 必要なもの
鳩botを動かすためには以下が必要です。
- Python3
- PostgreSQL(Dockerで導入可)
以下が必要です。
- Git、Python3、Pipenv、Docker(またはPostgreSQL)が動作するPC
- Slack API Token ([Slack API Tokenの取得方法](https://github.com/nakkaa/hato-bot/wiki/Slack-API-Token%E3%81%AE%E5%8F%96%E5%BE%97%E6%96%B9%E6%B3%95))
- Yahoo APIのトークン([Yahoo API Tokenの取得方法](https://github.com/nakkaa/hato-bot/wiki/Yahoo-API-Token%E3%81%AE%E5%8F%96%E5%BE%97%E6%96%B9%E6%B3%95))

## 初期設定

Expand All @@ -27,7 +39,7 @@
pipenv install
```
3. `.env` ファイルを作成し、SlackのAPI TokenとPostgreSQLの認証情報、(雨雲情報を取得する場合は)Yahoo APIのトークンを記述します
3. `.env` ファイルを作成し Slack API Token、PostgreSQLの認証情報、Yahoo API Tokenを記述します
```
SLACKBOT_API_TOKEN=xoxb_xxxxxxxxx
DATABASE_URL=postgres://postgres:password@localhost:5432/
Expand All @@ -45,6 +57,11 @@
6. `pipenv run python ./run.py` を実行します。
## formatする
## 補足
- コードをformatする場合は `pipenv run autopep8 --in-place --recursive .` を実行します。
## クレジット
Botで利用しているサービスのクレジットを記載します。
1. `pipenv run autopep8 --in-place --recursive .`
- [Web Services by Yahoo! JAPAN](https://developer.yahoo.co.jp/about)
23 changes: 15 additions & 8 deletions create_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,35 @@ def __init__(self):
def __enter__(self):
return self

def execute_sql(self, SQL) -> str:
def execute_sql(self, sql: str) -> None:
"""SQLを実行する"""

with self.conn.cursor() as cursor:
try:
cursor.execute(SQL)
cursor.execute(sql)
self.conn.commit()
print('Create table. {}'.format(SQL))
except:
print('Create table. {}'.format(sql))
except Exception as _e:
print('Can not execute sql(create_table).')
raise _e

def __exit__(self, exc_type, exc_value, traceback):
self.conn.close()


def create_table():
with CreateEnvDatabase() as db:
db.execute_sql(
def create_table() -> None:
"""テーブルを作成する"""

with CreateEnvDatabase() as _db:
_db.execute_sql(
"CREATE TABLE IF NOT EXISTS vocabulary(no serial UNIQUE, word text);")
db.execute_sql(
_db.execute_sql(
"CREATE TABLE IF NOT EXISTS labotter(user_name text UNIQUE, lab_in_flag int, lab_in timestamp, lab_rida timestamp, min_sum int);")


def main():
"""メイン関数"""

create_table()


Expand Down
Loading

0 comments on commit f43ccb3

Please sign in to comment.