pre-commit
This commit is contained in:
parent
b621d8ed5a
commit
02e5a9dfc7
2 changed files with 34 additions and 4 deletions
29
.pre-commit-config.yaml
Normal file
29
.pre-commit-config.yaml
Normal file
|
@ -0,0 +1,29 @@
|
|||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v2.4.0
|
||||
hooks:
|
||||
- id: check-added-large-files
|
||||
- id: check-ast
|
||||
- id: check-merge-conflict
|
||||
- id: check-symlinks
|
||||
- id: check-toml
|
||||
- id: check-yaml
|
||||
- id: debug-statements
|
||||
- id: detect-private-key
|
||||
- id: end-of-file-fixer
|
||||
- id: flake8
|
||||
- id: mixed-line-ending
|
||||
- id: trailing-whitespace
|
||||
- repo: https://github.com/pre-commit/mirrors-yapf
|
||||
rev: v0.29.0
|
||||
hooks:
|
||||
- id: yapf
|
||||
- repo: https://github.com/PyCQA/pydocstyle
|
||||
rev: 5.0.1
|
||||
hooks:
|
||||
- id: pydocstyle
|
||||
- repo: https://gitlab.com/smop/pre-commit-hooks
|
||||
rev: v1.0.0
|
||||
hooks:
|
||||
- id: check-poetry
|
||||
- id: check-gitlab-ci
|
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Matrix Webhook
|
||||
Matrix Webhook.
|
||||
|
||||
Post a message to a matrix room with a simple HTTP POST
|
||||
v1: matrix-client & http.server
|
||||
v2: matrix-nio & aiohttp
|
||||
|
@ -13,7 +14,6 @@ from signal import SIGINT, SIGTERM
|
|||
|
||||
from aiohttp import web
|
||||
from nio import AsyncClient
|
||||
from nio.rooms import MatrixRoom
|
||||
|
||||
SERVER_ADDRESS = ('', int(os.environ.get('PORT', 4785)))
|
||||
MATRIX_URL = os.environ.get('MATRIX_URL', 'https://matrix.org')
|
||||
|
@ -26,6 +26,7 @@ CLIENT = AsyncClient(MATRIX_URL, MATRIX_ID)
|
|||
async def handler(request):
|
||||
"""
|
||||
Coroutine given to the server, st. it knows what to do with an HTTP request.
|
||||
|
||||
This one handles a POST, checks its content, and forwards it to the matrix room.
|
||||
"""
|
||||
data = await request.read()
|
||||
|
@ -49,11 +50,10 @@ async def handler(request):
|
|||
|
||||
async def main(event):
|
||||
"""
|
||||
Main coroutine
|
||||
Launch main coroutine.
|
||||
|
||||
matrix client login & start web server
|
||||
"""
|
||||
|
||||
await CLIENT.login(MATRIX_PW)
|
||||
|
||||
server = web.Server(handler)
|
||||
|
@ -71,6 +71,7 @@ async def main(event):
|
|||
|
||||
|
||||
def terminate(event, signal):
|
||||
"""Close handling stuff."""
|
||||
event.set()
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.remove_signal_handler(signal)
|
||||
|
|
Loading…
Reference in a new issue