diff --git a/poetry.lock b/poetry.lock index 538359a..f5ed52e 100644 --- a/poetry.lock +++ b/poetry.lock @@ -131,6 +131,18 @@ d = ["aiohttp (>=3.7.4)"] jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"] uvloop = ["uvloop (>=0.15.2)"] +[[package]] +name = "blinker" +version = "1.5" +description = "Fast, simple object-to-object and broadcast signaling" +category = "main" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +files = [ + {file = "blinker-1.5-py2.py3-none-any.whl", hash = "sha256:1eb563df6fdbc39eeddc177d953203f99f097e9bf0e2b8f9f3cf18b6ca425e36"}, + {file = "blinker-1.5.tar.gz", hash = "sha256:923e5e2f69c155f2cc42dafbbd70e16e3fde24d2d4aa2ab72fbe386238892462"}, +] + [[package]] name = "certifi" version = "2022.12.7" @@ -1308,7 +1320,9 @@ files = [ ] [package.dependencies] +blinker = {version = ">=1.1", optional = true, markers = "extra == \"flask\""} certifi = "*" +flask = {version = ">=0.11", optional = true, markers = "extra == \"flask\""} urllib3 = {version = ">=1.26.11", markers = "python_version >= \"3.6\""} [package.extras] @@ -1707,4 +1721,4 @@ testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools" [metadata] lock-version = "2.0" python-versions = "^3.7" -content-hash = "e3031b5c16ad6cf25f786cf4d14f0871d0abace95d3380c1a6b14b7e1ab37756" +content-hash = "ea1fd278a3dc000ed3d374c9006b959014cf8f67c62c99bc4b15aeeca2e64311" diff --git a/pynyaata/__init__.py b/pynyaata/__init__.py index ab352a1..57f79ef 100644 --- a/pynyaata/__init__.py +++ b/pynyaata/__init__.py @@ -1,5 +1,6 @@ import asyncio from datetime import datetime +from os import getenv from secrets import token_hex from flask import Flask, redirect, render_template, request, url_for @@ -8,6 +9,25 @@ from pynyaata.bridge import search_all from pynyaata.forms import SearchForm from pynyaata.translations import current_lang, i18n +from sentry_sdk import init +from sentry_sdk.integrations.asyncio import AsyncioIntegration +from sentry_sdk.integrations.flask import FlaskIntegration +from sentry_sdk.integrations.redis import RedisIntegration +from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration + + +SENTRY_DNS = getenv("SENTRY_DSN") +if SENTRY_DNS: + init( + SENTRY_DNS, + integrations=[ + AsyncioIntegration(), + FlaskIntegration(), + RedisIntegration(), + SqlalchemyIntegration(), + ], + ) + app = Flask(__name__) app.config["SECRET_KEY"] = token_hex() diff --git a/pynyaata/bridge/__init__.py b/pynyaata/bridge/__init__.py index 97912ff..2a06999 100644 --- a/pynyaata/bridge/__init__.py +++ b/pynyaata/bridge/__init__.py @@ -22,4 +22,4 @@ async def search_all(query: str = "", page: int = 1) -> List[RemoteFile]: for bridge in BRIDGES: tasks.append(create_task(bridge.search(query, page))) - return await gather(*tasks) + return await gather(*tasks, return_exceptions=True) diff --git a/pynyaata/bridge/animeultime.py b/pynyaata/bridge/animeultime.py index 131e394..d093bbd 100644 --- a/pynyaata/bridge/animeultime.py +++ b/pynyaata/bridge/animeultime.py @@ -27,7 +27,7 @@ class AnimeUltime(Bridge): return parse_obj_as( HttpUrl, ( - f"{self.base_url}" + f"{self.base_url}/" f"{'search' if query else 'history'}-0-1/" f"{page_date.strftime('%m%Y') if query else ''}" ), diff --git a/pynyaata/types.py b/pynyaata/types.py index 6fc6eaf..cdf7724 100644 --- a/pynyaata/types.py +++ b/pynyaata/types.py @@ -2,7 +2,7 @@ from abc import ABC, abstractmethod from datetime import datetime from enum import Enum from functools import wraps -from logging import error +from logging import exception from typing import List, Optional from pydantic import BaseModel, ByteSize, HttpUrl @@ -72,7 +72,7 @@ def log_async(f): try: return await f(*args, **kwargs) except Exception as e: - error(e) + exception(e) raise e return wrapper diff --git a/pyproject.toml b/pyproject.toml index b469dfd..a88e080 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,7 @@ pydantic = "1.10.4" pymysql = "1.0.2" redis = "4.4.0" requests = "2.28.1" -sentry-sdk = "1.12.1" +sentry-sdk = {extras = ["flask"], version = "1.12.1"} [tool.poetry.group.dev.dependencies]