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