Add silent config option to suppress stdout output
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,7 @@ export interface TelegramConfig {
|
|||||||
export interface Config {
|
export interface Config {
|
||||||
days: DayUrls
|
days: DayUrls
|
||||||
devMode: boolean
|
devMode: boolean
|
||||||
|
silent: boolean
|
||||||
overrideTime: string | null
|
overrideTime: string | null
|
||||||
telegram: TelegramConfig
|
telegram: TelegramConfig
|
||||||
}
|
}
|
||||||
@@ -27,6 +28,7 @@ const config: Config = {
|
|||||||
friday: "",
|
friday: "",
|
||||||
},
|
},
|
||||||
devMode: false,
|
devMode: false,
|
||||||
|
silent: false,
|
||||||
overrideTime: null,
|
overrideTime: null,
|
||||||
telegram: {
|
telegram: {
|
||||||
botToken: "",
|
botToken: "",
|
||||||
|
|||||||
+10
-6
@@ -53,26 +53,30 @@ function formatMenu(menu: ParsedMenu): string {
|
|||||||
return lines.join("\n")
|
return lines.join("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function log(msg: string): void {
|
||||||
|
if (!config.silent) console.log(msg)
|
||||||
|
}
|
||||||
|
|
||||||
async function tg(text: string): Promise<void> {
|
async function tg(text: string): Promise<void> {
|
||||||
if (!config.telegram.botToken || !config.telegram.chatId) {
|
if (!config.telegram.botToken || !config.telegram.chatId) {
|
||||||
console.log(`TG (not configured): ${text}`)
|
console.log(`TG (not configured): ${text}`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
await sendMessage(config.telegram.botToken, config.telegram.chatId, text)
|
await sendMessage(config.telegram.botToken, config.telegram.chatId, text)
|
||||||
console.log(`TG sent: ${text.slice(0, 80)}${text.length > 80 ? "…" : ""}`)
|
log(`TG sent: ${text.slice(0, 80)}${text.length > 80 ? "…" : ""}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const { totalMinutes, dateStr } = getCurrentTime()
|
const { totalMinutes, dateStr } = getCurrentTime()
|
||||||
|
|
||||||
if (totalMinutes >= 14 * 60) {
|
if (totalMinutes >= 14 * 60) {
|
||||||
console.log("After 14:00, exiting.")
|
log("After 14:00, exiting.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const weekday = todayWeekday()
|
const weekday = todayWeekday()
|
||||||
if (!weekday) {
|
if (!weekday) {
|
||||||
console.log("Weekend, exiting.")
|
log("Weekend, exiting.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +93,7 @@ async function main() {
|
|||||||
const availability = checkAvailability(body)
|
const availability = checkAvailability(body)
|
||||||
|
|
||||||
if (!availability.available) {
|
if (!availability.available) {
|
||||||
console.log(`Menu not available: ${availability.reason}`)
|
log(`Menu not available: ${availability.reason}`)
|
||||||
if (isAfter10 && !state.sentAt10) {
|
if (isAfter10 && !state.sentAt10) {
|
||||||
await tg("Dnes menu není k dispozici.")
|
await tg("Dnes menu není k dispozici.")
|
||||||
state.sentAt10 = true
|
state.sentAt10 = true
|
||||||
@@ -109,7 +113,7 @@ async function main() {
|
|||||||
state.sentAt10 = true
|
state.sentAt10 = true
|
||||||
}
|
}
|
||||||
await saveState(state)
|
await saveState(state)
|
||||||
console.log("First run, reference saved.")
|
log("First run, reference saved.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +123,7 @@ async function main() {
|
|||||||
|
|
||||||
// Log text changes (always)
|
// Log text changes (always)
|
||||||
for (const change of diff.textChanges) {
|
for (const change of diff.textChanges) {
|
||||||
await logChange(dateStr, formatTextChange(change))
|
await logChange(dateStr, formatTextChange(change), config.silent)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAfter10) {
|
if (isAfter10) {
|
||||||
|
|||||||
+2
-2
@@ -3,10 +3,10 @@ import path from "path"
|
|||||||
|
|
||||||
const LOGS_DIR = "logs"
|
const LOGS_DIR = "logs"
|
||||||
|
|
||||||
export async function logChange(date: string, message: string): Promise<void> {
|
export async function logChange(date: string, message: string, silent = false): Promise<void> {
|
||||||
await fs.mkdir(LOGS_DIR, { recursive: true })
|
await fs.mkdir(LOGS_DIR, { recursive: true })
|
||||||
const file = path.join(LOGS_DIR, `${date}.log`)
|
const file = path.join(LOGS_DIR, `${date}.log`)
|
||||||
const time = new Date().toTimeString().slice(0, 8)
|
const time = new Date().toTimeString().slice(0, 8)
|
||||||
await fs.appendFile(file, `[${time}] ${message}\n`)
|
await fs.appendFile(file, `[${time}] ${message}\n`)
|
||||||
console.log(`LOG: ${message}`)
|
if (!silent) console.log(`LOG: ${message}`)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user