rasskazhi-o-sebe-kto-ty-chto/import-servers.js
2026-09-10 08:44:33 +00:00

73 lines
2.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const fs = require('fs');
const path = require('path');
// Чтение файла
const content = fs.readFileSync(path.join(__dirname, 'список серверов.txt'), 'utf8');
const lines = content.trim().split('\n');
const header = lines[0].split('\t');
const rows = lines.slice(1).map(line => {
const cols = line.split('\t');
return {
admin: cols[0],
city: cols[1],
region: cols[2],
ip: cols[3],
cityCode: cols[4]
};
});
// Чтение текущих данных
const dataPath = path.join(__dirname, 'data.json');
let data = JSON.parse(fs.readFileSync(dataPath, 'utf8'));
// Уникальные админы
const adminMap = new Map();
rows.forEach(row => {
if (!adminMap.has(row.admin)) {
adminMap.set(row.admin, {
name: row.admin,
position: '',
phone: '',
email: ''
});
}
});
// Добавляем новых админов
const existingAdmins = new Set(data.admins.map(a => a.name));
const newAdmins = [];
adminMap.forEach((admin, name) => {
if (!existingAdmins.has(name)) {
newAdmins.push({
id: Date.now() + Math.random(),
...admin
});
console.log('Добавлен админ:', name);
}
});
data.admins = [...data.admins, ...newAdmins];
// Добавляем серверы (уникальные по IP)
const existingIps = new Set(data.servers.map(s => s.ip));
const newServers = [];
rows.forEach(row => {
if (!existingIps.has(row.ip)) {
newServers.push({
id: Date.now() + Math.random(),
admin: row.admin,
city: row.city,
region: row.region,
cityCode: row.cityCode,
ip: row.ip
});
console.log('Добавлен сервер:', row.city, row.ip);
}
});
data.servers = [...data.servers, ...newServers];
// Сохранение
fs.writeFileSync(dataPath, JSON.stringify(data, null, 2));
console.log('\nГотово!');
console.log('Добавлено админов:', newAdmins.length);
console.log('Добавлено серверов:', newServers.length);