@@ -27,6 +27,8 @@ const Utils = require('../util/utils.js');
27
27
28
28
/* Constants */
29
29
30
+ const SLEEP_TIMEOUT_MS = 2000 ;
31
+
30
32
const RUSTLABS_ALL_ITEMS_URL = 'https://rustlabs.com/group=itemlist' ;
31
33
const RUSTLABS_ITEM_URL = 'https://rustlabs.com/item/' ;
32
34
@@ -77,6 +79,10 @@ const RUSTLABS_ITEM_SMELTING_REGEX1 =
77
79
/ < a \s h r e f = " \/ i t e m \/ ( \n | .) * ?i m g \/ .* ?\/ ( .* ?) \. p n g " \s a l t = " ( .* ?) " ( \n | .) * ?< \/ a > < a \s h r e f = " \/ i t e m \/ ( \n | .) * ?i m g \/ .* ?\/ w o o d \. p n g " ( \n | .) * ?t e x t - i n - i c o n " > ( .* ?) < \/ s p a n ( \n | .) * ?< a \s h r e f = " \/ i t e m \/ ( \n | .) * ?i m g \/ .* ?\/ ( .* ?) \. p n g " \s a l t = " ( .* ?) " ( \n | .) * ?t e x t - i n - i c o n " > ( .* ?) < ( \n | .) * ?< t d > ( .* ?s e c | .* ?m i n ) < / gm
78
80
const RUSTLABS_ITEM_SMELTING_REGEX2 = / < a \s h r e f = " \/ i t e m \/ ( \n | .) * ?i m g \/ .* ?\/ ( .* ?) \. p n g " \s a l t = " ( .* ?) " ( \n | .) * ?< a \s h r e f = " \/ i t e m \/ ( \n | .) * ?i m g \/ .* ?\/ ( .* ?) \. p n g " \s a l t = " ( .* ?) " ( \n | .) * ?t e x t - i n - i c o n " > ( .* ?) < \/ s p a n ( \n | .) * ?< t d > ( .* ?s e c | .* ?m i n ) < / gm
79
81
82
+ const RUSTLABS_ITEM_DESPAWN_REGEX = / < t d > D e s p a w n \s t i m e < \/ t d > ( \n | .) * ?< t d > ( .* ?) < \/ t d > / gm
83
+
84
+ const RUSTLABS_ITEM_STACK_REGEX = / < t d > S t a c k \s S i z e < \/ t d > ( \n | .) * ?< t d > ( .* ?) < \/ t d > / gm
85
+
80
86
const RUSTLABS_ALL_BUILDING_BLOCKS_REGEX = / \/ b u i l d i n g \/ ( .* ?) " > ( .* ?) < / gm
81
87
82
88
const RUSTLABS_ALL_OTHER_REGEX = / \/ e n t i t y \/ ( .* ?) " > ( .* ?) < / gm
@@ -93,6 +99,8 @@ rustlabsDurabilityData['items'] = new Object();
93
99
rustlabsDurabilityData [ 'buildingBlocks' ] = new Object ( ) ;
94
100
rustlabsDurabilityData [ 'other' ] = new Object ( ) ;
95
101
const rustlabsSmeltingData = new Object ( ) ;
102
+ const rustlabsDespawnData = new Object ( ) ;
103
+ const rustlabsStackData = new Object ( ) ;
96
104
97
105
async function scrape ( url ) {
98
106
try {
@@ -200,10 +208,10 @@ async function processAllItems() {
200
208
processItemRecycle ( rustlabsName , shortname , name , data ) ;
201
209
processItemDurability ( rustlabsName , shortname , name , data ) ;
202
210
processItemSmelting ( rustlabsName , shortname , name , data ) ;
203
- // Despawn time item?
204
- // stack size?
211
+ processItemDespawn ( rustlabsName , shortname , name , data ) ;
212
+ processItemStack ( rustlabsName , shortname , name , data ) ;
205
213
206
- await sleep ( 2000 ) ;
214
+ await sleep ( SLEEP_TIMEOUT_MS ) ;
207
215
}
208
216
}
209
217
@@ -246,7 +254,7 @@ async function processAllBuildingBlocks() {
246
254
247
255
processItemDurability ( rustlabsName , null , name , data , 'buildingBlocks' ) ;
248
256
249
- await sleep ( 2000 ) ;
257
+ await sleep ( SLEEP_TIMEOUT_MS ) ;
250
258
}
251
259
}
252
260
@@ -286,7 +294,7 @@ async function processAllOther() {
286
294
287
295
processItemDurability ( rustlabsName , null , name , data , 'other' ) ;
288
296
289
- await sleep ( 2000 ) ;
297
+ await sleep ( SLEEP_TIMEOUT_MS ) ;
290
298
}
291
299
}
292
300
@@ -735,6 +743,52 @@ function processItemSmelting(rustlabsName, shortname, name, data) {
735
743
rustlabsSmeltingData [ itemId ] = content ;
736
744
}
737
745
746
+ function processItemDespawn ( rustlabsName , shortname , name , data ) {
747
+ const itemId = Object . keys ( ITEMS ) . find ( e => ITEMS [ e ] . shortname === shortname && ITEMS [ e ] . name === name ) ;
748
+ if ( ! itemId ) return ;
749
+
750
+ let matches = [ ...data . matchAll ( RUSTLABS_ITEM_DESPAWN_REGEX ) ] ;
751
+ if ( matches . length !== 1 ) {
752
+ console . log ( ' - No despawn data found.' ) ;
753
+ return ;
754
+ }
755
+
756
+ matches = matches [ 0 ] ;
757
+ if ( matches . length !== 3 ) {
758
+ console . log ( ' - No despawn data found.' ) ;
759
+ return ;
760
+ }
761
+
762
+ const string = matches [ 2 ] . trim ( ) ;
763
+ const seconds = parseTime ( string ) ;
764
+
765
+ rustlabsDespawnData [ itemId ] = new Object ( ) ;
766
+ rustlabsDespawnData [ itemId ] [ "time" ] = seconds ;
767
+ rustlabsDespawnData [ itemId ] [ "timeString" ] = string ;
768
+ }
769
+
770
+ function processItemStack ( rustlabsName , shortname , name , data ) {
771
+ const itemId = Object . keys ( ITEMS ) . find ( e => ITEMS [ e ] . shortname === shortname && ITEMS [ e ] . name === name ) ;
772
+ if ( ! itemId ) return ;
773
+
774
+ let matches = [ ...data . matchAll ( RUSTLABS_ITEM_STACK_REGEX ) ] ;
775
+ if ( matches . length !== 1 ) {
776
+ console . log ( ' - No stack data found.' ) ;
777
+ return ;
778
+ }
779
+
780
+ matches = matches [ 0 ] ;
781
+ if ( matches . length !== 3 ) {
782
+ console . log ( ' - No stack data found.' ) ;
783
+ return ;
784
+ }
785
+
786
+ const quantity = matches [ 2 ] . trim ( ) . replace ( '×' , '' ) . replace ( / , / g, '' ) ;
787
+
788
+ rustlabsStackData [ itemId ] = new Object ( ) ;
789
+ rustlabsStackData [ itemId ] [ "quantity" ] = quantity ;
790
+ }
791
+
738
792
async function main ( ) {
739
793
await processAll ( ) ;
740
794
@@ -744,6 +798,8 @@ async function main() {
744
798
Fs . writeFileSync ( `${ __dirname } /rustlabsRecycleData.json` , JSON . stringify ( rustlabsRecycleData , null , 2 ) ) ;
745
799
Fs . writeFileSync ( `${ __dirname } /rustlabsDurabilityData.json` , JSON . stringify ( rustlabsDurabilityData , null , 2 ) ) ;
746
800
Fs . writeFileSync ( `${ __dirname } /rustlabsSmeltingData.json` , JSON . stringify ( rustlabsSmeltingData , null , 2 ) ) ;
801
+ Fs . writeFileSync ( `${ __dirname } /rustlabsDespawnData.json` , JSON . stringify ( rustlabsDespawnData , null , 2 ) ) ;
802
+ Fs . writeFileSync ( `${ __dirname } /rustlabsStackData.json` , JSON . stringify ( rustlabsStackData , null , 2 ) ) ;
747
803
}
748
804
749
805
main ( ) ;
0 commit comments