Cleanup
This commit is contained in:
parent
1d32171e21
commit
1d1a9ef3a0
2 changed files with 0 additions and 5 deletions
Binary file not shown.
|
|
@ -11,18 +11,15 @@ const server = createServer((req, res) => {
|
|||
req.on("data", chunk => (body += chunk));
|
||||
|
||||
req.on("end", async () => {
|
||||
// 1️⃣ HTML parsen
|
||||
const $ = cheerio.load(body);
|
||||
const items = $(".item").map((i, el) => $(el).text()).get();
|
||||
|
||||
const results = [];
|
||||
|
||||
// 2️⃣ Redis abfragen (Set pro Item)
|
||||
for (const item of items) {
|
||||
const setMembers = await redis.sMembers(`item:${item}`);
|
||||
|
||||
if (setMembers.length === 2) {
|
||||
// Angenommen: [verkaufspreis, realwert]
|
||||
const [verkaufspreisStr, realwertStr] = setMembers;
|
||||
const verkaufspreis = parseInt(verkaufspreisStr, 10);
|
||||
const realwert = parseInt(realwertStr, 10);
|
||||
|
|
@ -31,11 +28,9 @@ const server = createServer((req, res) => {
|
|||
}
|
||||
}
|
||||
|
||||
// 3️⃣ Sortieren & Top 5
|
||||
const topVerkaufspreis = [...results].sort((a, b) => b.verkaufspreis - a.verkaufspreis).slice(0, 5);
|
||||
const topRealwert = [...results].sort((a, b) => b.realwert - a.realwert).slice(0, 5);
|
||||
|
||||
// 4️⃣ JSON-Antwort
|
||||
res.writeHead(200, { "Content-Type": "application/json" });
|
||||
res.end(JSON.stringify({ topVerkaufspreis, topRealwert }, null, 2));
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue