Final changes (Fixed stuff, implemented stuff, removed password)
This commit is contained in:
parent
383e1bbf79
commit
9d75973ba7
|
@ -8,12 +8,11 @@ from nio import AsyncClient
|
|||
from textwrap import dedent
|
||||
from markdown2 import Markdown
|
||||
import asyncio
|
||||
import datetime
|
||||
from sql_connector import fetch_events, Event
|
||||
|
||||
MATRIX_URL=os.environ.get("MATRIX_URL","https://matrix.pvv.ntnu.no")
|
||||
MATRIX_USER=os.environ.get("MATRIX_USER","@bot_calendar:pvv.ntnu.no")
|
||||
MATRIX_TOKEN=os.environ.get("MATRIX_TOKEN","test")
|
||||
MATRIX_TOKEN=os.environ.get("MATRIX_TOKEN")
|
||||
ANNOUNCEMENT_CHANNEL=os.environ.get("ANNOUNCEMENT_CHANNEL", "!announcements:pvv.ntnu.no")
|
||||
|
||||
client = None
|
||||
|
@ -37,8 +36,6 @@ def create_announcement(event,atEveryone):
|
|||
url=url,
|
||||
)
|
||||
|
||||
# msgText = dedent(msgText)
|
||||
|
||||
if atEveryone:
|
||||
msgText = msgText + '\n@room'
|
||||
return msgText
|
||||
|
@ -46,29 +43,28 @@ def create_announcement(event,atEveryone):
|
|||
|
||||
async def sendMatrixAnnouncement(event: Event, channel: str = ANNOUNCEMENT_CHANNEL, atEveryone: bool = False) -> None:
|
||||
msgText = create_announcement(event,atEveryone)
|
||||
print(msgText)
|
||||
# return await client.room_send(
|
||||
# room_id=channel,
|
||||
# message_type="m.room.message",
|
||||
# content={
|
||||
# "msgtype": "m.text",
|
||||
# "body": msgText,
|
||||
# "format": "org.matrix.custom.html",
|
||||
# "formatted_body": Markdown().convert(msgText)
|
||||
# }
|
||||
# )
|
||||
return await client.room_send(
|
||||
room_id=channel,
|
||||
message_type="m.room.message",
|
||||
content={
|
||||
"msgtype": "m.text",
|
||||
"body": msgText,
|
||||
"format": "org.matrix.custom.html",
|
||||
"formatted_body": Markdown().convert(msgText)
|
||||
}
|
||||
)
|
||||
|
||||
async def sendCalendarEvents() -> None:
|
||||
# global client
|
||||
# client = AsyncClient(MATRIX_URL, MATRIX_USER)
|
||||
# client.access_token = MATRIX_TOKEN
|
||||
global client
|
||||
client = AsyncClient(MATRIX_URL, MATRIX_USER)
|
||||
client.access_token = MATRIX_TOKEN
|
||||
|
||||
eventsToday = fetch_events()
|
||||
|
||||
for event in eventsToday:
|
||||
await sendMatrixAnnouncement(event, ANNOUNCEMENT_CHANNEL, False)
|
||||
|
||||
# await client.close()
|
||||
await client.close()
|
||||
|
||||
def main():
|
||||
asyncio.run(sendCalendarEvents())
|
||||
|
|
|
@ -35,8 +35,6 @@ def fetch_events():
|
|||
|
||||
db_result = mycursor.fetchall()
|
||||
|
||||
|
||||
|
||||
results = []
|
||||
for row in db_result:
|
||||
results.append(Event(id=row[0],
|
||||
|
|
Loading…
Reference in New Issue