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
+ }
0 commit comments