triangle-utils 1.1.4 → 1.2.1

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 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.1.4",
3
+ "version": "1.2.1",
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.bee.youtube_search("Marie Gluesenkamp Perez")
25
+ const videos = await utils.youtube.batch_get_videos(["N4dyOzjjYYk"])
26
+
24
27
  console.log(videos)
@@ -24,7 +24,6 @@ export default class Utils_Bedrock {
24
24
  return response.generation
25
25
  } catch (e) {
26
26
  console.log("Failed to get from Bedrock.")
27
- return undefined
28
27
  }
29
28
  }
30
29
  console.log("Failed to get from Bedrock, quitting.")
@@ -54,7 +53,6 @@ export default class Utils_Bedrock {
54
53
  } catch (e) {
55
54
  console.log("Failed to get from Bedrock.")
56
55
  console.log(e.stack)
57
- return undefined
58
56
  }
59
57
  }
60
58
  console.log("Failed to get from Bedrock, quitting.")
@@ -76,7 +74,6 @@ export default class Utils_Bedrock {
76
74
  } catch (e) {
77
75
  console.log("Failed to get from Bedrock.")
78
76
  console.log(e.stack)
79
- return undefined
80
77
  }
81
78
  }
82
79
  console.log("Failed to get from Bedrock, quitting.")
@@ -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
+ }