Repository navigation
Expand file tree
/
Copy pathgenerateSummary.js
More file actions
174 lines (157 loc) · 5.79 KB
/
Copy pathgenerateSummary.js
File metadata and controls
174 lines (157 loc) · 5.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
const fs = require("fs");
const path = require("path");
const inputDir = path.join(__dirname, "json_outputs");
const outputFile = path.join(__dirname, "summary.csv");
const ipsFile = path.join(__dirname, "ips.txt"); // ips.txt dosya yolu
// IP-Birim eşleştirmelerini oku
const ipToBirim = {};
try {
const ipsContent = fs.readFileSync(ipsFile, "utf-8");
ipsContent.split("\n").forEach((line) => {
if (line.trim() === "") return;
const [ip, birim] = line.split(" - ").map((item) => item.trim());
if (ip && birim) {
ipToBirim[ip] = birim;
}
});
} catch (err) {
console.warn(
"⚠️ ips.txt dosyası okunamadı, birim bilgileri atlanacak:",
err.message
);
}
let output =
"Birim,IP,Son Güncelleme Tarihi,Siyah Kartuş %,Mavi Kartuş %,Kırmızı Kartuş %,Sarı Kartuş %,Siyah Fotokondüktör %,Mavi Fotokondüktör %,Kırmızı Fotokondüktör %,Sarı Fotokondüktör %,Isıtıcı Kiti %,Bakım Kiti %,Seri Numarası\n";
let toplamYazici = 0;
const files = fs.readdirSync(inputDir).filter((f) => f.endsWith(".json"));
for (const file of files) {
const filePath = path.join(inputDir, file);
const ip = file.replace(".json", "").replace(/_/g, ".");
try {
// Dosya istatistiklerini al
const stats = fs.statSync(filePath);
const lastModified = new Date(stats.mtime);
// TR zaman diliminde formatla
const formattedDate = lastModified
.toLocaleString("tr-TR", {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
hour12: false,
timeZone: "Europe/Istanbul",
})
.replace(/\s/g, " ")
.replace(",", "");
const data = JSON.parse(fs.readFileSync(filePath, "utf8"));
const supplies = data?.nodes?.supplies;
if (!supplies) {
console.warn(`⚠️ ${file}: supplies bilgisi bulunamadı.`);
continue;
}
let printerData = {
birim: ipToBirim[ip] || "BİRİM BULUNAMADI", // ips.txt'den birim bilgisini al
ip: ip,
lastModified: formattedDate, // Tarih bilgisini ekle
black: "",
cyan: "",
magenta: "",
yellow: "",
blackPhotoconductor: "",
cyanPhotoconductor: "",
magentaPhotoconductor: "",
yellowPhotoconductor: "",
fuserKit: "",
maintenanceKit: "",
serial: "",
};
for (const key in supplies) {
const item = supplies[key];
const color = item?.color || item?.supplyName || key;
const percent = item?.percentFull;
const serialNumber = item?.serialNumber?.trim() || "Bilinmiyor";
//emekten selamlar
// Siyah kartuş için özel olarak "Black Toner" anahtarını ara
if (supplies["Black Toner"]) {
const blackObj = supplies["Black Toner"];
printerData.black =
blackObj.percentFull !== undefined
? blackObj.percentFull
: blackObj.curlevel !== undefined
? blackObj.curlevel
: "";
printerData.serial = blackObj.serialNumber?.trim() || "Bilinmiyor";
}
if (color && percent !== undefined) {
if (color.toLowerCase().includes("cyan")) {
printerData.cyan = percent;
} else if (color.toLowerCase().includes("magenta")) {
printerData.magenta = percent;
} else if (color.toLowerCase().includes("yellow")) {
printerData.yellow = percent;
}
}
// Fotokondüktör bilgilerini çıkar
if (key === "Black Photoconductor") {
printerData.blackPhotoconductor =
item.percentFull !== undefined
? item.percentFull
: item.curlevel !== undefined
? item.curlevel
: "";
} else if (key === "Cyan Photoconductor") {
printerData.cyanPhotoconductor =
item.percentFull !== undefined
? item.percentFull
: item.curlevel !== undefined
? item.curlevel
: "";
} else if (key === "Magenta Photoconductor") {
printerData.magentaPhotoconductor =
item.percentFull !== undefined
? item.percentFull
: item.curlevel !== undefined
? item.curlevel
: "";
} else if (key === "Yellow Photoconductor") {
printerData.yellowPhotoconductor =
item.percentFull !== undefined
? item.percentFull
: item.curlevel !== undefined
? item.curlevel
: "";
}
// Kit bilgilerini çıkar
if (key === "Fuser Kit") {
printerData.fuserKit =
item.percentFull !== undefined
? item.percentFull
: item.curlevel !== undefined
? item.curlevel
: "";
} else if (
key === "Maintenance Kit" ||
key === "200K HCF Maintenance Kit" ||
key === "200K MPF Maintenance Kit" ||
key === "300K Maintenance Kit"
) {
printerData.maintenanceKit =
item.percentFull !== undefined
? item.percentFull
: item.curlevel !== undefined
? item.curlevel
: "";
}
}
//Birim belirleme kodu ipden çekilmiyor. ips.txt dosyasından çekiliyor bu kısımı sildim -Emek
output += `${printerData.birim},${printerData.ip},${printerData.lastModified},${printerData.black},${printerData.cyan},${printerData.magenta},${printerData.yellow},${printerData.blackPhotoconductor},${printerData.cyanPhotoconductor},${printerData.magentaPhotoconductor},${printerData.yellowPhotoconductor},${printerData.fuserKit},${printerData.maintenanceKit},${printerData.serial}\n`;
toplamYazici++;
} catch (err) {
console.warn(`❌ ${file} okunamadı: ${err.message}`);
}
}
fs.writeFileSync(outputFile, output, "utf8");
console.log(`✔ summary.csv oluşturuldu!`);
console.log(`📊 Toplam yazıcı: ${toplamYazici}`);