-
Notifications
You must be signed in to change notification settings - Fork 1
/
Episode 4.gs
82 lines (64 loc) · 2.7 KB
/
Episode 4.gs
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
function documentInterview() {
const threads = GmailApp.getChatThreads();
let transcript = '';
for (let thread of threads) {
let messages = thread.getMessages().filter(message => message.getFrom() != 'David Weiss <[email protected]>');
let candidate = messages[0].getFrom();
let interviewDate = thread.getLastMessageDate().toLocaleDateString();
for (let message of messages) {
transcript += `${message.getBody()} `;
}
let blob = Utilities.newBlob(
transcript,
MimeType.PLAIN_TEXT,
`Interview_Transcript_For_Candidate_${candidate}.txt`
);
let interviewTranscriptsFolder = DriveApp.getFoldersByName('HR').next().getFoldersByName('Interview Transcripts').next();
if(interviewTranscriptsFolder.getFoldersByName(interviewDate).hasNext()) {
interviewTranscriptsFolder.getFoldersByName(interviewDate).next().createFile(Utilities.gzip(blob,`Interview_Transcript_For_Candidate_${candidate}.gz`));
} else {
interviewTranscriptsFolder.createFolder(interviewDate).createFile(Utilities.gzip(blob,`Interview_Transcript_For_Candidate_${candidate}.gz`));
}
transcript = '';
// thread.moveToTrash();
}
}
function processSentiment() {
// Please use format "m/d/yyyy"
let interviewDate = '1/27/2021';
let files = DriveApp.getFoldersByName('HR').next().getFoldersByName('Interview Transcripts').next().getFoldersByName(interviewDate).next().getFiles();
let results = [];
while (files.hasNext()) {
let file = Utilities.ungzip(files.next());
let file_name = file.getName();
let transcript = file.getDataAsString();
const data = {
"document": {
"type": 'PLAIN_TEXT',
"language": 'en',
"content": transcript,
},
"encodingType": 'UTF8',
}
const params = {
'method' : 'post',
'headers': {
"Content-Type": "application/json"
},
'payload' : JSON.stringify(data),
};
let fetch = UrlFetchApp.fetch(`https://language.googleapis.com/v1beta2/documents:analyzeSentiment?key=AIzaSyCW5rSqtyZZISreUe-AWvh9YIEA7HntcYM`, params);
// Logger.log(fetch.getContentText());
results.push(Utilities.newBlob(fetch.getContentText(), MimeType.JSON, `RESULTS: ${file_name}`));
}
DriveApp.getFoldersByName('HR').next().getFoldersByName('Sentiment Analysis Results').next().createFile(Utilities.zip(results, interviewDate));
}
function logSentiments() {
// Please use format "m/d/yyyy"
let interviewDate = '1/27/2021';
const zipfile = DriveApp.getFoldersByName('HR').next().getFoldersByName('Sentiment Analysis Results').next().getFilesByName(interviewDate);
let files = Utilities.unzip(zipfile.next());
for (let file of files) {
Logger.log(file.getDataAsString());
}
}