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
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:
@@ -1,61 +1,39 @@
|
||||
import fs from 'fs/promises'
|
||||
import path from 'path'
|
||||
import { listSpielplanSeasons, readSpielplanData } from '../utils/spielplan-data.js'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
const filePath = path.join(process.cwd(), 'public', 'data', 'spielplan.csv')
|
||||
|
||||
// Prüfe ob Datei existiert
|
||||
try {
|
||||
await fs.access(filePath)
|
||||
} catch (_error) {
|
||||
const query = getQuery(event)
|
||||
const [spielplan, seasons] = await Promise.all([
|
||||
readSpielplanData({ season: query.season }),
|
||||
listSpielplanSeasons()
|
||||
])
|
||||
|
||||
if (!spielplan.data.length || !spielplan.headers.length) {
|
||||
return {
|
||||
success: false,
|
||||
message: 'Spielplan-Datei nicht gefunden',
|
||||
data: []
|
||||
message: 'Spielplan-Datei nicht gefunden oder leer',
|
||||
data: [],
|
||||
headers: []
|
||||
}
|
||||
}
|
||||
|
||||
// CSV-Datei lesen
|
||||
const csvContent = await fs.readFile(filePath, 'utf-8')
|
||||
const lines = csvContent.split('\n').filter(line => line.trim() !== '')
|
||||
|
||||
if (lines.length < 2) {
|
||||
return {
|
||||
success: false,
|
||||
message: 'Spielplan-Datei ist leer oder unvollständig',
|
||||
data: []
|
||||
}
|
||||
}
|
||||
|
||||
// Header-Zeile parsen
|
||||
const headers = lines[0].split(';').map(header => header.trim())
|
||||
|
||||
// Datenzeilen parsen
|
||||
const data = lines.slice(1).map(line => {
|
||||
const values = line.split(';').map(value => value.trim())
|
||||
const row = {}
|
||||
|
||||
headers.forEach((header, index) => {
|
||||
row[header] = values[index] || ''
|
||||
})
|
||||
|
||||
return row
|
||||
})
|
||||
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: 'Spielplan erfolgreich geladen',
|
||||
data: data,
|
||||
headers: headers
|
||||
data: spielplan.data,
|
||||
headers: spielplan.headers,
|
||||
source: spielplan.source,
|
||||
filePath: spielplan.filePath,
|
||||
season: spielplan.season,
|
||||
seasons
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Laden des Spielplans:', error)
|
||||
return {
|
||||
success: false,
|
||||
message: 'Fehler beim Laden des Spielplans',
|
||||
data: []
|
||||
data: [],
|
||||
headers: []
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user