triangle-utils 1.0.37 → 1.1.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/package.json +2 -1
- package/test.js +19 -6
- package/utils/Utils_Bee.js +26 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "triangle-utils",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"main": "Utils.js",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "ISC",
|
|
@@ -11,6 +11,7 @@
|
|
|
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.964.0",
|
|
14
15
|
"@aws-sdk/s3-request-presigner": "^3.953.0",
|
|
15
16
|
"nodemailer": "^7.0.11",
|
|
16
17
|
"scrapingbee": "^1.7.6",
|
package/test.js
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
import Utils from "./Utils.js";
|
|
2
|
+
import { SecretsManager } from "@aws-sdk/client-secrets-manager"
|
|
2
3
|
|
|
4
|
+
const secret_name = "api_keys"
|
|
3
5
|
|
|
4
|
-
const
|
|
6
|
+
const secrets_manager = new SecretsManager({ region: "us-east-1" })
|
|
5
7
|
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
})
|
|
8
|
+
const api_keys = await secrets_manager.getSecretValue({
|
|
9
|
+
SecretId: secret_name
|
|
10
|
+
}).then(response => JSON.parse(response.SecretString))
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
const config = {
|
|
13
|
+
google_email : "louishou@triangleanalytics.com",
|
|
14
|
+
alerts_email : "alerts@triangleanalytics.com",
|
|
15
|
+
region : "us-east-1",
|
|
16
|
+
...api_keys
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
config.fec_api_keys = config.fec_api_keys.split(",")
|
|
20
|
+
|
|
21
|
+
const utils = new Utils(config)
|
|
22
|
+
|
|
23
|
+
const videos = await utils.bee.youtube_search("Marie Gluesenkamp Perez")
|
|
24
|
+
console.log(videos)
|
package/utils/Utils_Bee.js
CHANGED
|
@@ -55,4 +55,30 @@ export default class Utils_Bee {
|
|
|
55
55
|
console.log("Failed to Google thrice, quitting.")
|
|
56
56
|
return undefined
|
|
57
57
|
}
|
|
58
|
+
|
|
59
|
+
async youtube_search(query) {
|
|
60
|
+
for (let i = 0; i < 3; i++) {
|
|
61
|
+
try {
|
|
62
|
+
const bee_url = "https://app.scrapingbee.com/api/v1/youtube/search?api_key=" + this.config.scraping_bee_api_key + "&search=" + encodeURI(query) + "&sort_by=upload_date"
|
|
63
|
+
console.log(bee_url)
|
|
64
|
+
const response = await fetch(bee_url)
|
|
65
|
+
if (!response.ok) {
|
|
66
|
+
console.log("Failed to YouTube Search:", response.status)
|
|
67
|
+
continue
|
|
68
|
+
}
|
|
69
|
+
const data = await response.json()
|
|
70
|
+
const results = data.results
|
|
71
|
+
|
|
72
|
+
if (results === undefined) {
|
|
73
|
+
console.log("Failed to YouTube Search.")
|
|
74
|
+
continue
|
|
75
|
+
}
|
|
76
|
+
return results
|
|
77
|
+
} catch {
|
|
78
|
+
console.log("Failed to YouTube Search.")
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
console.log("Failed to YouTube Search thrice, quitting.")
|
|
82
|
+
return undefined
|
|
83
|
+
}
|
|
58
84
|
}
|