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