triangle-utils 1.4.54 → 1.4.56
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.d.ts +1 -0
- package/dist/src/UtilsBee.js +27 -0
- package/dist/src/UtilsDynamoDB.js +9 -0
- package/dist/src/UtilsMisc.d.ts +2 -2
- package/dist/src/UtilsMisc.js +7 -4
- package/package.json +1 -1
- package/src/UtilsBee.ts +28 -0
- package/src/UtilsDynamoDB.ts +9 -0
- package/src/UtilsMisc.ts +9 -6
package/dist/src/UtilsBee.d.ts
CHANGED
|
@@ -6,4 +6,5 @@ export declare class UtilsBee {
|
|
|
6
6
|
get(url: string, params?: Record<string, string | number | boolean>): Promise<string | Error | undefined>;
|
|
7
7
|
google_search(query: string, news?: boolean): Promise<Record<string, any>[] | undefined>;
|
|
8
8
|
youtube_search(query: string, options?: {}): Promise<Record<string, any>[] | undefined>;
|
|
9
|
+
youtube_get_subtitles(video_id: string): Promise<Record<string, any> | undefined>;
|
|
9
10
|
}
|
package/dist/src/UtilsBee.js
CHANGED
|
@@ -109,4 +109,31 @@ export class UtilsBee {
|
|
|
109
109
|
console.log("Failed to YouTube Search thrice, quitting.");
|
|
110
110
|
return undefined;
|
|
111
111
|
}
|
|
112
|
+
async youtube_get_subtitles(video_id) {
|
|
113
|
+
if (this.bee === undefined) {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
for (let i = 0; i < 3; i++) {
|
|
117
|
+
try {
|
|
118
|
+
const url = "https://app.scrapingbee.com/api/v1/youtube/subtitles?video_id=" + video_id + "&api_key=" + this.bee.api_key;
|
|
119
|
+
const response = await fetch(url);
|
|
120
|
+
if (response.status !== 200) {
|
|
121
|
+
console.log("Failed to get YouTube Subtitles:", response.status);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const data = await response.json();
|
|
125
|
+
const subtitles = data.subtitles;
|
|
126
|
+
if (subtitles === undefined) {
|
|
127
|
+
console.log("Failed to YouTube Search.");
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
return subtitles;
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
console.log("Failed to YouTube Search.");
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
console.log("Failed to YouTube Search thrice, quitting.");
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
112
139
|
}
|
|
@@ -219,6 +219,9 @@ export class UtilsDynamoDB {
|
|
|
219
219
|
},
|
|
220
220
|
ExpressionAttributeValues: {
|
|
221
221
|
...Object.fromEntries(Object.entries(primary_key)
|
|
222
|
+
.map(([key, value]) => [":" + key, convert_input(value)])
|
|
223
|
+
.filter(([key, value]) => value !== undefined)),
|
|
224
|
+
...Object.fromEntries(Object.entries(filters)
|
|
222
225
|
.map(([key, value]) => [":" + key, convert_input(value)])
|
|
223
226
|
.filter(([key, value]) => value !== undefined))
|
|
224
227
|
},
|
|
@@ -274,6 +277,9 @@ export class UtilsDynamoDB {
|
|
|
274
277
|
.map(([key, value]) => [":" + key, convert_input(value)])
|
|
275
278
|
.filter(([key, value]) => value !== undefined)),
|
|
276
279
|
...Object.fromEntries(Object.entries(secondary_key_prefix)
|
|
280
|
+
.map(([key, value]) => [":" + key, convert_input(value)])
|
|
281
|
+
.filter(([key, value]) => value !== undefined)),
|
|
282
|
+
...Object.fromEntries(Object.entries(filters)
|
|
277
283
|
.map(([key, value]) => [":" + key, convert_input(value)])
|
|
278
284
|
.filter(([key, value]) => value !== undefined))
|
|
279
285
|
},
|
|
@@ -336,6 +342,9 @@ export class UtilsDynamoDB {
|
|
|
336
342
|
.filter(([key, value]) => value !== undefined)),
|
|
337
343
|
...Object.fromEntries(Object.entries(secondary_key_range)
|
|
338
344
|
.map(([key, value]) => [":" + key + "_max", convert_input(value[1])])
|
|
345
|
+
.filter(([key, value]) => value !== undefined)),
|
|
346
|
+
...Object.fromEntries(Object.entries(filters)
|
|
347
|
+
.map(([key, value]) => [":" + key, convert_input(value)])
|
|
339
348
|
.filter(([key, value]) => value !== undefined))
|
|
340
349
|
},
|
|
341
350
|
FilterExpression: filter_expression.length > 0 ? filter_expression : undefined,
|
package/dist/src/UtilsMisc.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ interface Encryption {
|
|
|
6
6
|
export declare class UtilsMisc {
|
|
7
7
|
readonly config: TriangleUtilsConfig;
|
|
8
8
|
constructor(config: TriangleUtilsConfig);
|
|
9
|
-
safe_run(f: () => Promise<
|
|
10
|
-
iterate<T>(inputs: T[], f: (input: T, iterator_id: number, index: number) => Promise<
|
|
9
|
+
safe_run<T>(f: () => Promise<T>): Promise<T | undefined>;
|
|
10
|
+
iterate<T, U>(inputs: T[], f: (input: T, iterator_id: number, index: number) => Promise<U>, num_iterators?: number, print_option?: number | boolean): Promise<(U | undefined)[]>;
|
|
11
11
|
static wait(duration: number): Promise<unknown>;
|
|
12
12
|
static get_current_time(): string;
|
|
13
13
|
static get_current_milliseconds(): number;
|
package/dist/src/UtilsMisc.js
CHANGED
|
@@ -6,11 +6,11 @@ export class UtilsMisc {
|
|
|
6
6
|
}
|
|
7
7
|
async safe_run(f) {
|
|
8
8
|
try {
|
|
9
|
-
await f();
|
|
9
|
+
return await f();
|
|
10
10
|
}
|
|
11
11
|
catch (error) {
|
|
12
12
|
if (!(error instanceof Error)) {
|
|
13
|
-
return;
|
|
13
|
+
return undefined;
|
|
14
14
|
}
|
|
15
15
|
if (error.stack !== undefined) {
|
|
16
16
|
console.log(error.stack.toString());
|
|
@@ -19,11 +19,13 @@ export class UtilsMisc {
|
|
|
19
19
|
console.log(error.toString());
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
+
return undefined;
|
|
22
23
|
}
|
|
23
24
|
async iterate(inputs, f, num_iterators = 1, print_option) {
|
|
24
25
|
const print_freq = typeof print_option === "boolean" ? (print_option === true ? 1 : 0) : print_option;
|
|
25
26
|
let index = 0;
|
|
26
27
|
let iterators = [];
|
|
28
|
+
const outputs = []; //new Array(inputs.length).fill(undefined)
|
|
27
29
|
for (let iterator_id = 0; iterator_id < num_iterators; iterator_id++) {
|
|
28
30
|
iterators.push((async () => {
|
|
29
31
|
while (index < inputs.length) {
|
|
@@ -31,11 +33,12 @@ export class UtilsMisc {
|
|
|
31
33
|
if (print_freq !== undefined && ((index - 1) % print_freq === 0)) {
|
|
32
34
|
console.log(iterator_id + ":" + (index - 1) + "/" + inputs.length);
|
|
33
35
|
}
|
|
34
|
-
await this.safe_run(() => f(inputs[index - 1], iterator_id, index));
|
|
36
|
+
const output = await this.safe_run(() => f(inputs[index - 1], iterator_id, index));
|
|
37
|
+
outputs.push(output);
|
|
35
38
|
}
|
|
36
39
|
})());
|
|
37
40
|
}
|
|
38
|
-
|
|
41
|
+
return outputs;
|
|
39
42
|
}
|
|
40
43
|
static async wait(duration) {
|
|
41
44
|
return new Promise(resolve => setTimeout(resolve, duration));
|
package/package.json
CHANGED
package/src/UtilsBee.ts
CHANGED
|
@@ -118,4 +118,32 @@ export class UtilsBee {
|
|
|
118
118
|
console.log("Failed to YouTube Search thrice, quitting.")
|
|
119
119
|
return undefined
|
|
120
120
|
}
|
|
121
|
+
|
|
122
|
+
async youtube_get_subtitles(video_id : string) : Promise<Record<string, any> | undefined> {
|
|
123
|
+
if (this.bee === undefined) {
|
|
124
|
+
return undefined
|
|
125
|
+
}
|
|
126
|
+
for (let i = 0; i < 3; i++) {
|
|
127
|
+
try {
|
|
128
|
+
const url = "https://app.scrapingbee.com/api/v1/youtube/subtitles?video_id=" + video_id + "&api_key=" + this.bee.api_key
|
|
129
|
+
const response = await fetch(url)
|
|
130
|
+
if (response.status !== 200) {
|
|
131
|
+
console.log("Failed to get YouTube Subtitles:", response.status)
|
|
132
|
+
continue
|
|
133
|
+
}
|
|
134
|
+
const data : Record<string, any> = await response.json()
|
|
135
|
+
const subtitles = data.subtitles
|
|
136
|
+
|
|
137
|
+
if (subtitles === undefined) {
|
|
138
|
+
console.log("Failed to YouTube Search.")
|
|
139
|
+
continue
|
|
140
|
+
}
|
|
141
|
+
return subtitles
|
|
142
|
+
} catch {
|
|
143
|
+
console.log("Failed to YouTube Search.")
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
console.log("Failed to YouTube Search thrice, quitting.")
|
|
147
|
+
return undefined
|
|
148
|
+
}
|
|
121
149
|
}
|
package/src/UtilsDynamoDB.ts
CHANGED
|
@@ -267,6 +267,9 @@ export class UtilsDynamoDB {
|
|
|
267
267
|
},
|
|
268
268
|
ExpressionAttributeValues: {
|
|
269
269
|
...Object.fromEntries(Object.entries(primary_key)
|
|
270
|
+
.map(([key, value]) => [":" + key, convert_input(value)])
|
|
271
|
+
.filter(([key, value]) => value !== undefined)),
|
|
272
|
+
...Object.fromEntries(Object.entries(filters)
|
|
270
273
|
.map(([key, value]) => [":" + key, convert_input(value)])
|
|
271
274
|
.filter(([key, value]) => value !== undefined))
|
|
272
275
|
},
|
|
@@ -338,6 +341,9 @@ export class UtilsDynamoDB {
|
|
|
338
341
|
.map(([key, value]) => [":" + key, convert_input(value)])
|
|
339
342
|
.filter(([key, value]) => value !== undefined)),
|
|
340
343
|
...Object.fromEntries(Object.entries(secondary_key_prefix)
|
|
344
|
+
.map(([key, value]) => [":" + key, convert_input(value)])
|
|
345
|
+
.filter(([key, value]) => value !== undefined)),
|
|
346
|
+
...Object.fromEntries(Object.entries(filters)
|
|
341
347
|
.map(([key, value]) => [":" + key, convert_input(value)])
|
|
342
348
|
.filter(([key, value]) => value !== undefined))
|
|
343
349
|
},
|
|
@@ -416,6 +422,9 @@ export class UtilsDynamoDB {
|
|
|
416
422
|
.filter(([key, value]) => value !== undefined)),
|
|
417
423
|
...Object.fromEntries(Object.entries(secondary_key_range)
|
|
418
424
|
.map(([key, value]) => [":" + key + "_max", convert_input(value[1])])
|
|
425
|
+
.filter(([key, value]) => value !== undefined)),
|
|
426
|
+
...Object.fromEntries(Object.entries(filters)
|
|
427
|
+
.map(([key, value]) => [":" + key, convert_input(value)])
|
|
419
428
|
.filter(([key, value]) => value !== undefined))
|
|
420
429
|
},
|
|
421
430
|
FilterExpression : filter_expression.length > 0 ? filter_expression : undefined,
|
package/src/UtilsMisc.ts
CHANGED
|
@@ -15,12 +15,12 @@ export class UtilsMisc {
|
|
|
15
15
|
this.config = config
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
async safe_run(f : () => Promise<
|
|
18
|
+
async safe_run<T>(f : () => Promise<T>) : Promise<T | undefined> {
|
|
19
19
|
try {
|
|
20
|
-
await f()
|
|
20
|
+
return await f()
|
|
21
21
|
} catch (error) {
|
|
22
22
|
if (!(error instanceof Error)) {
|
|
23
|
-
return
|
|
23
|
+
return undefined
|
|
24
24
|
}
|
|
25
25
|
if (error.stack !== undefined) {
|
|
26
26
|
console.log(error.stack.toString())
|
|
@@ -28,12 +28,14 @@ export class UtilsMisc {
|
|
|
28
28
|
console.log(error.toString())
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
+
return undefined
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
async iterate<T>(inputs : T[], f : (input : T, iterator_id : number, index : number) => Promise<
|
|
34
|
+
async iterate<T, U>(inputs : T[], f : (input : T, iterator_id : number, index : number) => Promise<U>, num_iterators : number = 1, print_option? : number | boolean) {
|
|
34
35
|
const print_freq : number | undefined = typeof print_option === "boolean" ? (print_option === true ? 1 : 0) : print_option
|
|
35
36
|
let index = 0
|
|
36
37
|
let iterators = []
|
|
38
|
+
const outputs : (U | undefined)[] = []//new Array(inputs.length).fill(undefined)
|
|
37
39
|
for (let iterator_id = 0; iterator_id < num_iterators; iterator_id++) {
|
|
38
40
|
iterators.push((async () => {
|
|
39
41
|
while (index < inputs.length) {
|
|
@@ -41,11 +43,12 @@ export class UtilsMisc {
|
|
|
41
43
|
if (print_freq !== undefined && ((index - 1) % print_freq === 0)) {
|
|
42
44
|
console.log(iterator_id + ":" + (index - 1) + "/" + inputs.length)
|
|
43
45
|
}
|
|
44
|
-
await this.safe_run(() => f(inputs[index - 1], iterator_id, index))
|
|
46
|
+
const output = await this.safe_run(() => f(inputs[index - 1], iterator_id, index))
|
|
47
|
+
outputs.push(output)
|
|
45
48
|
}
|
|
46
49
|
})())
|
|
47
50
|
}
|
|
48
|
-
|
|
51
|
+
return outputs
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
|