gitea
ben/notflixbot/pipeline/head This commit looks good Details

main
Ben Kristinsson 7 months ago
parent 6e777e9348
commit 8809491061

2
Jenkinsfile vendored

@ -1,3 +1,3 @@
@Library('shared-jenkins-pipelines') _
dockerimg tag: 'latest', dockreg: 'dockreg.sudo.is'
dockerimg tag: 'latest', dockreg: 'git.sudo.is/ben'

@ -1,6 +1,7 @@
import asyncio
import getpass
import json
import time
import aiohttp.client_exceptions
import click
@ -113,7 +114,17 @@ class MatrixClient:
blocked and waiting for the first iteration of the sync loop to start
"""
logger.info("matrix client syncing forever")
return await self.nio.sync_forever(timeout=3000, full_state=True)
while True:
try:
return await self.nio.sync_forever(
timeout=3000, full_state=True)
except (
asyncio.exceptions.TimeoutError,
aiohttp.client_exceptions.ClientOSError
) as e:
logger.error(e)
logger.error("timed out, reconnecting after 10s..")
time.sleep(10.0)
async def start(self):
if not self.nio.logged_in:
@ -302,7 +313,7 @@ class MatrixClient:
logger.debug(f"got invite to {room.room_id} from {event.sender}")
result = await self.nio.join(room.room_id)
if type(result) == JoinError:
if isinstance(result, JoinError):
logger.error(f"error joining room {room.room_id}: {result}.")
else:
logger.info(
@ -398,7 +409,7 @@ class MatrixClient:
async def _handle_crash(self, room, event):
# CRASH AND BURN
return 1/0
return 1 / 0
async def _handle_add(self, room, event):
try:

@ -267,9 +267,12 @@ class Webhook:
async def _handle_grafana(self, request):
j = request['json']
with open('/home/ben/grafana-json-dump.txt', 'a') as f:
f.write(json.dumps(j, indent=2))
state = j['state']
name = j['ruleName']
u = j['ruleUrl']
name = j.get('ruleName', "NO_RULE_NAME")
u = j.get('ruleUrl', 'NO_URL')
if 'message' in j:
m = f"\n> {j['message']}\n\n"
else:
@ -300,10 +303,10 @@ class Webhook:
else:
emoji = WARNING
msg = f"{emoji} grafana: <u>[{name}]({u})</u> {mv} {m}"
plain = f"{emoji} {name}"
msg = f"{emoji} grafana: <u>[{name}]({u})</u> {mv} {m}" # noqa
plain = f"{emoji} {name}" # noqa
await self._send(request['room'], msg, plain)
# await self._send(request['room'], msg, plain)
async def _handle_jellyfin(self, request):
"""
@ -336,7 +339,7 @@ class Webhook:
prefix = f"{j['SeriesName']} - "
else:
prefix = ""
msg = f"{VIDEO} `{user}` is playing [_{prefix}{name}_]({url}) from {device} ({client})" # noqa
msg = f"{VIDEO} `{user}` is playing [_{prefix}{name}_]({url}) from {device} ({client})" # noqa
plain = msg.replace(
"playing _", "playing ").replace("_ from", " from")
await self._send(request['room'], msg, plain, not_again=True)

30
poetry.lock generated

@ -80,6 +80,18 @@ docs = ["furo", "sphinx", "zope.interface", "sphinx-notfound-page"]
tests = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface", "cloudpickle"]
tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "cloudpickle"]
[[package]]
name = "autopep8"
version = "1.6.0"
description = "A tool that automatically formats Python code to conform to the PEP 8 style guide"
category = "dev"
optional = false
python-versions = "*"
[package.dependencies]
pycodestyle = ">=2.8.0"
toml = "*"
[[package]]
name = "black"
version = "22.1.0"
@ -583,6 +595,14 @@ category = "main"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*"
[[package]]
name = "toml"
version = "0.10.2"
description = "Python Library for Tom's Obvious, Minimal Language"
category = "dev"
optional = false
python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*"
[[package]]
name = "tomli"
version = "2.0.1"
@ -677,7 +697,7 @@ pyzmq = "*"
[metadata]
lock-version = "1.1"
python-versions = "^3.9"
content-hash = "77739c45e62d5dc4becb507625ca3d33525a3736f76f0b5f5144740361f1fd53"
content-hash = "c491ddb766a315b4024b1e39deeb745a7f43b24eb12e84ef64ea4af0df80c693"
[metadata.files]
aiofiles = [
@ -778,6 +798,10 @@ attrs = [
{file = "attrs-21.4.0-py2.py3-none-any.whl", hash = "sha256:2d27e3784d7a565d36ab851fe94887c5eccd6a463168875832a1be79c82828b4"},
{file = "attrs-21.4.0.tar.gz", hash = "sha256:626ba8234211db98e869df76230a137c4c40a12d72445c45d5f5b716f076e2fd"},
]
autopep8 = [
{file = "autopep8-1.6.0-py2.py3-none-any.whl", hash = "sha256:ed77137193bbac52d029a52c59bec1b0629b5a186c495f1eb21b126ac466083f"},
{file = "autopep8-1.6.0.tar.gz", hash = "sha256:44f0932855039d2c15c4510d6df665e4730f2b8582704fa48f9c55bd3e17d979"},
]
black = [
{file = "black-22.1.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:1297c63b9e1b96a3d0da2d85d11cd9bf8664251fd69ddac068b98dc4f34f73b6"},
{file = "black-22.1.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:2ff96450d3ad9ea499fc4c60e425a1439c2120cbbc1ab959ff20f7c76ec7e866"},
@ -1233,6 +1257,10 @@ six = [
{file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"},
{file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"},
]
toml = [
{file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"},
{file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"},
]
tomli = [
{file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"},
{file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"},

@ -21,6 +21,7 @@ pytest = "^5.2"
flake8 = "^4.0.1"
isort = "^5.10.1"
black = "^22.1.0"
autopep8 = "^1.6.0"
[tool.poetry.scripts]
notflixbot = "notflixbot.main:main"

Loading…
Cancel
Save