[twitter] Add public twitter endpoint to list all bots to a hood
This commit is contained in:
parent
a5a098a386
commit
5575782b9b
|
@ -6,17 +6,22 @@ from fastapi import APIRouter, Depends, HTTPException, Response, status
|
|||
from kibicara.config import config
|
||||
from kibicara.platforms.twitter.bot import spawner
|
||||
from kibicara.platforms.twitter.model import Twitter
|
||||
from kibicara.webapi.hoods import get_hood
|
||||
from kibicara.webapi.hoods import get_hood, get_hood_unauthorized
|
||||
from logging import getLogger
|
||||
from sqlite3 import IntegrityError
|
||||
from ormantic.exceptions import NoMatch
|
||||
from peony.oauth_dance import get_oauth_token, get_access_token
|
||||
from peony.exceptions import NotAuthenticated
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
logger = getLogger(__name__)
|
||||
|
||||
|
||||
class BodyTwitterPublic(BaseModel):
|
||||
username: str
|
||||
|
||||
|
||||
async def get_twitter(twitter_id: int, hood=Depends(get_hood)):
|
||||
try:
|
||||
return await Twitter.objects.get(id=twitter_id, hood=hood)
|
||||
|
@ -28,6 +33,20 @@ router = APIRouter()
|
|||
twitter_callback_router = APIRouter()
|
||||
|
||||
|
||||
@router.get(
|
||||
'/public',
|
||||
# TODO response_model,
|
||||
operation_id='get_twitters_public',
|
||||
)
|
||||
async def twitter_read_all_public(hood=Depends(get_hood_unauthorized)):
|
||||
twitterbots = await Twitter.objects.filter(hood=hood).all()
|
||||
return [
|
||||
BodyTwitterPublic(username=twitterbot.username)
|
||||
for twitterbot in twitterbots
|
||||
if twitterbot.verified == 1 and twitterbot.enabled == 1
|
||||
]
|
||||
|
||||
|
||||
@router.get(
|
||||
'/',
|
||||
# TODO response_model,
|
||||
|
|
Loading…
Reference in a new issue