triangle-utils 1.4.5 → 1.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/UtilsBee.js +13 -16
- package/dist/src/UtilsMisc.d.ts +1 -1
- package/dist/src/UtilsMisc.js +3 -3
- package/package.json +1 -1
- package/src/UtilsBee.ts +13 -16
- package/src/UtilsMisc.ts +3 -3
package/dist/src/UtilsBee.js
CHANGED
|
@@ -10,25 +10,22 @@ export class UtilsBee {
|
|
|
10
10
|
if (this.bee === undefined) {
|
|
11
11
|
return undefined;
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return response.data;
|
|
21
|
-
}
|
|
22
|
-
return undefined;
|
|
13
|
+
try {
|
|
14
|
+
const response = await this.bee.htmlApi({
|
|
15
|
+
url: url,
|
|
16
|
+
params: params
|
|
17
|
+
});
|
|
18
|
+
if (response.data instanceof Buffer) {
|
|
19
|
+
return response.data;
|
|
23
20
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
console.log(
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
if (error instanceof Error) {
|
|
25
|
+
console.log(error.stack);
|
|
29
26
|
}
|
|
27
|
+
console.log("Failed to get from Scraping Bee.");
|
|
30
28
|
}
|
|
31
|
-
console.log("Failed to get from Scraping Bee, quitting.");
|
|
32
29
|
return undefined;
|
|
33
30
|
}
|
|
34
31
|
async get(url, params = {}) {
|
package/dist/src/UtilsMisc.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare class UtilsMisc {
|
|
|
11
11
|
send_email(recipient: string, subject: string, text: string): Promise<boolean>;
|
|
12
12
|
admin_alert(text: string): Promise<boolean>;
|
|
13
13
|
safe_run(f: () => Promise<any>): Promise<void>;
|
|
14
|
-
iterate<T>(inputs: T[], f: (input: T) => Promise<any>,
|
|
14
|
+
iterate<T>(inputs: T[], f: (input: T, index: number) => Promise<any>, num_iterators?: number, print_indices?: boolean): Promise<void>;
|
|
15
15
|
static wait(duration: number): Promise<unknown>;
|
|
16
16
|
static get_current_time(): string;
|
|
17
17
|
static get_current_milliseconds(): number;
|
package/dist/src/UtilsMisc.js
CHANGED
|
@@ -58,17 +58,17 @@ export class UtilsMisc {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
async iterate(inputs, f,
|
|
61
|
+
async iterate(inputs, f, num_iterators = 1, print_indices = false) {
|
|
62
62
|
let index = 0;
|
|
63
63
|
let iterators = [];
|
|
64
|
-
for (let i = 0; i <
|
|
64
|
+
for (let i = 0; i < num_iterators; i++) {
|
|
65
65
|
iterators.push((async () => {
|
|
66
66
|
while (index < inputs.length) {
|
|
67
67
|
index += 1;
|
|
68
68
|
if (print_indices) {
|
|
69
69
|
console.log(i + ":" + (index - 1) + "/" + inputs.length);
|
|
70
70
|
}
|
|
71
|
-
await this.safe_run(() => f(inputs[index - 1]));
|
|
71
|
+
await this.safe_run(() => f(inputs[index - 1], index));
|
|
72
72
|
}
|
|
73
73
|
})());
|
|
74
74
|
}
|
package/package.json
CHANGED
package/src/UtilsBee.ts
CHANGED
|
@@ -14,24 +14,21 @@ export class UtilsBee {
|
|
|
14
14
|
if (this.bee === undefined) {
|
|
15
15
|
return undefined
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
console.log(error.stack)
|
|
30
|
-
}
|
|
31
|
-
console.log("Failed to get from Scraping Bee.")
|
|
17
|
+
try {
|
|
18
|
+
const response = await this.bee.htmlApi({
|
|
19
|
+
url : url,
|
|
20
|
+
params : params
|
|
21
|
+
})
|
|
22
|
+
if (response.data instanceof Buffer) {
|
|
23
|
+
return response.data
|
|
24
|
+
}
|
|
25
|
+
return undefined
|
|
26
|
+
} catch (error) {
|
|
27
|
+
if (error instanceof Error) {
|
|
28
|
+
console.log(error.stack)
|
|
32
29
|
}
|
|
30
|
+
console.log("Failed to get from Scraping Bee.")
|
|
33
31
|
}
|
|
34
|
-
console.log("Failed to get from Scraping Bee, quitting.")
|
|
35
32
|
return undefined
|
|
36
33
|
|
|
37
34
|
}
|
package/src/UtilsMisc.ts
CHANGED
|
@@ -69,17 +69,17 @@ export class UtilsMisc {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
async iterate<T>(inputs : T[], f : (input : T) => Promise<any>,
|
|
72
|
+
async iterate<T>(inputs : T[], f : (input : T, index : number) => Promise<any>, num_iterators : number = 1, print_indices : boolean = false) {
|
|
73
73
|
let index = 0
|
|
74
74
|
let iterators = []
|
|
75
|
-
for (let i = 0; i <
|
|
75
|
+
for (let i = 0; i < num_iterators; i++) {
|
|
76
76
|
iterators.push((async () => {
|
|
77
77
|
while (index < inputs.length) {
|
|
78
78
|
index += 1
|
|
79
79
|
if (print_indices) {
|
|
80
80
|
console.log(i + ":" + (index - 1) + "/" + inputs.length)
|
|
81
81
|
}
|
|
82
|
-
await this.safe_run(() => f(inputs[index - 1]))
|
|
82
|
+
await this.safe_run(() => f(inputs[index - 1], index))
|
|
83
83
|
}
|
|
84
84
|
})())
|
|
85
85
|
}
|