Compare commits
18 Commits
f086fd9792
...
v0.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 1729332373 | |||
| 8c5d6de5a4 | |||
| 5f735dce6a | |||
| de11a6934c | |||
| 457a49e754 | |||
| 92a2c6956a | |||
| 1bf297752d | |||
| 156a2db485 | |||
| 714738dcba | |||
| 66212229f5 | |||
| 3167bd7976 | |||
| 877d9e37b3 | |||
| fd0081d4d0 | |||
| 966353de3e | |||
| ae9ae46fea | |||
| d8e2027efa | |||
| 272c9519b9 | |||
| 1890d28f47 |
@@ -13,3 +13,6 @@ helm-charts
|
|||||||
.editorconfig
|
.editorconfig
|
||||||
.idea
|
.idea
|
||||||
coverage*
|
coverage*
|
||||||
|
output*
|
||||||
|
dist
|
||||||
|
data
|
||||||
10
.env.sample
Normal file
10
.env.sample
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
ntfy_on=true
|
||||||
|
ntfy_username=chiko
|
||||||
|
ntfy_password=Blub
|
||||||
|
ntfy_host=ntfy.some-service.com
|
||||||
|
ntfy_topic=SomeTopic
|
||||||
|
|
||||||
|
dc_on=true
|
||||||
|
dc_webhook=123123123123123/ABCDEFABCDEFABCDEFABCDEFABCDEFABCDEFABCDEF
|
||||||
|
dc_botname=Botname Here
|
||||||
|
dc_avatar_url=https://pico.eix-1.n8x.sx/-tbcjZCuAtj
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -37,3 +37,4 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
|||||||
|
|
||||||
*.db
|
*.db
|
||||||
*.sqlite
|
*.sqlite
|
||||||
|
data
|
||||||
50
Dockerfile
50
Dockerfile
@@ -1,14 +1,27 @@
|
|||||||
FROM debian:12 AS base
|
FROM debian:12 AS base
|
||||||
WORKDIR /usr/src/app
|
ARG BUILD_DATE
|
||||||
RUN apt-get update && \
|
ARG VERSION
|
||||||
apt-get install -y curl unzip ca-certificates python3 python3-pip && \
|
LABEL build_version="77th_eventcalendarntfy ${VERSION}, Build-date:- ${BUILD_DATE}"
|
||||||
rm -rf /var/lib/apt/lists/*
|
LABEL maintainer="chiko <chiko@xcsone.de>"
|
||||||
|
WORKDIR /opt/app
|
||||||
|
RUN set -eux && \
|
||||||
|
echo "Updating APT" && \
|
||||||
|
apt-get update -y -qq && \
|
||||||
|
apt-get upgrade -y -qq && \
|
||||||
|
echo "Installing tools" && \
|
||||||
|
apt-get install -y -qq \
|
||||||
|
curl unzip cron ca-certificates logrotate && \
|
||||||
|
echo "Cleaning up" && \
|
||||||
|
apt-get --yes autoremove --purge && \
|
||||||
|
apt-get clean --yes && \
|
||||||
|
rm --recursive --force --verbose /var/lib/apt/lists/* && \
|
||||||
|
rm --recursive --force --verbose /tmp/* && \
|
||||||
|
rm --recursive --force --verbose /var/tmp/* && \
|
||||||
|
rm --recursive --force --verbose /var/cache/apt/archives/* && \
|
||||||
|
truncate --size 0 /var/log/*log
|
||||||
# install BunJs
|
# install BunJs
|
||||||
RUN curl -fsSL https://bun.com/install | bash
|
RUN curl -fsSL https://bun.com/install | bash
|
||||||
ENV PATH="/root/.bun/bin:$PATH"
|
ENV PATH="/root/.bun/bin:$PATH"
|
||||||
# symlink python
|
|
||||||
RUN ln -s /usr/bin/python3 /usr/bin/python
|
|
||||||
|
|
||||||
# install dependencies into temp directory
|
# install dependencies into temp directory
|
||||||
# this will cache them and speed up future builds
|
# this will cache them and speed up future builds
|
||||||
FROM base AS install
|
FROM base AS install
|
||||||
@@ -20,24 +33,27 @@ RUN cd /temp/dev && bun install --frozen-lockfile
|
|||||||
RUN mkdir -p /temp/prod
|
RUN mkdir -p /temp/prod
|
||||||
COPY package.json bun.lock /temp/prod/
|
COPY package.json bun.lock /temp/prod/
|
||||||
RUN cd /temp/prod && bun install --frozen-lockfile --production
|
RUN cd /temp/prod && bun install --frozen-lockfile --production
|
||||||
# prepare python packages
|
|
||||||
RUN pip3 install -r requirements.txt
|
COPY ./docker/Crontab /etc/cron.d/
|
||||||
|
RUN chmod 0644 /etc/cron.d/Crontab
|
||||||
|
COPY ./docker/cron-bun-log /etc/logrotate.d/
|
||||||
|
RUN mkdir /var/log/cron && touch /var/log/cron.log
|
||||||
|
|
||||||
# copy node_modules from temp directory
|
# copy node_modules from temp directory
|
||||||
# then copy all (non-ignored) project files into the image
|
# then copy all (non-ignored) project files into the image
|
||||||
FROM base AS prerelease
|
FROM base AS prerelease
|
||||||
COPY --from=install /temp/dev/node_modules node_modules
|
COPY --from=install /temp/dev/node_modules node_modules
|
||||||
COPY . .
|
COPY . ./
|
||||||
|
|
||||||
# [optional] tests & build
|
# [optional] tests & build
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
# copy production dependencies and source code into final image
|
# copy production dependencies and source code into final image
|
||||||
FROM base AS release
|
FROM base AS release
|
||||||
COPY --from=install /temp/prod/node_modules node_modules
|
COPY --from=install /temp/prod/node_modules node_modules
|
||||||
COPY --from=prerelease /usr/src/app/index.ts .
|
COPY --from=prerelease /opt/app/package.json .
|
||||||
COPY --from=prerelease /usr/src/app/package.json .
|
#COPY --from=prerelease .entrypoint.sh .
|
||||||
|
COPY . ./
|
||||||
# run the app
|
RUN mkdir /var/log/cron && touch /var/log/cron.log
|
||||||
USER bun
|
VOLUME /opt/app/data/db
|
||||||
ENTRYPOINT ["./entrypoint.sh"]
|
# VOLUME /var/log/cron
|
||||||
|
CMD bun run ./src/app.ts --today && cron && tail -f /var/log/cron.log
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
from dotenv import load_dotenv
|
|
||||||
import os
|
|
||||||
|
|
||||||
load_dotenv() # Load environment variables from .env file
|
|
||||||
ntfy_username = os.getenv('ntfy_username')
|
|
||||||
ntfy_password = os.getenv('ntfy_password')
|
|
||||||
ntfy_host = os.getenv('ntfy_host')
|
|
||||||
ntfy_topic = os.getenv('ntfy_topic')
|
|
||||||
dc_webhook = os.getenv('dc_webhook')
|
|
||||||
dc_botname = os.getenv('dc_botname')
|
|
||||||
dc_avatar_url = os.getenv('dc_avatar_url')
|
|
||||||
|
|
||||||
from argparse import ArgumentParser
|
|
||||||
import apprise
|
|
||||||
|
|
||||||
parser = ArgumentParser()
|
|
||||||
parser.add_argument("--title")
|
|
||||||
parser.add_argument("--body")
|
|
||||||
parser.add_argument("--click")
|
|
||||||
args = parser.parse_args()
|
|
||||||
print(args)
|
|
||||||
|
|
||||||
apobj = apprise.Apprise()
|
|
||||||
# config = apprise.AppriseConfig()
|
|
||||||
# config.add('https://myserver:8080/path/to/config')
|
|
||||||
if ntfy_host and ntfy_topic:
|
|
||||||
ntfy_link = f"ntfys://{ntfy_username}:{ntfy_password}@{ntfy_host}/{ntfy_topic}"
|
|
||||||
if args.click:
|
|
||||||
ntfy_link = ntfy_link + "?click=" + args.click
|
|
||||||
apobj.add(ntfy_link)
|
|
||||||
if dc_webhook:
|
|
||||||
apobj.add(f"discord://{dc_webhook}?avatar_url={dc_avatar_url}&botname={dc_botname}");
|
|
||||||
|
|
||||||
apobj.notify(
|
|
||||||
body=args.body,
|
|
||||||
title=args.title
|
|
||||||
)
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
import * as Bun from "bun";
|
|
||||||
|
|
||||||
export function sendNotification(title: string, body: string, click?: string | null) {
|
|
||||||
const command = [
|
|
||||||
"python",
|
|
||||||
"./app/notification.py",
|
|
||||||
`--title=${title}`,
|
|
||||||
`--body=${body}`,
|
|
||||||
];
|
|
||||||
if (click) {
|
|
||||||
command.push(`--click=${click}`);
|
|
||||||
}
|
|
||||||
Bun.spawn(command);
|
|
||||||
}
|
|
||||||
37
docker-compose.yml
Normal file
37
docker-compose.yml
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
services:
|
||||||
|
app:
|
||||||
|
build: .
|
||||||
|
volumes:
|
||||||
|
- ./data/db:/opt/app/data/db
|
||||||
|
- ./data/app/log:/var/log
|
||||||
|
env_file:
|
||||||
|
- path: ./.env
|
||||||
|
required: true
|
||||||
|
depends_on:
|
||||||
|
apprise:
|
||||||
|
condition: service_healthy
|
||||||
|
links:
|
||||||
|
- apprise
|
||||||
|
apprise:
|
||||||
|
image: caronc/apprise:latest
|
||||||
|
hostname: apprise
|
||||||
|
environment:
|
||||||
|
- APPRISE_WORKER_COUNT=1
|
||||||
|
- APPRISE_STATEFUL_MODE=simple
|
||||||
|
# - PUID=$(id -u)
|
||||||
|
# - PGID=$(id -g)
|
||||||
|
volumes:
|
||||||
|
- ./data/apprise/config:/config
|
||||||
|
- ./data/apprise/plugin:/plugin
|
||||||
|
- ./data/apprise/attach:/attach
|
||||||
|
# ports:
|
||||||
|
#- 8880:8000
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "curl", "-f", "http://localhost:8000/status"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
# networks:
|
||||||
|
# default:
|
||||||
|
# external: true
|
||||||
|
# name: npm
|
||||||
2
docker/Crontab
Normal file
2
docker/Crontab
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
8 * * * * bun run ./src/app.ts --today > /var/log/cron.log 2>&1
|
||||||
|
*/15 * * * * bun run ./src/app.ts > /var/log/cron.log 2>&1
|
||||||
8
docker/cron-bun-log
Normal file
8
docker/cron-bun-log
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
/var/log/cron.log {
|
||||||
|
daily
|
||||||
|
rotate 7
|
||||||
|
compress
|
||||||
|
missingok
|
||||||
|
notifempty
|
||||||
|
copytruncate
|
||||||
|
}
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
crontab -l > mycron
|
|
||||||
echo "0 8 * * * bun run ./app/app.ts --today > /dev/null 2>&1" >> mycron
|
|
||||||
echo "0 * * * * bun run ./app/app.ts --all > /dev/null 2>&1" >> mycron
|
|
||||||
crontab mycron
|
|
||||||
rm mycron
|
|
||||||
11
package.json
11
package.json
@@ -1,17 +1,20 @@
|
|||||||
{
|
{
|
||||||
|
"version": "0.1.0",
|
||||||
"name": "eventcalender",
|
"name": "eventcalender",
|
||||||
"module": "index.ts",
|
"module": "./src/app.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"private": true,
|
"private": true,
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bun": "^1.3.0"
|
"@types/bun": "^1.3.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "bun run ./app/app.ts",
|
"dev": "bun run ./src/app.ts",
|
||||||
"dev:init": "bun run ./app/app.ts --init",
|
"dev:init": "bun run ./src/app.ts --init",
|
||||||
"db:init": "bun run ./run/db_init.ts",
|
"db:init": "bun run ./run/db_init.ts",
|
||||||
"db:deleteall": "bun run ./run/db_deleteall.ts",
|
"db:deleteall": "bun run ./run/db_deleteall.ts",
|
||||||
"build": "bun build ./app/app.ts --compile --outfile ./build/77th_event_calendar_notification"
|
"build": "bun build --compile --minify --sourcemap ./src/app.ts --outfile ./build/77th_event_calendar_notification",
|
||||||
|
"build:linux": "bun build --compile --minify --sourcemap --target=bun-linux-arm64 ./src/app.ts --outfile ./build/77th_event_calendar_notification",
|
||||||
|
"docker:build": "docker build -t chiko/77th_eventcalendarntfy:0.1.0 ."
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"typescript": "^5"
|
"typescript": "^5"
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
apprise
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import * as db from "../app/sql";
|
import * as db from "../src/sql";
|
||||||
|
|
||||||
const query = db.db.query("DELETE FROM events;");
|
const query = db.db.query("DELETE FROM events;");
|
||||||
query.run();
|
query.run();
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Event } from "../app/component/event/events";
|
import { Event } from "../src/component/event/events";
|
||||||
import * as db from "../app/sql";
|
import * as db from "../src/sql";
|
||||||
import { Database } from "bun:sqlite";
|
import { Database } from "bun:sqlite";
|
||||||
|
|
||||||
export function init ( db: Database ) {
|
export function init ( db: Database ) {
|
||||||
|
|||||||
@@ -1,31 +1,25 @@
|
|||||||
import { TEventType } from "./component/event/event.types";
|
import { TEventType } from "./component/event/event.types";
|
||||||
import { db } from "./sql";
|
import { db } from "./sql";
|
||||||
import { Event, type TEventEntityNew, type TGetEventsOptions } from "./component/event/events";
|
import { Event, type TEventEntityNew, type TGetEventsOptions } from "./component/event/events";
|
||||||
|
import { createPlaceholders, getTsNow, pad_l2 } from "./util";
|
||||||
import { sendNotification } from "./sendNotification";
|
import { sendNotification } from "./sendNotification";
|
||||||
import { createPlaceholders, pad_l2 } from "./util";
|
|
||||||
|
|
||||||
const argv = require('minimist')(process.argv.slice(2));
|
const argv = require('minimist')(process.argv.slice(2));
|
||||||
console.dir(argv)
|
console.log("App started");
|
||||||
|
console.dir({argv})
|
||||||
// const TS_TODAY = new Date();
|
|
||||||
|
|
||||||
function getTsNow() {
|
|
||||||
const now = new Date();
|
|
||||||
const rtn = {
|
|
||||||
year: now.getFullYear(),
|
|
||||||
month: now.getMonth() + 1,
|
|
||||||
day: now.getDate(),
|
|
||||||
minute: now.getMinutes(),
|
|
||||||
seconds: now.getSeconds()
|
|
||||||
}
|
|
||||||
return rtn;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function main ( ) {
|
async function main ( ) {
|
||||||
|
console.log("Excecuting main()");
|
||||||
const TODAY = getTsNow();
|
const TODAY = getTsNow();
|
||||||
|
console.dir(TODAY);
|
||||||
const events_currentMonth = await Event.fetch_events( TODAY.year, TODAY.month , -120 );
|
const events_currentMonth = await Event.fetch_events( TODAY.year, TODAY.month , -120 );
|
||||||
|
console.log("events_currentMonth.length:" + events_currentMonth.length );
|
||||||
const events_nextMonth = await Event.fetch_events( TODAY.year, TODAY.month + 1 , -120 );
|
const events_nextMonth = await Event.fetch_events( TODAY.year, TODAY.month + 1 , -120 );
|
||||||
|
console.log("events_nextMonth.length:" + events_nextMonth.length );
|
||||||
const events = [...events_currentMonth, ...events_nextMonth];
|
const events = [...events_currentMonth, ...events_nextMonth];
|
||||||
|
console.log("events.length:" + events.length );
|
||||||
|
|
||||||
|
// const TS_TODAY = new Date();
|
||||||
// Write to JSON File Section START
|
// Write to JSON File Section START
|
||||||
// const data = JSON.stringify(events, null, 2);
|
// const data = JSON.stringify(events, null, 2);
|
||||||
// const TS = `${TS_TODAY.getFullYear()}-${TS_TODAY.getMonth() + 1}-${TS_TODAY.getDate()}_${TS_TODAY.getHours()}-${TS_TODAY.getMinutes()}-${TS_TODAY.getSeconds()}`;
|
// const TS = `${TS_TODAY.getFullYear()}-${TS_TODAY.getMonth() + 1}-${TS_TODAY.getDate()}_${TS_TODAY.getHours()}-${TS_TODAY.getMinutes()}-${TS_TODAY.getSeconds()}`;
|
||||||
@@ -33,16 +27,19 @@ async function main( ) {
|
|||||||
// Write to JSON File Section END
|
// Write to JSON File Section END
|
||||||
|
|
||||||
const allEventUids = events.map( event => { return event.uid; });
|
const allEventUids = events.map( event => { return event.uid; });
|
||||||
|
console.dir(allEventUids );
|
||||||
const placeholders = createPlaceholders( allEventUids );
|
const placeholders = createPlaceholders( allEventUids );
|
||||||
const getAllRelevantEventsQuery = db.query(
|
const getAllRelevantEventsQuery = db.query(
|
||||||
`SELECT * FROM events WHERE uid IN (${placeholders}); `
|
`SELECT * FROM events WHERE uid IN (${placeholders}); `
|
||||||
).as(Event );
|
).as(Event );
|
||||||
const AllRelevantEvents = getAllRelevantEventsQuery.all(...allEventUids);
|
const AllRelevantEvents = getAllRelevantEventsQuery.all(...allEventUids);
|
||||||
|
console.log("AllRelevantEvents.length:" + AllRelevantEvents.length );
|
||||||
const eventsToInsert: TEventEntityNew[] = [];
|
const eventsToInsert: TEventEntityNew[] = [];
|
||||||
for ( const ev of events ) {
|
for ( const ev of events ) {
|
||||||
|
console.log("loop ev: " + [ ev.uid, ev.title, ev.date_at ].join( ", " ) );
|
||||||
const found = AllRelevantEvents.find(event => event.uid === ev.uid);
|
const found = AllRelevantEvents.find(event => event.uid === ev.uid);
|
||||||
if ( found ) {
|
if ( found ) {
|
||||||
|
console.log("loop ev found: " + [ found.uid, found.title, found.date_at ].join( ", " ) );
|
||||||
if (
|
if (
|
||||||
found.title != ev.title ||
|
found.title != ev.title ||
|
||||||
found.description != ev.description ||
|
found.description != ev.description ||
|
||||||
@@ -55,29 +52,34 @@ async function main( ) {
|
|||||||
found.timezone != ev.timezone ||
|
found.timezone != ev.timezone ||
|
||||||
found.link != ev.link
|
found.link != ev.link
|
||||||
) {
|
) {
|
||||||
|
console.log("loop ev different (changed): " + [ ev.uid, ev.title, ev.date_at ].join( ", " ) );
|
||||||
const newEventToInsert: TEventEntityNew = {... ev, notification: "changed"};
|
const newEventToInsert: TEventEntityNew = {... ev, notification: "changed"};
|
||||||
eventsToInsert.push( newEventToInsert );
|
eventsToInsert.push( newEventToInsert );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
console.log("loop ev added (new): " + [ ev.uid, ev.title, ev.date_at ].join( ", " ) );
|
||||||
const newEventToInsert: TEventEntityNew = {... ev, notification: "new"};
|
const newEventToInsert: TEventEntityNew = {... ev, notification: "new"};
|
||||||
eventsToInsert.push( newEventToInsert );
|
eventsToInsert.push( newEventToInsert );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.dir(eventsToInsert)
|
||||||
Event.insert( eventsToInsert, db);
|
Event.insert( eventsToInsert, db);
|
||||||
const options: TGetEventsOptions = {
|
const where: TGetEventsOptions = {}
|
||||||
}
|
where.notification = ["new", "changed"]
|
||||||
if ( argv.today ) {
|
if ( argv.today ) {
|
||||||
options.date = {
|
where.date = {
|
||||||
year: TODAY.year,
|
year: TODAY.year,
|
||||||
month: TODAY.month,
|
month: TODAY.month,
|
||||||
day: TODAY.day
|
day: TODAY.day
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
options.notification = ["new", "changed"]
|
|
||||||
}
|
}
|
||||||
const list_of_events = Event.get_events( options, db );
|
const list_of_events = Event.get_events( where, db );
|
||||||
|
console.dir({
|
||||||
|
list_of_events,
|
||||||
|
where
|
||||||
|
});
|
||||||
for ( const ev of list_of_events ) {
|
for ( const ev of list_of_events ) {
|
||||||
|
console.log("loop list_of_events - ev: " + [ev.uid, ev.title, ev.date_at, "notification:" + ev.notification].join( ", " ) );
|
||||||
const body = [
|
const body = [
|
||||||
`Title: ${ev.title}`,
|
`Title: ${ev.title}`,
|
||||||
`Location: ${ev.location}`,
|
`Location: ${ev.location}`,
|
||||||
@@ -87,6 +89,7 @@ async function main( ) {
|
|||||||
`By: ${ev.posted_by}`,
|
`By: ${ev.posted_by}`,
|
||||||
`Link: ${ev.link}`,
|
`Link: ${ev.link}`,
|
||||||
].join("\n");
|
].join("\n");
|
||||||
|
console.log("loop list_of_events - ev 'body': " + body );
|
||||||
const notification_prefix = ( (event: Event) => {
|
const notification_prefix = ( (event: Event) => {
|
||||||
switch( event.notification) {
|
switch( event.notification) {
|
||||||
case "new":
|
case "new":
|
||||||
@@ -112,11 +115,9 @@ async function main( ) {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
})( ev );
|
})( ev );
|
||||||
sendNotification(
|
const title = `${today_prefix ? "TODAY " : ""}${notification_prefix ? notification_prefix + ": " : ""} ${ev.title} (${ TEventType[ ev.event_type ] })`;
|
||||||
`${today_prefix ? "TODAY " : ""}${notification_prefix ? notification_prefix + ": " : ""} ${ev.title} (${ TEventType[ ev.event_type ] })`,
|
console.log("loop list_of_events - ev 'title': " + title );
|
||||||
`${body}`
|
await sendNotification( title, body, ev.link ? ev.link : null);
|
||||||
// `${ev.link || "https://77th-jsoc.com/#/events"}`
|
|
||||||
);
|
|
||||||
ev.set_notification("done", db);
|
ev.set_notification("done", db);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
41
src/notification.py
Normal file
41
src/notification.py
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
from dotenv import load_dotenv
|
||||||
|
import os
|
||||||
|
|
||||||
|
def main():
|
||||||
|
load_dotenv() # Load environment variables from .env file
|
||||||
|
ntfy_username = os.getenv('ntfy_username')
|
||||||
|
ntfy_password = os.getenv('ntfy_password')
|
||||||
|
ntfy_host = os.getenv('ntfy_host')
|
||||||
|
ntfy_topic = os.getenv('ntfy_topic')
|
||||||
|
dc_webhook = os.getenv('dc_webhook')
|
||||||
|
dc_botname = os.getenv('dc_botname')
|
||||||
|
dc_avatar_url = os.getenv('dc_avatar_url')
|
||||||
|
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
import apprise
|
||||||
|
|
||||||
|
parser = ArgumentParser()
|
||||||
|
parser.add_argument("--title")
|
||||||
|
parser.add_argument("--body")
|
||||||
|
parser.add_argument("--click")
|
||||||
|
args = parser.parse_args()
|
||||||
|
print(args)
|
||||||
|
|
||||||
|
apobj = apprise.Apprise()
|
||||||
|
# config = apprise.AppriseConfig()
|
||||||
|
# config.add('https://myserver:8080/path/to/config')
|
||||||
|
if ntfy_host and ntfy_topic:
|
||||||
|
ntfy_link = f"ntfys://{ntfy_username}:{ntfy_password}@{ntfy_host}/{ntfy_topic}"
|
||||||
|
if args.click:
|
||||||
|
ntfy_link = ntfy_link + "?click=" + args.click
|
||||||
|
apobj.add(ntfy_link)
|
||||||
|
if dc_webhook:
|
||||||
|
apobj.add(f"discord://{dc_webhook}?avatar_url={dc_avatar_url}&botname={dc_botname}");
|
||||||
|
|
||||||
|
apobj.notify(
|
||||||
|
body=args.body,
|
||||||
|
title=args.title
|
||||||
|
)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
26
src/sendNotification.ts
Normal file
26
src/sendNotification.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
export async function sendNotification(title: string, body: string, link?: string | null) {
|
||||||
|
console.dir({
|
||||||
|
sendNotification: {
|
||||||
|
title,
|
||||||
|
body,
|
||||||
|
link
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const response = await fetch("http://apprise:8000/notify", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
urls: [
|
||||||
|
`ntfys://${process.env.ntfy_username}:${process.env.ntfy_password}@${process.env.ntfy_host}/${process.env.ntfy_topic}${ link ? `?click=${link}`: "?click=https://77th-jsoc.com/#/events" }`,
|
||||||
|
`discord://${process.env.dc_webhook}?avatar_url=${process.env.dc_avatar_url}&botname=${process.env.dc_botname}`
|
||||||
|
].join(","),
|
||||||
|
title: title,
|
||||||
|
body: body,
|
||||||
|
format: "text"
|
||||||
|
})
|
||||||
|
});
|
||||||
|
const responseBody = await response.json();
|
||||||
|
return responseBody;
|
||||||
|
}
|
||||||
16
src/sendNotificationPy.ts
Normal file
16
src/sendNotificationPy.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import * as Bun from "bun";
|
||||||
|
|
||||||
|
export async function sendNotificationPy(title: string, body: string, click?: string | null) {
|
||||||
|
const command = [
|
||||||
|
"python3",
|
||||||
|
"./src/notification.py",
|
||||||
|
`--title=${title}`,
|
||||||
|
`--body=${body}`,
|
||||||
|
];
|
||||||
|
if ( click ) {
|
||||||
|
command.push(`--click=${click}`);
|
||||||
|
}
|
||||||
|
const proc = Bun.spawn(command);
|
||||||
|
const text = await proc.stdout.text();
|
||||||
|
console.log("sendNotification: " + text);
|
||||||
|
}
|
||||||
@@ -11,3 +11,5 @@ export const db = new Database(db_filepath);
|
|||||||
export function init () {
|
export function init () {
|
||||||
Event.createTable(db);
|
Event.createTable(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init();
|
||||||
@@ -27,3 +27,15 @@ export function pad_l2 ( _thing: string | number ): string {
|
|||||||
};
|
};
|
||||||
return _thing.padStart(2, "0");
|
return _thing.padStart(2, "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getTsNow() {
|
||||||
|
const now = new Date();
|
||||||
|
const rtn = {
|
||||||
|
year: now.getFullYear(),
|
||||||
|
month: now.getMonth() + 1,
|
||||||
|
day: now.getDate(),
|
||||||
|
minute: now.getMinutes(),
|
||||||
|
seconds: now.getSeconds()
|
||||||
|
}
|
||||||
|
return rtn;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user