From 11fc55e88a7297fb0410d97d0d9bdf82cac9162b Mon Sep 17 00:00:00 2001 From: extreme4all <40169115+extreme4all@users.noreply.github.com> Date: Sun, 28 Jul 2024 14:48:28 +0200 Subject: [PATCH] ruff check --fix --- src/api/legacy/legacy.py | 16 ++++++++-------- src/api/v1/hiscore.py | 13 ++++++------- src/api/v1/label.py | 1 - src/api/v1/player.py | 13 ++++++------- src/api/v1/prediction.py | 10 +++++----- src/api/v1/report.py | 9 +-------- src/api/v1/scraper.py | 7 +++---- src/api/v2/highscore.py | 1 - src/app/repositories/highscore.py | 1 - src/app/repositories/player.py | 4 ++-- src/core/server.py | 3 --- src/database/functions.py | 8 ++++---- src/kafka/highscore.py | 3 --- src/kafka/modules/abc.py | 1 - tests/test_feedback.py | 3 +-- tests/test_hiscore.py | 6 +++--- tests/test_label.py | 3 +-- tests/test_player.py | 2 +- tests/test_report.py | 3 +-- tests/test_scraper.py | 2 +- tests/utils/test_logging_helpers.py | 2 +- 21 files changed, 44 insertions(+), 67 deletions(-) diff --git a/src/api/legacy/legacy.py b/src/api/legacy/legacy.py index 8060b641..3f5ce9dd 100644 --- a/src/api/legacy/legacy.py +++ b/src/api/legacy/legacy.py @@ -9,7 +9,7 @@ import pandas as pd from src.core import config -from src.database.database import DISCORD_ENGINE, EngineType +from src.database.database import DISCORD_ENGINE from src.database import functions from src.database.functions import execute_sql, list_to_string, verify_token from src.utils import logging_helpers @@ -800,7 +800,7 @@ async def receive_plugin_feedback(feedback: Feedback, version: str = None): voter_data = await sql_insert_player(player_name) if not len(voter_data) > 0: - raise HTTPException(status_code=405, detail=f"Voter does not exist") + raise HTTPException(status_code=405, detail="Voter does not exist") feedback_params["voter_id"] = voter_data.get("id") exclude = ["player_name"] @@ -914,7 +914,7 @@ async def verify_bot(token: str, bots: bots, request: Request): label = bots["label"] if len(playerNames) == 0: - raise HTTPException(status_code=405, detail=f"Invalid Parameters") + raise HTTPException(status_code=405, detail="Invalid Parameters") data = [] for name in playerNames: @@ -992,17 +992,17 @@ async def verify_discord_user( code = verify_data.get("code", "") if len(code) != 4: - raise HTTPException(status_code=400, detail=f"Please provide a 4 digit code.") + raise HTTPException(status_code=400, detail="Please provide a 4 digit code.") try: provided_code = int(code) except ValueError: - raise HTTPException(status_code=400, detail=f"Please provide a 4 digit code.") + raise HTTPException(status_code=400, detail="Please provide a 4 digit code.") player = await sql_get_player(verify_data["player_name"]) if player == None: - raise HTTPException(status_code=400, detail=f"Could not find player") + raise HTTPException(status_code=400, detail="Could not find player") pending_discord = await sql_get_unverified_discord_user(player["id"]) @@ -1011,7 +1011,7 @@ async def verify_discord_user( token_id = token_info.get("id") if not pending_discord: - raise HTTPException(status_code=400, detail=f"No pending links for this user.") + raise HTTPException(status_code=400, detail="No pending links for this user.") found_code = False for record in pending_discord: @@ -1021,7 +1021,7 @@ async def verify_discord_user( break if not (found_code): - raise HTTPException(status_code=400, detail=f"Linking code is incorrect.") + raise HTTPException(status_code=400, detail="Linking code is incorrect.") return {"ok": "ok"} diff --git a/src/api/v1/hiscore.py b/src/api/v1/hiscore.py index 3e44665a..244fae6f 100644 --- a/src/api/v1/hiscore.py +++ b/src/api/v1/hiscore.py @@ -2,7 +2,6 @@ from src.database.functions import PLAYERDATA_ENGINE from sqlalchemy.ext.asyncio import AsyncSession -from src.database.database import EngineType from src.database.functions import sqlalchemy_result, verify_token from src.database.models import ( Player, @@ -220,22 +219,22 @@ async def get_latest_hiscore_data_by_player_features( sql = select(PlayerHiscoreDataLatest) # filters - if not possible_ban is None: + if possible_ban is not None: sql = sql.where(Player.possible_ban == possible_ban) - if not confirmed_ban is None: + if confirmed_ban is not None: sql = sql.where(Player.confirmed_ban == confirmed_ban) - if not confirmed_player is None: + if confirmed_player is not None: sql = sql.where(Player.confirmed_player == confirmed_player) - if not label_id is None: + if label_id is not None: sql = sql.where(Player.label_id == label_id) - if not label_jagex is None: + if label_jagex is not None: sql = sql.where(Player.label_jagex == label_jagex) - if not greater_than is None: + if greater_than is not None: sql = sql.where(Player.id >= greater_than) # paging diff --git a/src/api/v1/label.py b/src/api/v1/label.py index 8d96836c..ef2fdafb 100644 --- a/src/api/v1/label.py +++ b/src/api/v1/label.py @@ -1,4 +1,3 @@ -from src.database.database import EngineType from src.database.functions import sqlalchemy_result, verify_token from src.database.models import Label as dbLabel from fastapi import APIRouter diff --git a/src/api/v1/player.py b/src/api/v1/player.py index 5a0a1f2b..1f100a93 100644 --- a/src/api/v1/player.py +++ b/src/api/v1/player.py @@ -1,10 +1,9 @@ import time -from typing import List, Optional +from typing import Optional from src.database import functions from src.database.functions import PLAYERDATA_ENGINE from sqlalchemy.ext.asyncio import AsyncSession -from src.database.database import Engine, EngineType from src.database.functions import sqlalchemy_result, verify_token from src.database.models import Player as dbPlayer from src.utils import logging_helpers @@ -107,19 +106,19 @@ async def get_bulk_player_data_from_the_plugin_database( # filters # filters - if not possible_ban is None: + if possible_ban is not None: sql = sql.where(dbPlayer.possible_ban == possible_ban) - if not confirmed_ban is None: + if confirmed_ban is not None: sql = sql.where(dbPlayer.confirmed_ban == confirmed_ban) - if not confirmed_player is None: + if confirmed_player is not None: sql = sql.where(dbPlayer.confirmed_player == confirmed_player) - if not label_id is None: + if label_id is not None: sql = sql.where(dbPlayer.label_id == label_id) - if not label_jagex is None: + if label_jagex is not None: sql = sql.where(dbPlayer.label_jagex == label_jagex) # query pagination diff --git a/src/api/v1/prediction.py b/src/api/v1/prediction.py index 38ac8e69..8ea7ab4b 100644 --- a/src/api/v1/prediction.py +++ b/src/api/v1/prediction.py @@ -213,19 +213,19 @@ async def gets_predictions_by_player_features( sql: Select = select(dbPrediction) # filters - if not possible_ban is None: + if possible_ban is not None: sql = sql.where(Player.possible_ban == possible_ban) - if not confirmed_ban is None: + if confirmed_ban is not None: sql = sql.where(Player.confirmed_ban == confirmed_ban) - if not confirmed_player is None: + if confirmed_player is not None: sql = sql.where(Player.confirmed_player == confirmed_player) - if not label_id is None: + if label_id is not None: sql = sql.where(Player.label_id == label_id) - if not label_jagex is None: + if label_jagex is not None: sql = sql.where(Player.label_jagex == label_jagex) # paging diff --git a/src/api/v1/report.py b/src/api/v1/report.py index 1ff9f417..11fe9d04 100644 --- a/src/api/v1/report.py +++ b/src/api/v1/report.py @@ -1,17 +1,12 @@ import logging -import time from datetime import date from typing import List, Optional import asyncio -import pandas as pd from src.database import functions from src.database.functions import PLAYERDATA_ENGINE from src.database.models import ( Player, Report, - playerReports, - playerReportsManual, - stgReport, ) from src.utils import logging_helpers from fastapi import APIRouter, HTTPException, Query, Request, status @@ -20,10 +15,8 @@ from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.orm import aliased from sqlalchemy.sql import func -from sqlalchemy.sql.expression import Insert, Select, insert, select, update -from sqlalchemy import Text, text +from sqlalchemy.sql.expression import Select, select, update import aiohttp -import random import traceback logger = logging.getLogger(__name__) diff --git a/src/api/v1/scraper.py b/src/api/v1/scraper.py index f006d915..069d9d14 100644 --- a/src/api/v1/scraper.py +++ b/src/api/v1/scraper.py @@ -6,12 +6,11 @@ from src.database.functions import PLAYERDATA_ENGINE from sqlalchemy.ext.asyncio import AsyncSession -from src.database.database import EngineType from src.database.functions import batch_function, execute_sql, verify_token from src.database.models import Player as dbPlayer from src.database.models import playerHiscoreData from src.utils import logging_helpers -from fastapi import APIRouter, BackgroundTasks, Request +from fastapi import APIRouter, Request from pydantic import BaseModel from sqlalchemy.exc import InternalError, OperationalError from sqlalchemy.sql.expression import insert, update @@ -168,7 +167,7 @@ async def sqla_update_player(players: List): ) await session.execute(sql, player) dbplayer.remove(player) - except (OperationalError, InternalError) as e: + except (OperationalError, InternalError): await handle_lock(sqla_update_player, dbplayer) return @@ -185,7 +184,7 @@ async def sqla_insert_hiscore(hiscores: List): async with session.begin(): await session.execute(sql, hiscore) dbhiscores.remove(hiscore) - except (OperationalError, InternalError) as e: + except (OperationalError, InternalError): await handle_lock(sqla_insert_hiscore, dbhiscores) return diff --git a/src/api/v2/highscore.py b/src/api/v2/highscore.py index ba34ae84..300aff39 100644 --- a/src/api/v2/highscore.py +++ b/src/api/v2/highscore.py @@ -8,7 +8,6 @@ PlayerHiscoreDataLatest as RepositoryPlayerHiscoreDataLatest, ) from src.app.schemas.highscore import PlayerHiscoreData as SchemaPlayerHiscoreData -from pydantic import BaseModel router = APIRouter(tags=["Hiscore"]) diff --git a/src/app/repositories/highscore.py b/src/app/repositories/highscore.py index 937bf6a8..14048c47 100644 --- a/src/app/repositories/highscore.py +++ b/src/app/repositories/highscore.py @@ -3,7 +3,6 @@ from pydantic import BaseModel, ValidationError from sqlalchemy import select, union_all from sqlalchemy.dialects.mysql import insert -from sqlalchemy.exc import OperationalError from sqlalchemy.ext.asyncio import AsyncResult, AsyncSession from sqlalchemy.sql.expression import Insert, Select, and_ diff --git a/src/app/repositories/player.py b/src/app/repositories/player.py index a35ded06..f7cb5a97 100644 --- a/src/app/repositories/player.py +++ b/src/app/repositories/player.py @@ -1,9 +1,9 @@ import logging from pydantic import ValidationError -from sqlalchemy import delete, insert, select, update +from sqlalchemy import insert, select, update from sqlalchemy.ext.asyncio import AsyncResult, AsyncSession -from sqlalchemy.sql.expression import Delete, Insert, Select, Update, and_ +from sqlalchemy.sql.expression import Insert, Select, Update from src.app.schemas.player import Player as SchemaPlayer from src.database.database import PLAYERDATA_ENGINE diff --git a/src/core/server.py b/src/core/server.py index 16236f50..e95feb20 100644 --- a/src/core/server.py +++ b/src/core/server.py @@ -1,4 +1,3 @@ -import asyncio import json import logging import time @@ -10,8 +9,6 @@ from fastapi.responses import JSONResponse from src import api -from src.core import config -from src.kafka.highscore import HighscoreProcessor logger = logging.getLogger(__name__) diff --git a/src/database/functions.py b/src/database/functions.py index 7841bda9..8f6e1da1 100644 --- a/src/database/functions.py +++ b/src/database/functions.py @@ -17,7 +17,7 @@ # Although never directly used, the engines are imported to add a permanent reference # to these entities to prevent the # garbage collector from trying to dispose of our engines. -from src.database.database import PLAYERDATA_ENGINE, Engine, EngineType +from src.database.database import PLAYERDATA_ENGINE, Engine from src.database.models import ApiPermission, ApiUsage, ApiUser, ApiUserPerm logger = logging.getLogger(__name__) @@ -186,15 +186,15 @@ async def verify_token(token: str, verification: str, route: str = None) -> bool # If len api_user == 0; user does not have necessary permissions if len(api_user) == 0: - raise HTTPException(status_code=401, detail=f"Insufficent Permissions") + raise HTTPException(status_code=401, detail="Insufficent Permissions") api_user = api_user[0] if api_user["is_active"] != 1: - raise HTTPException(status_code=403, detail=f"Insufficent Permissions") + raise HTTPException(status_code=403, detail="Insufficent Permissions") if (len(usage_data) > api_user["ratelimit"]) and (api_user["ratelimit"] != -1): - raise HTTPException(status_code=429, detail=f"Your Ratelimit has been reached.") + raise HTTPException(status_code=429, detail="Your Ratelimit has been reached.") return True diff --git a/src/kafka/highscore.py b/src/kafka/highscore.py index c62708e1..806295c0 100644 --- a/src/kafka/highscore.py +++ b/src/kafka/highscore.py @@ -1,7 +1,5 @@ -import json import logging -from aiokafka import AIOKafkaConsumer, ConsumerRecord, TopicPartition from src.app.repositories.highscore import PlayerHiscoreData as RepoHiscore from src.app.repositories.player import Player as RepositoryPlayer @@ -9,7 +7,6 @@ from src.app.schemas.player import Player as SchemaPlayer from src.database.models import playerHiscoreData as dbHiscore from src.kafka.modules.kafka_consumer import KafkaMessageConsumer -from src.kafka.modules.kafka_producer import KafkaMessageProducer from asyncio import Queue import asyncio import time diff --git a/src/kafka/modules/abc.py b/src/kafka/modules/abc.py index 81dc0758..e6647612 100644 --- a/src/kafka/modules/abc.py +++ b/src/kafka/modules/abc.py @@ -1,5 +1,4 @@ from abc import ABC, abstractmethod -from aiokafka import ConsumerRecord class AbstractConsumer(ABC): diff --git a/tests/test_feedback.py b/tests/test_feedback.py index 9f5d04cb..a8a542b4 100644 --- a/tests/test_feedback.py +++ b/tests/test_feedback.py @@ -3,7 +3,6 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -import pytest def test_get_feedback(test_client): @@ -24,5 +23,5 @@ def test_get_feedback(test_client): # type check if response.ok: - error = f"Invalid response return type, expected list[dict]" + error = "Invalid response return type, expected list[dict]" assert isinstance(response.json(), list), error diff --git a/tests/test_hiscore.py b/tests/test_hiscore.py index 9312b554..007276bf 100644 --- a/tests/test_hiscore.py +++ b/tests/test_hiscore.py @@ -30,7 +30,7 @@ def test_get_player_hiscore_data(test_client): # type check if response.ok: - error = f"Invalid response return type, expected list[dict]" + error = "Invalid response return type, expected list[dict]" assert isinstance(response.json(), list), error @@ -58,7 +58,7 @@ def test_get_latest_hiscore_data_for_an_account(test_client): # type check if response.ok: - error = f"Invalid response return type, expected list[dict]" + error = "Invalid response return type, expected list[dict]" assert isinstance(response.json(), list), error @@ -114,7 +114,7 @@ def test_get_account_hiscore_xp_change(test_client): # type check if response.ok: - error = f"Invalid response return type, expected list[dict]" + error = "Invalid response return type, expected list[dict]" assert isinstance(response.json(), list), error diff --git a/tests/test_label.py b/tests/test_label.py index 24fb364c..9dcc432a 100644 --- a/tests/test_label.py +++ b/tests/test_label.py @@ -3,7 +3,6 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -import pytest from src.core.config import token @@ -29,5 +28,5 @@ def test_get_labels(test_client): # type check if response.ok: - error = f"Invalid response return type, expected list[dict]" + error = "Invalid response return type, expected list[dict]" assert isinstance(response.json(), list), error diff --git a/tests/test_player.py b/tests/test_player.py index e342f4b5..10f5267c 100644 --- a/tests/test_player.py +++ b/tests/test_player.py @@ -30,5 +30,5 @@ def test_get_player_information(test_client): # type check if response.ok: - error = f"Invalid response return type, expected list[dict]" + error = "Invalid response return type, expected list[dict]" assert isinstance(response.json(), list), error diff --git a/tests/test_report.py b/tests/test_report.py index aff0b484..ffe3673f 100644 --- a/tests/test_report.py +++ b/tests/test_report.py @@ -3,7 +3,6 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -import pytest from src.core.config import token @@ -29,5 +28,5 @@ def test_report_count(test_client): # type check if response.ok: - error = f"Invalid response return type, expected list[dict]" + error = "Invalid response return type, expected list[dict]" assert isinstance(response.json(), list), error diff --git a/tests/test_scraper.py b/tests/test_scraper.py index 03e3f26d..f6916d3c 100644 --- a/tests/test_scraper.py +++ b/tests/test_scraper.py @@ -22,5 +22,5 @@ def test_scraper_players(test_client): # type check if response.ok: - error = f"Invalid response return type, expected list[dict]" + error = "Invalid response return type, expected list[dict]" assert isinstance(response.json(), list), error diff --git a/tests/utils/test_logging_helpers.py b/tests/utils/test_logging_helpers.py index 0ad894b5..b20ebadb 100644 --- a/tests/utils/test_logging_helpers.py +++ b/tests/utils/test_logging_helpers.py @@ -8,7 +8,7 @@ from api.routers import hiscore from src.utils import logging_helpers -request_path = f"/v1/hiscore/Latest" +request_path = "/v1/hiscore/Latest" request_params = {"player_id": 1, "token": token}