[mastodon] New style: double quotes instead of single quotes

This commit is contained in:
missytake 2023-03-18 21:00:50 +01:00
parent 7fd716cecc
commit 36638b1c64
3 changed files with 22 additions and 22 deletions

View file

@ -43,14 +43,14 @@ class MastodonBot(Censor):
last_seen = int(self.model.last_seen) last_seen = int(self.model.last_seen)
for status in notifications: for status in notifications:
try: try:
status_id = int(status['status']['id']) status_id = int(status["status"]["id"])
except KeyError: except KeyError:
continue # ignore notifications which don't have a status continue # ignore notifications which don't have a status
if status_id <= last_seen: if status_id <= last_seen:
continue # toot was already processed in the past continue # toot was already processed in the past
if status_id > int(self.model.last_seen): if status_id > int(self.model.last_seen):
await self.model.update(last_seen=str(status_id)) await self.model.update(last_seen=str(status_id))
text = re.sub(r'<[^>]*>', '', status['status']['content']) text = re.sub(r"<[^>]*>", "", status["status"]["content"])
text = re.sub( text = re.sub(
"(?<=^|(?<=[^a-zA-Z0-9-_.]))@([A-Za-z]+[A-Za-z0-9-_]+)", "", text "(?<=^|(?<=[^a-zA-Z0-9-_.]))@([A-Za-z]+[A-Za-z0-9-_]+)", "", text
) )
@ -58,7 +58,7 @@ class MastodonBot(Censor):
"Mastodon in %s received toot #%s: %s" "Mastodon in %s received toot #%s: %s"
% (self.model.hood.name, status_id, text) % (self.model.hood.name, status_id, text)
) )
if status['status']['visibility'] == 'public': if status["status"]["visibility"] == "public":
await self.publish(Message(text, toot_id=status_id)) await self.publish(Message(text, toot_id=status_id))
else: else:
await self.publish(Message(text)) await self.publish(Message(text))

View file

@ -15,7 +15,7 @@ class MastodonInstance(Model):
client_secret: Text() client_secret: Text()
class Mapping(Mapping): class Mapping(Mapping):
table_name = 'mastodoninstances' table_name = "mastodoninstances"
class MastodonAccount(Model): class MastodonAccount(Model):
@ -27,4 +27,4 @@ class MastodonAccount(Model):
last_seen: Text() last_seen: Text()
class Mapping(Mapping): class Mapping(Mapping):
table_name = 'mastodonaccounts' table_name = "mastodonaccounts"

View file

@ -55,9 +55,9 @@ twitter_callback_router = APIRouter()
@router.get( @router.get(
'/public', "/public",
# TODO response_model, # TODO response_model,
operation_id='get_mastodons_public', operation_id="get_mastodons_public",
) )
async def mastodon_read_all_public(hood=Depends(get_hood_unauthorized)): async def mastodon_read_all_public(hood=Depends(get_hood_unauthorized)):
mastodonbots = await MastodonAccount.objects.filter(hood=hood).all() mastodonbots = await MastodonAccount.objects.filter(hood=hood).all()
@ -69,28 +69,28 @@ async def mastodon_read_all_public(hood=Depends(get_hood_unauthorized)):
@router.get( @router.get(
'/', "/",
# TODO response_model, # TODO response_model,
operation_id='get_mastodons', operation_id="get_mastodons",
) )
async def mastodon_read_all(hood=Depends(get_hood)): async def mastodon_read_all(hood=Depends(get_hood)):
return await MastodonAccount.objects.filter(hood=hood).all() return await MastodonAccount.objects.filter(hood=hood).all()
@router.get( @router.get(
'/{mastodon_id}', "/{mastodon_id}",
# TODO response_model # TODO response_model
operation_id='get_mastodon', operation_id="get_mastodon",
) )
async def mastodon_read(mastodon=Depends(get_mastodon)): async def mastodon_read(mastodon=Depends(get_mastodon)):
return mastodon return mastodon
@router.delete( @router.delete(
'/{mastodon_id}', "/{mastodon_id}",
status_code=status.HTTP_204_NO_CONTENT, status_code=status.HTTP_204_NO_CONTENT,
# TODO response_model # TODO response_model
operation_id='delete_mastodon', operation_id="delete_mastodon",
) )
async def mastodon_delete(mastodon=Depends(get_mastodon)): async def mastodon_delete(mastodon=Depends(get_mastodon)):
spawner.stop(mastodon) spawner.stop(mastodon)
@ -99,20 +99,20 @@ async def mastodon_delete(mastodon=Depends(get_mastodon)):
@router.get( @router.get(
'/{mastodon_id}/status', "/{mastodon_id}/status",
status_code=status.HTTP_200_OK, status_code=status.HTTP_200_OK,
# TODO response_model # TODO response_model
operation_id='status_mastodon', operation_id="status_mastodon",
) )
async def mastodon_status(mastodon=Depends(get_mastodon)): async def mastodon_status(mastodon=Depends(get_mastodon)):
return {'status': spawner.get(mastodon).status.name} return {"status": spawner.get(mastodon).status.name}
@router.post( @router.post(
'/{mastodon_id}/start', "/{mastodon_id}/start",
status_code=status.HTTP_200_OK, status_code=status.HTTP_200_OK,
# TODO response_model # TODO response_model
operation_id='start_mastodon', operation_id="start_mastodon",
) )
async def mastodon_start(mastodon=Depends(get_mastodon)): async def mastodon_start(mastodon=Depends(get_mastodon)):
await mastodon.update(enabled=True) await mastodon.update(enabled=True)
@ -121,10 +121,10 @@ async def mastodon_start(mastodon=Depends(get_mastodon)):
@router.post( @router.post(
'/{mastodon_id}/stop', "/{mastodon_id}/stop",
status_code=status.HTTP_200_OK, status_code=status.HTTP_200_OK,
# TODO response_model # TODO response_model
operation_id='stop_mastodon', operation_id="stop_mastodon",
) )
async def mastodon_stop(mastodon=Depends(get_mastodon)): async def mastodon_stop(mastodon=Depends(get_mastodon)):
await mastodon.update(enabled=False) await mastodon.update(enabled=False)
@ -133,10 +133,10 @@ async def mastodon_stop(mastodon=Depends(get_mastodon)):
@router.post( @router.post(
'/', "/",
status_code=status.HTTP_201_CREATED, status_code=status.HTTP_201_CREATED,
# TODO response_model # TODO response_model
operation_id='create_mastodon', operation_id="create_mastodon",
) )
async def mastodon_create(instance_url, username, password, hood=Depends(get_hood)): async def mastodon_create(instance_url, username, password, hood=Depends(get_hood)):
"""Add a Mastodon Account to a Ticketfrei account. """Add a Mastodon Account to a Ticketfrei account.