triangle-utils 1.2.1 → 1.2.2
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 +1 -1
- package/test.js +39 -7
- package/utils/Utils_Bee.js +1 -1
- package/utils/Utils_CitizenPortal.js +62 -0
package/Utils.js
CHANGED
|
@@ -7,6 +7,7 @@ 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
9
|
import Utils_Youtube from "./utils/Utils_Youtube.js"
|
|
10
|
+
import Utils_CitizenPortal from "./utils/Utils_CitizenPortal.js"
|
|
10
11
|
|
|
11
12
|
export default class Utils extends Utils_Misc {
|
|
12
13
|
constructor(config) {
|
|
@@ -25,5 +26,8 @@ export default class Utils extends Utils_Misc {
|
|
|
25
26
|
if (config.youtube_api_key !== undefined) {
|
|
26
27
|
this.youtube = new Utils_Youtube(config)
|
|
27
28
|
}
|
|
29
|
+
if (config.citizenportal_api_key !== undefined) {
|
|
30
|
+
this.citizenportal = new Utils_CitizenPortal(config)
|
|
31
|
+
}
|
|
28
32
|
}
|
|
29
33
|
}
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -3,14 +3,12 @@ import { SecretsManager } from "@aws-sdk/client-secrets-manager"
|
|
|
3
3
|
|
|
4
4
|
const secret_name = "api_keys"
|
|
5
5
|
|
|
6
|
-
const secrets_manager = new SecretsManager({ region: "us-east-
|
|
6
|
+
const secrets_manager = new SecretsManager({ region: "us-east-2" })
|
|
7
7
|
|
|
8
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
|
-
|
|
14
12
|
const config = {
|
|
15
13
|
google_email : "louishou@triangleanalytics.com",
|
|
16
14
|
alerts_email : "alerts@triangleanalytics.com",
|
|
@@ -18,10 +16,44 @@ const config = {
|
|
|
18
16
|
...api_keys
|
|
19
17
|
}
|
|
20
18
|
|
|
21
|
-
config.fec_api_keys = config.fec_api_keys.split(",")
|
|
22
|
-
|
|
23
19
|
const utils = new Utils(config)
|
|
24
20
|
|
|
25
|
-
const videos = await utils.youtube.batch_get_videos(["N4dyOzjjYYk"])
|
|
21
|
+
// const videos = await utils.youtube.batch_get_videos(["N4dyOzjjYYk"])
|
|
22
|
+
|
|
23
|
+
// console.log(videos)
|
|
24
|
+
|
|
25
|
+
// const states = await utils.citizenportal.get_sub_jurisdictions(2145)
|
|
26
|
+
|
|
27
|
+
// console.log(states)
|
|
28
|
+
|
|
29
|
+
const documents = await utils.citizenportal.get_jurisdiction_documents(28222)
|
|
30
|
+
|
|
31
|
+
console.log(documents.length)
|
|
32
|
+
|
|
33
|
+
// let response = await fetch("https://api.citizenportal.ai/api/v1/meetings", {
|
|
34
|
+
// headers : {
|
|
35
|
+
// "X-API-Key" : config.citizenportal_api_key
|
|
36
|
+
// }
|
|
37
|
+
// })
|
|
38
|
+
// .then(response => response.json())
|
|
39
|
+
|
|
40
|
+
// for (const doc of response.data) {
|
|
41
|
+
|
|
42
|
+
// response = await fetch("https://api.citizenportal.ai/api/v1/meetings/" + doc.packageId + "/transcript", {
|
|
43
|
+
// headers : {
|
|
44
|
+
// "X-API-Key" : config.citizenportal_api_key
|
|
45
|
+
// }
|
|
46
|
+
// })
|
|
47
|
+
// .then(response => response.json())
|
|
48
|
+
// console.log(response)
|
|
49
|
+
// }
|
|
50
|
+
|
|
51
|
+
// console.log(response)
|
|
52
|
+
let response = await fetch("https://api.citizenportal.ai/api/v1/meetings/606000/transcript", {
|
|
53
|
+
headers : {
|
|
54
|
+
"X-API-Key" : config.citizenportal_api_key
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
.then(response => response.json())
|
|
26
58
|
|
|
27
|
-
console.log(
|
|
59
|
+
console.log(response)
|
package/utils/Utils_Bee.js
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export default class Utils_CitizenPortal {
|
|
2
|
+
|
|
3
|
+
constructor(config) {
|
|
4
|
+
this.config = config
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
async get_sub_jurisdictions(jurisdiction_id) {
|
|
8
|
+
for (let i = 0; i < 3; i++) {
|
|
9
|
+
try {
|
|
10
|
+
const citizenportal_api = "https://api.citizenportal.ai/api/v1/taxonomies?parent_id=" + jurisdiction_id.toString() + "&limit=1000"
|
|
11
|
+
console.log(citizenportal_api)
|
|
12
|
+
const response = await fetch(citizenportal_api, {
|
|
13
|
+
headers : {
|
|
14
|
+
"X-API-Key" : this.config.citizenportal_api_key
|
|
15
|
+
}
|
|
16
|
+
}).then(response => response.json())
|
|
17
|
+
return response.taxonomies
|
|
18
|
+
} catch (e) {
|
|
19
|
+
console.log(e.stack)
|
|
20
|
+
console.log("Failed to get from CitizenPortal.")
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
console.log("Failed to get from CitizenPortal, quitting.")
|
|
24
|
+
return undefined
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async get_jurisdiction_documents(jurisdiction_id) {
|
|
28
|
+
const documents = []
|
|
29
|
+
for (let page = 0; ; page++) {
|
|
30
|
+
const citizenportal_api = "https://api.citizenportal.ai/api/v1/meetings?taxonomy_id=" + jurisdiction_id.toString() + "&include_descendants=false&limit=100&offset=" + (100 * page).toString()
|
|
31
|
+
console.log(citizenportal_api)
|
|
32
|
+
let response = undefined
|
|
33
|
+
for (let i = 0; i < 3; i++) {
|
|
34
|
+
try {
|
|
35
|
+
response = await fetch(citizenportal_api, {
|
|
36
|
+
headers : {
|
|
37
|
+
"X-API-Key" : this.config.citizenportal_api_key
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
.then(response => response.json())
|
|
41
|
+
console.log(response.data.length)
|
|
42
|
+
if (response.data === undefined) {
|
|
43
|
+
console.log("Failed to fetch, retrying.")
|
|
44
|
+
continue
|
|
45
|
+
}
|
|
46
|
+
break
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
console.log("Failed to fetch, retrying.")
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (response === undefined || response.data === undefined) {
|
|
53
|
+
console.log("Failed thriced, exiting.")
|
|
54
|
+
return undefined
|
|
55
|
+
}
|
|
56
|
+
if (response.data.length === 0) {
|
|
57
|
+
return documents
|
|
58
|
+
}
|
|
59
|
+
documents.push(...response.data)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|