triangle-utils 1.1.3 → 1.2.0
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/Utils.js +4 -0
- package/package.json +3 -1
- package/test.js +4 -1
- package/utils/Utils_DynamoDB.js +8 -4
- package/utils/Utils_Youtube.js +32 -0
package/Utils.js
CHANGED
|
@@ -6,6 +6,7 @@ import Utils_S3 from "./utils/Utils_S3.js"
|
|
|
6
6
|
import Utils_Bedrock from "./utils/Utils_Bedrock.js"
|
|
7
7
|
import Utils_Bee from "./utils/Utils_Bee.js"
|
|
8
8
|
import Utils_S3Vectors from "./utils/Utils_S3Vectors.js"
|
|
9
|
+
import Utils_Youtube from "./utils/Utils_Youtube.js"
|
|
9
10
|
|
|
10
11
|
export default class Utils extends Utils_Misc {
|
|
11
12
|
constructor(config) {
|
|
@@ -21,5 +22,8 @@ export default class Utils extends Utils_Misc {
|
|
|
21
22
|
if (config.scraping_bee_api_key !== undefined) {
|
|
22
23
|
this.bee = new Utils_Bee(config)
|
|
23
24
|
}
|
|
25
|
+
if (config.youtube_api_key !== undefined) {
|
|
26
|
+
this.youtube = new Utils_Youtube(config)
|
|
27
|
+
}
|
|
24
28
|
}
|
|
25
29
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "triangle-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"main": "Utils.js",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "ISC",
|
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
"@aws-sdk/client-dynamodb": "^3.953.0",
|
|
12
12
|
"@aws-sdk/client-s3": "^3.953.0",
|
|
13
13
|
"@aws-sdk/client-s3vectors": "^3.953.0",
|
|
14
|
+
"@aws-sdk/client-secrets-manager": "^3.965.0",
|
|
14
15
|
"@aws-sdk/s3-request-presigner": "^3.953.0",
|
|
16
|
+
"googleapis": "^170.0.0",
|
|
15
17
|
"nodemailer": "^7.0.11",
|
|
16
18
|
"scrapingbee": "^1.7.6",
|
|
17
19
|
"triangle-utils": "^1.0.34"
|
package/test.js
CHANGED
|
@@ -9,6 +9,8 @@ const api_keys = await secrets_manager.getSecretValue({
|
|
|
9
9
|
SecretId: secret_name
|
|
10
10
|
}).then(response => JSON.parse(response.SecretString))
|
|
11
11
|
|
|
12
|
+
console.log(api_keys)
|
|
13
|
+
|
|
12
14
|
const config = {
|
|
13
15
|
google_email : "louishou@triangleanalytics.com",
|
|
14
16
|
alerts_email : "alerts@triangleanalytics.com",
|
|
@@ -20,5 +22,6 @@ config.fec_api_keys = config.fec_api_keys.split(",")
|
|
|
20
22
|
|
|
21
23
|
const utils = new Utils(config)
|
|
22
24
|
|
|
23
|
-
const videos = await utils.
|
|
25
|
+
const videos = await utils.youtube.batch_get_videos(["N4dyOzjjYYk"])
|
|
26
|
+
|
|
24
27
|
console.log(videos)
|
package/utils/Utils_DynamoDB.js
CHANGED
|
@@ -151,7 +151,9 @@ export default class Utils_DynamoDB {
|
|
|
151
151
|
return await compile_pages(request, (request) => this.dynamodb.query(request), compile)
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
async query_prefix(table, primary_key, secondary_key_prefix,
|
|
154
|
+
async query_prefix(table, primary_key, secondary_key_prefix, options = {}) {
|
|
155
|
+
const reverse = options.reverse !== undefined ? options.reverse : false
|
|
156
|
+
const compile = options.reverse !== undefined ? options.compile : true
|
|
155
157
|
if (Object.keys(primary_key).length !== 1 || Object.keys(secondary_key_prefix).length !== 1) {
|
|
156
158
|
return undefined
|
|
157
159
|
}
|
|
@@ -168,10 +170,12 @@ export default class Utils_DynamoDB {
|
|
|
168
170
|
KeyConditionExpression: "#a = :a AND begins_with(#b, :b)",
|
|
169
171
|
ScanIndexForward : !reverse
|
|
170
172
|
}
|
|
171
|
-
return await compile_pages(request, (request) => this.dynamodb.query(request))
|
|
173
|
+
return await compile_pages(request, (request) => this.dynamodb.query(request), compile)
|
|
172
174
|
}
|
|
173
175
|
|
|
174
|
-
async query_range(table, primary_key, secondary_key_range,
|
|
176
|
+
async query_range(table, primary_key, secondary_key_range, options = {}) {
|
|
177
|
+
const reverse = options.reverse !== undefined ? options.reverse : false
|
|
178
|
+
const compile = options.reverse !== undefined ? options.compile : true
|
|
175
179
|
if (Object.keys(primary_key).length !== 1 || Object.keys(secondary_key_range).length !== 1 || Object.values(secondary_key_range)[0].length !== 2) {
|
|
176
180
|
return undefined
|
|
177
181
|
}
|
|
@@ -189,7 +193,7 @@ export default class Utils_DynamoDB {
|
|
|
189
193
|
KeyConditionExpression: "#a = :a AND (#b BETWEEN :b1 AND :b2)",
|
|
190
194
|
ScanIndexForward : !reverse
|
|
191
195
|
}
|
|
192
|
-
return await compile_pages(request, (request) => this.dynamodb.query(request))
|
|
196
|
+
return await compile_pages(request, (request) => this.dynamodb.query(request), compile)
|
|
193
197
|
}
|
|
194
198
|
|
|
195
199
|
async set(table, key, attributes) {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { youtube_v3 } from "googleapis"
|
|
2
|
+
|
|
3
|
+
export default class Utils_Youtube {
|
|
4
|
+
|
|
5
|
+
constructor(config) {
|
|
6
|
+
this.config = config
|
|
7
|
+
this.youtube = new youtube_v3.Youtube({
|
|
8
|
+
auth: config.youtube_api_key
|
|
9
|
+
})
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async batch_get_videos(video_ids, attributes = ["snippet", "contentDetails"]) {
|
|
13
|
+
for (let i = 0; i < 3; i++) {
|
|
14
|
+
try {
|
|
15
|
+
const response = await this.youtube.videos.list({
|
|
16
|
+
part : attributes,
|
|
17
|
+
id : video_ids
|
|
18
|
+
})
|
|
19
|
+
if (response.status !== 200) {
|
|
20
|
+
console.log("Status", response.status)
|
|
21
|
+
return undefined
|
|
22
|
+
}
|
|
23
|
+
return response.data.items
|
|
24
|
+
} catch (e) {
|
|
25
|
+
console.log(e.stack)
|
|
26
|
+
console.log("Failed to get from Scraping Bee.")
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
console.log("Failed to get from Scraping Bee, quitting.")
|
|
30
|
+
return undefined
|
|
31
|
+
}
|
|
32
|
+
}
|