Skip to content

Commit 913f2ac

Browse files
committed
Added screen scraper for auction data
1 parent d7d5549 commit 913f2ac

File tree

9 files changed

+1324
-8394
lines changed

9 files changed

+1324
-8394
lines changed

eng.traineddata

22.4 MB
Binary file not shown.

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"scripts": {
88
"test": "echo \"Error: no test specified\" && exit 1",
99
"start": "node src/index.js",
10+
"scrape": "node src/scrape.js",
1011
"start:watch": "nodemon src/index.js"
1112
},
1213
"repository": {
@@ -20,6 +21,14 @@
2021
},
2122
"homepage": "https://github.com/Clonex/lost-ark-calculator#readme",
2223
"dependencies": {
24+
"clipboardy": "^3.0.0",
25+
"jimp": "^0.16.1",
26+
"node-tesseract-ocr": "^2.2.1",
27+
"robotjs": "^0.6.0",
28+
"screenshot-desktop": "^1.12.7",
29+
"tesseract.js": "^2.1.5"
30+
},
31+
"devDependencies": {
2332
"nodemon": "^2.0.15"
2433
}
2534
}

src/AuctionExctractor.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import robot from "robotjs";
2+
import clipboard from "clipboardy";
3+
4+
import { createWorker } from 'tesseract.js';
5+
import {captureImage, wait} from "./helpers.js";
6+
7+
8+
export default class AuctionExtractor {
9+
SEARCH_POS = {x: 1551, y: 243};
10+
LOADING_POS = {x: 1060, y: 447};
11+
PRICE_POS = {x: 1082, y: 312};
12+
13+
LOADING_COLOR = "101114";
14+
15+
_worker;
16+
constructor()
17+
{
18+
// this.getPrice("Elemental HP potion");
19+
this._worker = createWorker({
20+
logger: m => {}
21+
});
22+
}
23+
24+
async start(items)
25+
{
26+
let out = {};
27+
28+
const names = Object.keys(items);
29+
for(let i = 0; i < 5; i++) //names.length
30+
{
31+
const name = names[i];
32+
out[name] = await this.getPrice(name);
33+
console.log(`[${i}/${names.length}]`, "Got price for", name, "=", out[name]);
34+
}
35+
36+
return out;
37+
// const test = await this.getPrice("Strong Iron Ore");
38+
// console.log("Got something", test);
39+
}
40+
41+
async getPrice(itemName)
42+
{
43+
await clipboard.write(itemName);
44+
await wait(10);
45+
// To search bar and search
46+
robot.moveMouse(this.SEARCH_POS.x, this.SEARCH_POS.y);
47+
robot.mouseClick();
48+
49+
robot.moveMouse(this.SEARCH_POS.x - 100, this.SEARCH_POS.y);
50+
robot.mouseClick();
51+
// await clipboard.read();
52+
robot.keyTap('v', 'control');
53+
54+
// robot.typeStringDelayed(itemName, 99999999999999);
55+
robot.keyTap("enter");
56+
57+
// Wait for search results
58+
await wait(120);
59+
while(robot.getPixelColor(this.LOADING_POS.x, this.LOADING_POS.y) === this.LOADING_COLOR)
60+
{
61+
await wait(100);
62+
}
63+
64+
const price = await captureImage(this.PRICE_POS.x, this.PRICE_POS.y, 123, 39, itemName);
65+
66+
67+
await this._worker.load();
68+
await this._worker.loadLanguage('eng');
69+
await this._worker.initialize('eng');
70+
await this._worker.setParameters({
71+
tessedit_char_whitelist: '0123456789.',
72+
});
73+
const { data: { text } } = await this._worker.recognize(price);
74+
return text.length > 0 ? Number(text.trim()) : false;
75+
}
76+
}

src/data/prices.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)