-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
extreme4all
committed
Jan 23, 2024
1 parent
c227ed7
commit 7546a08
Showing
23 changed files
with
662 additions
and
496 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.