Add script for importing match schedule and logging
Some checks failed
Code Analysis and Production Deploy / analyze (push) Has been skipped
Code Analysis and Production Deploy / deploy-production (push) Has been skipped
Code Analysis and Production Deploy / deploy-test (push) Successful in 2m2s
Code Analysis and Production Deploy / analyze (pull_request) Failing after 33s
Code Analysis and Production Deploy / deploy-production (pull_request) Has been skipped
Code Analysis and Production Deploy / deploy-test (pull_request) Has been skipped
Require Package Version Change / check (pull_request) Failing after 10s

- Created `import-spielplan.js` to fetch and parse the match schedule from the specified URL, saving the output as JSON.
- Added `run-spielplan-import.sh` to automate the execution of the import script and log output.
- Introduced `spielplan.html` file to store the downloaded HTML content for further processing.
This commit is contained in:
Torsten Schulz (local)
2026-05-19 16:23:28 +02:00
parent c78adc0d52
commit 0849c625cb
21 changed files with 11413 additions and 233 deletions

View File

@@ -1,5 +1,6 @@
import fs from 'fs/promises'
import path from 'path'
import { readSpielplanData } from '../../utils/spielplan-data.js'
export default defineEventHandler(async (event) => {
try {
@@ -13,56 +14,15 @@ export default defineEventHandler(async (event) => {
})
}
// Lade Spielplandaten - bevorzugt aus server/data
let csvPath = path.join(process.cwd(), 'server/data/spielplan.csv')
try {
await fs.access(csvPath)
} catch {
csvPath = path.join(process.cwd(), 'public/data/spielplan.csv')
}
let csvContent
try {
csvContent = await fs.readFile(csvPath, 'utf-8')
} catch (_error) {
const spielplan = await readSpielplanData({ season: query.season })
if (!spielplan.data.length || !spielplan.headers.length) {
throw createError({
statusCode: 404,
statusMessage: 'Spielplandaten nicht gefunden'
})
}
// Parse CSV
const lines = csvContent.split('\n').filter(line => line.trim())
if (lines.length < 2) {
throw createError({
statusCode: 400,
statusMessage: 'Keine Spielplandaten verfügbar'
})
}
// Automatische Erkennung des Trennzeichens
const firstLine = lines[0]
const tabCount = (firstLine.match(/\t/g) || []).length
const semicolonCount = (firstLine.match(/;/g) || []).length
const delimiter = tabCount > semicolonCount ? '\t' : ';'
// nosemgrep: javascript.lang.security.audit.unsafe-formatstring.unsafe-formatstring
console.log(`Verwendetes Trennzeichen: ${delimiter === '\t' ? 'Tab' : 'Semikolon'}`)
const headers = firstLine.split(delimiter)
console.log('CSV-Header:', headers)
const dataRows = lines.slice(1).map(line => {
const values = line.split(delimiter)
const row = {}
headers.forEach((header, index) => {
row[header] = values[index] || ''
})
return row
})
console.log('Anzahl Datenzeilen:', dataRows.length)
console.log('Erste Datenzeile:', dataRows[0])
const dataRows = spielplan.data
// Filtere Daten basierend auf Team
let filteredData = dataRows
@@ -175,33 +135,6 @@ export default defineEventHandler(async (event) => {
})
}
// Filtere nach aktueller Saison (2025/26)
const currentSaisonStart = new Date(2025, 6, 1) // 01.07.2025
const currentSaisonEnd = new Date(2026, 5, 30) // 30.06.2026
filteredData = filteredData.filter(row => {
const termin = row.Termin
if (!termin) return false
try {
let spielDatum
if (termin.includes(' ')) {
const datumTeil = termin.split(' ')[0]
const [tag, monat, jahr] = datumTeil.split('.')
spielDatum = new Date(jahr, monat - 1, tag)
} else {
spielDatum = new Date(termin)
}
if (isNaN(spielDatum.getTime())) return false
return spielDatum >= currentSaisonStart && spielDatum <= currentSaisonEnd
} catch (_error) {
return false
}
})
// Sammle Halle-Informationen für die jeweilige Mannschaft
const hallenMap = new Map()

View File

@@ -0,0 +1,24 @@
import { getCurrentSeasonSlug, listSpielplanSeasons } from '../../utils/spielplan-data.js'
export default defineEventHandler(async () => {
try {
const seasons = await listSpielplanSeasons()
const currentSeason = getCurrentSeasonSlug()
const defaultSeason = seasons.find((season) => season.slug === currentSeason)?.slug || seasons[0]?.slug || null
return {
success: true,
seasons,
currentSeason,
defaultSeason
}
} catch (error) {
console.error('Fehler beim Laden der Spielplan-Saisons:', error)
return {
success: false,
seasons: [],
currentSeason: getCurrentSeasonSlug(),
defaultSeason: null
}
}
})