-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
66 lines (44 loc) · 1.58 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import json
import logging
from pydantic_settings import BaseSettings, SettingsConfigDict
from requests import Session
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
class Config(BaseSettings):
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8")
gong_access_key: str
gong_secret_key: str
call_ids: list[int]
def main():
config = Config()
session = Session()
session.auth = (config.gong_access_key, config.gong_secret_key)
host = "https://api.gong.io"
path = "/v2/calls/transcript"
cursor = ""
while True:
payload = {
"cursor": cursor,
"filter": {
"callIds": config.call_ids,
},
}
logger.info(f"Getting data from Gong API with payload: {payload}")
response = session.post(host + path, json=payload)
if response.status_code != 200:
raise Exception(
f"Failed to get data from Gong API. Status code: {response.text}"
)
data = response.json()
for call_transcript in data["callTranscripts"]:
with open(f'output/{call_transcript["callId"]}.json', "w") as f:
logger.info(
f'Writing call transcript to file {call_transcript["callId"]}.json'
)
f.write(json.dumps(call_transcript["transcript"]))
cursor = data["records"].get("cursor")
if not cursor:
break
logger.info("Finished getting transcripts from Gong API")
if __name__ == "__main__":
main()