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,6 +1,12 @@
|
||||
import fs from 'fs/promises'
|
||||
import path from 'path'
|
||||
import { getUserFromToken, hasAnyRole } from '../../utils/auth.js'
|
||||
import {
|
||||
createSpielplanJsonFromCsv,
|
||||
getCurrentSeasonSlug,
|
||||
getSpielplanSeasonJsonPathForCsvPath,
|
||||
inferSeasonSlugFromRows
|
||||
} from '../../utils/spielplan-data.js'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
@@ -104,11 +110,20 @@ export default defineEventHandler(async (event) => {
|
||||
const uniquePaths = [...new Set([...internalPaths])]
|
||||
const writeResults = []
|
||||
const writeErrors = []
|
||||
const jsonWriteResults = []
|
||||
|
||||
for (const targetPath of uniquePaths) {
|
||||
try {
|
||||
await writeFileAtomicAndVerify(targetPath, content)
|
||||
writeResults.push(targetPath)
|
||||
if (filename === 'spielplan.csv') {
|
||||
const spielplanJson = createSpielplanJsonFromCsv(content)
|
||||
const seasonSlug = inferSeasonSlugFromRows(spielplanJson.data) || getCurrentSeasonSlug()
|
||||
const jsonContent = `${JSON.stringify(spielplanJson, null, 2)}\n`
|
||||
const jsonPath = getSpielplanSeasonJsonPathForCsvPath(targetPath, seasonSlug)
|
||||
await writeFileAtomicAndVerify(jsonPath, jsonContent)
|
||||
jsonWriteResults.push(jsonPath)
|
||||
}
|
||||
} catch (e) {
|
||||
writeErrors.push({ targetPath, error: e?.message || String(e) })
|
||||
}
|
||||
@@ -125,7 +140,8 @@ export default defineEventHandler(async (event) => {
|
||||
return {
|
||||
success: true,
|
||||
message: 'Datei erfolgreich gespeichert',
|
||||
writtenTo: writeResults
|
||||
writtenTo: writeResults,
|
||||
jsonWrittenTo: jsonWriteResults
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user