fix: several fixes
This commit is contained in:
98
scripts/test-teachers-db.js
Normal file
98
scripts/test-teachers-db.js
Normal file
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Скрипт для проверки базы данных преподавателей
|
||||
* Запуск: node scripts/test-teachers-db.js
|
||||
*/
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
// Определяем директорию базы данных
|
||||
function getDatabaseDir() {
|
||||
if (process.env.DATABASE_DIR) {
|
||||
return process.env.DATABASE_DIR;
|
||||
}
|
||||
|
||||
const cwd = process.cwd();
|
||||
console.log(`Current working directory: ${cwd}`);
|
||||
|
||||
if (cwd.includes('.next/standalone')) {
|
||||
const standaloneMatch = cwd.match(/^(.+?)\/\.next\/standalone/);
|
||||
if (standaloneMatch && standaloneMatch[1]) {
|
||||
return standaloneMatch[1];
|
||||
}
|
||||
return path.resolve(cwd, '..', '..');
|
||||
}
|
||||
|
||||
if (fs.existsSync('/opt/kspguti-schedule')) {
|
||||
return '/opt/kspguti-schedule';
|
||||
}
|
||||
|
||||
return cwd;
|
||||
}
|
||||
|
||||
const DATABASE_DIR = getDatabaseDir();
|
||||
const DB_PATH = path.join(DATABASE_DIR, 'db', 'schedule-app.db');
|
||||
|
||||
console.log(`Database directory: ${DATABASE_DIR}`);
|
||||
console.log(`Database path: ${DB_PATH}`);
|
||||
console.log(`Database exists: ${fs.existsSync(DB_PATH)}`);
|
||||
|
||||
if (!fs.existsSync(DB_PATH)) {
|
||||
console.error('Database file does not exist!');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Проверяем права доступа
|
||||
try {
|
||||
fs.accessSync(DB_PATH, fs.constants.R_OK | fs.constants.W_OK);
|
||||
console.log('Database file is readable and writable');
|
||||
} catch (err) {
|
||||
console.error('Database file permissions error:', err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Подключаемся к базе данных
|
||||
const Database = require('better-sqlite3');
|
||||
const db = new Database(DB_PATH);
|
||||
|
||||
// Проверяем таблицу teachers
|
||||
console.log('\n=== Teachers Table ===');
|
||||
const teachersCount = db.prepare('SELECT COUNT(*) as count FROM teachers').get();
|
||||
console.log(`Total teachers in database: ${teachersCount.count}`);
|
||||
|
||||
if (teachersCount.count > 0) {
|
||||
const teachers = db.prepare('SELECT id, parseId, name FROM teachers LIMIT 10').all();
|
||||
console.log('First 10 teachers:');
|
||||
teachers.forEach((t, i) => {
|
||||
console.log(` ${i + 1}. [${t.id}] ${t.name} (parseId: ${t.parseId})`);
|
||||
});
|
||||
} else {
|
||||
console.log('Teachers table is EMPTY!');
|
||||
}
|
||||
|
||||
// Проверяем таблицу groups
|
||||
console.log('\n=== Groups Table ===');
|
||||
const groupsCount = db.prepare('SELECT COUNT(*) as count FROM groups').get();
|
||||
console.log(`Total groups in database: ${groupsCount.count}`);
|
||||
|
||||
if (groupsCount.count > 0) {
|
||||
const groups = db.prepare('SELECT id, parseId, name, course FROM groups LIMIT 10').all();
|
||||
console.log('First 10 groups:');
|
||||
groups.forEach((g, i) => {
|
||||
console.log(` ${i + 1}. [${g.id}] ${g.name} (parseId: ${g.parseId}, course: ${g.course})`);
|
||||
});
|
||||
}
|
||||
|
||||
// Проверяем таблицу settings
|
||||
console.log('\n=== Settings Table ===');
|
||||
const settings = db.prepare('SELECT value FROM settings WHERE key = ?').get('app');
|
||||
if (settings) {
|
||||
console.log('App settings:', settings.value);
|
||||
} else {
|
||||
console.log('No app settings found');
|
||||
}
|
||||
|
||||
db.close();
|
||||
console.log('\nDone!');
|
||||
76
scripts/test-teachers-parser.js
Normal file
76
scripts/test-teachers-parser.js
Normal file
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Тест парсера преподавателей
|
||||
* Запуск: node scripts/test-teachers-parser.js
|
||||
*/
|
||||
|
||||
const { JSDOM } = require('jsdom');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
// Импортируем парсер
|
||||
const { parseTeachersList } = require('./src/app/parser/teachers-list');
|
||||
|
||||
// HTML с сервера (сохраните в файл или передайте через аргумент)
|
||||
const testHtml = `
|
||||
<html>
|
||||
<body>
|
||||
<table border="0" cellpadding="1" cellspacing="1" width="100%" bgcolor="ffffff">
|
||||
<tr><td bgcolor='eeeeee' align=center><a href='?mn=3&obj=3'><b>Абалымова Людмила Павловна</b></a></td></tr>
|
||||
<tr><td bgcolor='dddddd' align=center><a href='?mn=3&obj=4'><b>Абрамова Светлана Геннадьевна</b></a></td></tr>
|
||||
<tr><td bgcolor='eeeeee' align=center><a href='?mn=3&obj=253'><b>Айриянц Илона Артуровна</b></a></td></tr>
|
||||
<tr><td bgcolor='dddddd' align=center><a href='?mn=3&obj=2'><b>Алёхин Иван Николаевич</b></a></td></tr>
|
||||
<tr><td bgcolor='eeeeee' align=center><a href='?mn=3&obj=65'><b>Андреевская Наталья Владимировна</b></a></td></tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
|
||||
console.log('=== Testing Teachers Parser ===\n');
|
||||
|
||||
// Создаём JSDOM
|
||||
const dom = new JSDOM(testHtml, { url: 'https://lk.ks.psuti.ru/?mn=3' });
|
||||
const document = dom.window.document;
|
||||
|
||||
// Проверяем, находит ли селектор ссылки
|
||||
const links = Array.from(document.querySelectorAll('a[href*="?mn=3&obj="], a[href*="mn=3&obj="]'));
|
||||
console.log(`Links found by selector: ${links.length}`);
|
||||
links.forEach((link, i) => {
|
||||
console.log(` ${i + 1}. href="${link.getAttribute('href')}", text="${link.textContent?.trim()}"`);
|
||||
});
|
||||
|
||||
// Запускаем парсер
|
||||
const teachers = parseTeachersList(document);
|
||||
console.log(`\nTeachers parsed: ${teachers.length}`);
|
||||
teachers.forEach((t, i) => {
|
||||
console.log(` ${i + 1}. [${t.parseId}] ${t.name}`);
|
||||
});
|
||||
|
||||
dom.window.close();
|
||||
|
||||
// Теперь тестируем на реальном HTML с сервера
|
||||
console.log('\n\n=== Testing with Real HTML from Server ===\n');
|
||||
|
||||
const realHtmlPath = path.join(__dirname, 'teachers-test.html');
|
||||
if (fs.existsSync(realHtmlPath)) {
|
||||
const realHtml = fs.readFileSync(realHtmlPath, 'utf8');
|
||||
const realDom = new JSDOM(realHtml, { url: 'https://lk.ks.psuti.ru/?mn=3' });
|
||||
const realDocument = realDom.window.document;
|
||||
|
||||
const realTeachers = parseTeachersList(realDocument);
|
||||
console.log(`Real teachers parsed: ${realTeachers.length}`);
|
||||
realTeachers.slice(0, 10).forEach((t, i) => {
|
||||
console.log(` ${i + 1}. [${t.parseId}] ${t.name}`);
|
||||
});
|
||||
|
||||
if (realTeachers.length > 10) {
|
||||
console.log(` ... and ${realTeachers.length - 10} more`);
|
||||
}
|
||||
|
||||
realDom.window.close();
|
||||
} else {
|
||||
console.log(`Test file not found: ${realHtmlPath}`);
|
||||
console.log('To test with real HTML, save the curl output to scripts/teachers-test.html');
|
||||
console.log('Example: curl -L "https://lk.ks.psuti.ru/?mn=3" > scripts/teachers-test.html');
|
||||
}
|
||||
Reference in New Issue
Block a user