ruff format
This commit is contained in:
@@ -10,16 +10,19 @@ from markdown2 import Markdown
|
||||
import asyncio
|
||||
from .sql_connector import fetch_events, Event
|
||||
|
||||
MATRIX_URL=os.environ.get("MATRIX_URL","https://matrix.pvv.ntnu.no").strip()
|
||||
MATRIX_USER=os.environ.get("MATRIX_USER","@bot_calendar:pvv.ntnu.no").strip()
|
||||
MATRIX_TOKEN=os.environ.get("MATRIX_TOKEN").strip()
|
||||
ANNOUNCEMENT_CHANNEL=os.environ.get("ANNOUNCEMENT_CHANNEL", "!announcements:pvv.ntnu.no").strip()
|
||||
MATRIX_URL = os.environ.get("MATRIX_URL", "https://matrix.pvv.ntnu.no").strip()
|
||||
MATRIX_USER = os.environ.get("MATRIX_USER", "@bot_calendar:pvv.ntnu.no").strip()
|
||||
MATRIX_TOKEN = os.environ.get("MATRIX_TOKEN").strip()
|
||||
ANNOUNCEMENT_CHANNEL = os.environ.get(
|
||||
"ANNOUNCEMENT_CHANNEL", "!announcements:pvv.ntnu.no"
|
||||
).strip()
|
||||
|
||||
client = None
|
||||
|
||||
|
||||
def create_announcement(event: Event, atEveryone: bool) -> str:
|
||||
url = "https://www.pvv.ntnu.no/hendelser/info.php?id={}".format(event.id)
|
||||
msgText = dedent('''\
|
||||
msgText = dedent("""\
|
||||
## Dagens arrangement / Event of the Day: "{name}"
|
||||
- 🕒 **{start}**
|
||||
- 📍 **{location}**
|
||||
@@ -27,26 +30,24 @@ def create_announcement(event: Event, atEveryone: bool) -> str:
|
||||
{description}
|
||||
|
||||
[Les mer / Read More]({url})
|
||||
''').format(
|
||||
name=event.name,
|
||||
start=event.start.strftime('%H:%M'),
|
||||
location=event.location,
|
||||
description=event.description,
|
||||
url=url,
|
||||
)
|
||||
""").format(
|
||||
name=event.name,
|
||||
start=event.start.strftime("%H:%M"),
|
||||
location=event.location,
|
||||
description=event.description,
|
||||
url=url,
|
||||
)
|
||||
|
||||
if atEveryone:
|
||||
msgText = msgText + '\n@room'
|
||||
msgText = msgText + "\n@room"
|
||||
|
||||
return msgText
|
||||
|
||||
|
||||
async def sendMatrixAnnouncement(
|
||||
event: Event,
|
||||
channel: str = ANNOUNCEMENT_CHANNEL,
|
||||
atEveryone: bool = False
|
||||
event: Event, channel: str = ANNOUNCEMENT_CHANNEL, atEveryone: bool = False
|
||||
) -> None:
|
||||
msgText = create_announcement(event,atEveryone)
|
||||
msgText = create_announcement(event, atEveryone)
|
||||
return await client.room_send(
|
||||
room_id=channel,
|
||||
message_type="m.room.message",
|
||||
@@ -55,9 +56,10 @@ async def sendMatrixAnnouncement(
|
||||
"body": msgText,
|
||||
"format": "org.matrix.custom.html",
|
||||
"formatted_body": Markdown().convert(msgText),
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
async def sendCalendarEvents() -> None:
|
||||
global client
|
||||
client = AsyncClient(MATRIX_URL, MATRIX_USER)
|
||||
@@ -70,8 +72,10 @@ async def sendCalendarEvents() -> None:
|
||||
|
||||
await client.close()
|
||||
|
||||
|
||||
def main():
|
||||
asyncio.run(sendCalendarEvents())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user