Compare commits
No commits in common. "38b66677ab8c01aee10cd59e745af9ce3ea88092" and "7e62a7af3fb4f20556066fc9b9ccb7620c0add91" have entirely different histories.
38b66677ab
...
7e62a7af3f
|
@ -106,7 +106,7 @@ in
|
|||
''
|
||||
install -Dm600 ${envFile} /run/pvv-calendar-bot/env
|
||||
${pkgs.replace-secret}/bin/replace-secret '@MATRIX_ACCESS_TOKEN@' ${cfg.settings.secretsFile} /run/pvv-calendar-bot/env
|
||||
${pkgs.replace-secret}/bin/replace-secret '@MYSQL_PASSWORD@' ${cfg.settings.database.passwordFile} /run/pvv-calendar-bot/env
|
||||
#${pkgs.replace-secret}/bin/replace-secret '@MYSQL_PASSWORD@' ${cfg.settings.database.passwordFile} /run/pvv-calendar-bot/env
|
||||
'';
|
||||
|
||||
serviceConfig = {
|
||||
|
|
|
@ -10,14 +10,15 @@ 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")
|
||||
MATRIX_USER=os.environ.get("MATRIX_USER","@bot_calendar:pvv.ntnu.no")
|
||||
MATRIX_TOKEN=os.environ.get("MATRIX_TOKEN")
|
||||
ANNOUNCEMENT_CHANNEL=os.environ.get("ANNOUNCEMENT_CHANNEL", "!announcements:pvv.ntnu.no")
|
||||
|
||||
client = None
|
||||
|
||||
def create_announcement(event: Event, atEveryone: bool) -> str:
|
||||
|
||||
def create_announcement(event,atEveryone):
|
||||
url = "https://www.pvv.ntnu.no/hendelser/info.php?id={}".format(event.id)
|
||||
msgText = dedent('''\
|
||||
## Dagens arrangement / Event of the Day: "{name}"
|
||||
|
@ -37,15 +38,10 @@ def create_announcement(event: Event, atEveryone: bool) -> str:
|
|||
|
||||
if atEveryone:
|
||||
msgText = msgText + '\n@room'
|
||||
|
||||
return msgText
|
||||
|
||||
|
||||
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)
|
||||
return await client.room_send(
|
||||
room_id=channel,
|
||||
|
@ -54,7 +50,7 @@ async def sendMatrixAnnouncement(
|
|||
"msgtype": "m.text",
|
||||
"body": msgText,
|
||||
"format": "org.matrix.custom.html",
|
||||
"formatted_body": Markdown().convert(msgText),
|
||||
"formatted_body": Markdown().convert(msgText)
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -20,34 +20,33 @@ class Event:
|
|||
|
||||
def fetch_events():
|
||||
mydb = mysql.connector.connect(
|
||||
host = os.environ.get("MYSQL_URL","mysql.pvv.ntnu.no").strip(),
|
||||
user = os.environ.get("MYSQL_USER","calendar-bot").strip(),
|
||||
password = os.environ["MYSQL_PASSWORD"].strip(),
|
||||
database = "www-data_nettside",
|
||||
host = os.environ.get("MYSQL_URL","mysql.pvv.ntnu.no"),
|
||||
user = os.environ.get("MYSQL_USER","calendar-bot"),
|
||||
password = os.environ["MYSQL_PASSWORD"], #lmao
|
||||
database = "www-data_nettside"
|
||||
)
|
||||
|
||||
mycursor = mydb.cursor()
|
||||
mycursor.execute("""
|
||||
SELECT id,name,start,stop,location,description,organiser
|
||||
FROM events
|
||||
WHERE DATE(start) = CURDATE()
|
||||
""")
|
||||
SELECT id,name,start,stop,location,description,organiser
|
||||
FROM events
|
||||
WHERE DATE(start) = CURDATE()
|
||||
""")
|
||||
|
||||
db_result = mycursor.fetchall()
|
||||
|
||||
results = []
|
||||
for row in db_result:
|
||||
results.append(Event(
|
||||
id = row[0],
|
||||
name = row[1],
|
||||
start = datetime.fromisoformat(row[2]),
|
||||
stop = datetime.fromisoformat(row[3]),
|
||||
location = row[4],
|
||||
description = row[5],
|
||||
organiser = row[6],
|
||||
))
|
||||
results.append(Event(id=row[0],
|
||||
name=row[1],
|
||||
start=datetime.fromisoformat(row[2]),
|
||||
stop=datetime.fromisoformat(row[3]),
|
||||
location=row[4],
|
||||
description=row[5],
|
||||
organiser=row[6],
|
||||
))
|
||||
return results
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pprint(fetch_events())
|
||||
pprint(fetch_events())
|
Loading…
Reference in New Issue