Skip to content

Commit

Permalink
ruff check --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
extreme4all committed Jul 28, 2024
1 parent 1d40578 commit 11fc55e
Show file tree
Hide file tree
Showing 21 changed files with 44 additions and 67 deletions.
16 changes: 8 additions & 8 deletions src/api/legacy/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"])

Expand All @@ -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:
Expand All @@ -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"}

Expand Down
13 changes: 6 additions & 7 deletions src/api/v1/hiscore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/api/v1/label.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 6 additions & 7 deletions src/api/v1/player.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/api/v1/prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 1 addition & 8 deletions src/api/v1/report.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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__)
Expand Down
7 changes: 3 additions & 4 deletions src/api/v1/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/api/v2/highscore.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
PlayerHiscoreDataLatest as RepositoryPlayerHiscoreDataLatest,
)
from src.app.schemas.highscore import PlayerHiscoreData as SchemaPlayerHiscoreData
from pydantic import BaseModel

router = APIRouter(tags=["Hiscore"])

Expand Down
1 change: 0 additions & 1 deletion src/app/repositories/highscore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_

Expand Down
4 changes: 2 additions & 2 deletions src/app/repositories/player.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/core/server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
import json
import logging
import time
Expand All @@ -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__)

Expand Down
8 changes: 4 additions & 4 deletions src/database/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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

Expand Down
3 changes: 0 additions & 3 deletions src/kafka/highscore.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
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
from src.app.schemas.highscore import PlayerHiscoreData as SchemaHiscore
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
Expand Down
1 change: 0 additions & 1 deletion src/kafka/modules/abc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from abc import ABC, abstractmethod
from aiokafka import ConsumerRecord


class AbstractConsumer(ABC):
Expand Down
3 changes: 1 addition & 2 deletions tests/test_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
6 changes: 3 additions & 3 deletions tests/test_hiscore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down
3 changes: 1 addition & 2 deletions tests/test_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
2 changes: 1 addition & 1 deletion tests/test_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit 11fc55e

Please sign in to comment.