Skip to content

Commit

Permalink
Merge pull request #79 from Bot-detector/update-dependancies
Browse files Browse the repository at this point in the history
Update dependancies
  • Loading branch information
extreme4all authored Jan 23, 2024
2 parents 6c1d92b + 554641c commit ace52bd
Show file tree
Hide file tree
Showing 24 changed files with 720 additions and 524 deletions.
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
repos:
- repo: https://github.com/psf/black
rev: 23.10.1
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black"]
39 changes: 32 additions & 7 deletions notes.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,62 @@
# api documentation
```
```sh
http://127.0.0.1:5000/docs
http://127.0.0.1:5000/redoc
```
# extra info
```
```sh
POST: to create data.
GET: to read data.
PUT: to update data.
DELETE: to delete data.
```
# keeping fork up to date
```
```sh
git checkout develop
git pull --rebase upstream develop
git push
```
# setup
creating a python venv to work in and install the project requirements
## linux
```sh
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install --upgrade pip
pip install -r requirements.txt
```
## windows
creating a python venv to work in and install the project requirements
```sh
python -m venv .venv
.venv\Scripts\activate
python -m pip install --upgrade pip
pip install -r requirements.txt
```
# for admin purposes saving & upgrading
when you added some dependancies update the requirements
## linux
```sh
#!/bin/bash

# Replace '==' with '>=' in requirements.txt
sed -i 's/==/>=/g' requirements.txt

# Install or upgrade packages
pip install -r requirements.txt --upgrade

# Save the installed package versions to requirements.txt
pip freeze > requirements.txt

# Replace '>=' with '==' in requirements.txt
sed -i 's/>=/==/g' requirements.txt
```
## windows
when you added some dependancies update the requirements
```sh
venv\Scripts\activate
call pip freeze > requirements.txt
```
when you want to upgrade the dependancies
```
```sh
venv\Scripts\activate
powershell "(Get-Content requirements.txt) | ForEach-Object { $_ -replace '==', '>=' } | Set-Content requirements.txt"
call pip install -r requirements.txt --upgrade
Expand All @@ -40,7 +65,7 @@ powershell "(Get-Content requirements.txt) | ForEach-Object { $_ -replace '>=',
```
# branch cleanup
if your branch gets out of sync and for some reason you have many pushes and pulls, to become insync without pushing some random changes do this
```
```sh
git fetch origin
git reset --hard origin/{branchname}
git clean -f -d
Expand Down
55 changes: 34 additions & 21 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,41 @@
aiohttp==3.8.5
aiohttp==3.9.1
aiosignal==1.3.1
anyio==3.6.2
async-timeout==4.0.2
attrs==22.2.0
black==23.1.0
charset-normalizer==3.1.0
click==8.1.3
annotated-types==0.6.0
anyio==4.2.0
async-timeout==4.0.3
attrs==23.2.0
black==23.12.1
cfgv==3.4.0
charset-normalizer==3.3.2
click==8.1.7
colorama==0.4.6
fastapi==0.95.0
frozenlist==1.3.3
distlib==0.3.8
exceptiongroup==1.2.0
fastapi==0.109.0
filelock==3.13.1
frozenlist==1.4.1
h11==0.14.0
idna==3.4
Jinja2==3.1.2
MarkupSafe==2.1.2
identify==2.5.33
idna==3.6
Jinja2==3.1.3
MarkupSafe==2.1.4
multidict==6.0.4
mypy-extensions==1.0.0
packaging==23.0
pathspec==0.11.1
platformdirs==3.1.1
pydantic==1.10.6
python-dotenv==1.0.0
nodeenv==1.8.0
packaging==23.2
pathspec==0.12.1
platformdirs==4.1.0
pre-commit==3.6.0
pydantic==2.5.3
pydantic-settings==2.1.0
pydantic_core==2.14.6
python-dotenv==1.0.1
python-multipart==0.0.6
PyYAML==6.0.1
sniffio==1.3.0
starlette==0.27.0
typing_extensions==4.5.0
uvicorn==0.21.1
yarl==1.8.2
starlette==0.35.1
tomli==2.0.1
typing_extensions==4.9.0
uvicorn==0.27.0
virtualenv==20.25.0
yarl==1.9.4
5 changes: 3 additions & 2 deletions src/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from fastapi import APIRouter
from src.api import monitoring, home, account_search, contributors, contact, faq

from src.api import account_search, contact, contributors, faq, home, monitoring

router = APIRouter()
router.include_router(monitoring.router, prefix="/monitoring")
router.include_router(home.router, prefix="/home")
router.include_router(account_search.router, prefix="/account-search")
router.include_router(contributors.router, prefix="/contributors")
router.include_router(contact.router, prefix="/contact")
router.include_router(faq.router, prefix="/about")
router.include_router(faq.router, prefix="/about")
5 changes: 2 additions & 3 deletions src/api/account_search.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from fastapi import APIRouter, Request, Form
from fastapi import APIRouter, Form, Request
from fastapi.responses import HTMLResponse

from src.core.config import CONFIG, templates, BD_API

from src.core.config import BD_API, CONFIG, templates

router = APIRouter()

Expand Down
3 changes: 2 additions & 1 deletion src/api/contact.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from fastapi import APIRouter, Request
from fastapi.responses import HTMLResponse

from src.core.config import CONFIG, templates

router = APIRouter()


@router.get("/")
async def contact(request: Request) -> HTMLResponse:
return templates.TemplateResponse("pages/contact.html", {"request": request})
return templates.TemplateResponse("pages/contact.html", {"request": request})
2 changes: 1 addition & 1 deletion src/api/contributors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

@router.get("/")
async def contributors(request: Request):
return templates.TemplateResponse("pages/contributors.html", {"request": request})
return templates.TemplateResponse("pages/contributors.html", {"request": request})
2 changes: 1 addition & 1 deletion src/api/faq.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

@router.get("/")
async def faq(request: Request):
return templates.TemplateResponse("pages/faq.html", {"request": request})
return templates.TemplateResponse("pages/faq.html", {"request": request})
8 changes: 5 additions & 3 deletions src/api/home.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
from fastapi import APIRouter, Request

from src.core.config import CONFIG, templates, BD_API
from pydantic import BaseModel

from src.core.config import BD_API, CONFIG, templates

router = APIRouter()


class Stats(BaseModel):
total_bans: int
total_real_players: int
total_accounts: int


@router.get("/")
async def home(request: Request):
stats = await BD_API.get_project_stats()
stats = Stats(**stats)
response = {"request": request, "stats": stats.dict()}
return templates.TemplateResponse("pages/home.html", response)
return templates.TemplateResponse("pages/home.html", response)
2 changes: 1 addition & 1 deletion src/api/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

@router.get("/", response_model=Health)
async def health() -> Health:
return Health(version=CONFIG.RELEASE_VERSION, status="Healthy")
return Health(version=CONFIG.RELEASE_VERSION, status="Healthy")
4 changes: 2 additions & 2 deletions src/app/controllers/bot_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ async def get_player(self, player_name: str):
async with self.session.get(url) as response:
data = await response.json()
return data

async def get_project_stats(self):
url = f"{self.base_url}/site/dashboard/projectstats"
async with self.session.get(url) as response:
data = await response.json()
return data
return data
40 changes: 22 additions & 18 deletions src/app/controllers/patreon.py
Original file line number Diff line number Diff line change
@@ -1,89 +1,93 @@
from typing import List

import aiohttp
from pydantic import BaseModel
from typing import List


class Campaign(BaseModel):
id: str
type: str
attributes: dict
relationships: dict


class CampaignsResponse(BaseModel):
data: List[Campaign]


class Member(BaseModel):
id: str
type: str
attributes: dict
relationships: dict


class MembersResponse(BaseModel):
data: List[Member]


class Patreon:
def __init__(
self,
client_id: str,
client_secret: str,
base_url: str = "https://www.patreon.com/api/oauth2/v2"
base_url: str = "https://www.patreon.com/api/oauth2/v2",
):
self.client_id = client_id
self.client_secret = client_secret
self.base_url = base_url
self.session = aiohttp.ClientSession()
self.access_token = None
self.headers = None

async def _client_authenticate(self):
# Step 1: Exchange your client credentials for an access token
data = {
"grant_type": "client_credentials",
"client_id": self.client_id,
"client_secret": self.client_secret,
"scope": "identity campaigns"
"scope": "identity campaigns",
}
token_url = f"{self.base_url}/oauth2/token"
async with self.session.post(token_url, data=data) as resp:
token_data = await resp.json()
self.access_token = token_data["access_token"]
self.headers = {
"Authorization": f"Bearer {self.access_token}"
}

self.headers = {"Authorization": f"Bearer {self.access_token}"}

async def _get_headers(self):
# Check if we are authenticated
if not self.headers:
await self._client_authenticate()

return self.headers

async def get_campaigns(self) -> CampaignsResponse:
headers = await self._get_headers()

url = f"{self.base_url}/campaigns"
async with self.session.get(url, headers=headers) as resp:
data = await resp.json()
return CampaignsResponse(**data)

async def get_members(self, campaign_id: str) -> MembersResponse:
headers = await self._get_headers()

url = f"{self.base_url}/campaigns/{campaign_id}/members"
async with self.session.get(url, headers=headers) as resp:
data = await resp.json()
return MembersResponse(**data)

async def get_member(self, member_id: str) -> Member:
headers = await self._get_headers()

url = f"{self.base_url}/members/{member_id}"
async with self.session.get(url, headers=headers) as resp:
data = await resp.json()
return Member(**data)

async def get_identity(self):
headers = await self._get_headers()

url = f"{self.base_url}/identity"
async with self.session.get(url, headers=headers) as resp:
return await resp.json()
return await resp.json()
2 changes: 1 addition & 1 deletion src/app/schemas/extras/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

class Health(BaseModel):
version: str = Field(..., example="1.0.0")
status: str = Field(..., example="OK")
status: str = Field(..., example="OK")
7 changes: 4 additions & 3 deletions src/core/config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from pydantic import BaseSettings
import os

from src.app.controllers.bot_detector import BotDetector
from src.app.controllers.patreon import Patreon
import dotenv
from fastapi.templating import Jinja2Templates
from pydantic_settings import BaseSettings

from src.app.controllers.bot_detector import BotDetector
from src.app.controllers.patreon import Patreon
from src.core.fastapi.middelware import https_url_for

dotenv.load_dotenv()
Expand Down
3 changes: 2 additions & 1 deletion src/core/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
from fastapi.middleware import Middleware
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import RedirectResponse
from fastapi.staticfiles import StaticFiles

from src import api
from src.core.config import CONFIG
from fastapi.staticfiles import StaticFiles


def init_routers(_app: FastAPI) -> None:
Expand Down
Loading

0 comments on commit ace52bd

Please sign in to comment.