-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcode.gs
More file actions
66 lines (52 loc) · 2.48 KB
/
Copy pathcode.gs
File metadata and controls
66 lines (52 loc) · 2.48 KB
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
function getGmailMessages() {
// Search query for job application emails received after August 1, 2024
//const searchQuery = 'Application -{Linkedin Indeed catchafire} after:2024/5/5 before:2025/5/6';
//const searchQuery = 'Job application -{hirist.tech, indeed, linkedin, glassdoor} after:2024/08/01'
const searchQuery = "from:rbc@myworkday.com"
const threads = GmailApp.search(searchQuery, 0, 2);
let totalusedtokensinloop = 0
// Loop through the threads, starting from the oldest thread
for (let i = threads.length - 1; i >= 0; i--) {
const messages = threads[i].getMessages();
// Loop through the messages within each thread, starting from the oldest message
for (let j = messages.length - 1; j >= 0; j--) {
const message = messages[j];
// Extract details from the email
const date = message.getDate();
const body = message.getPlainBody(); // Using plain text body for better compatibility
const subjectplusbody = "subject: " + message.getSubject() + " body: " + body;
const subjectplusbodysnip = message.getSubject() + " " + body.substring(0,100)
const emailLink = message.getThread().getPermalink(); // Get the permalink to the thread
const is_relavant = queryGeminiforsubject(subjectplusbodysnip);
if(
is_relavant == 1
){
var {jobInfo, totalTokenCount} = queryGeminiforBody(subjectplusbody, date)
// Check if 'joninfo' exists and has elements
if (jobInfo) {
try {
const status = jobInfo.status;
const jobTitle = jobInfo.jobTitle;
const company = jobInfo.company;
const location = jobInfo.location;
const update = jobInfo.update;
// Format the date
const formattedDate = formatDate(date);
totalusedtokensinloop += totalTokenCount
// Call the function to input data into the sheet
input_to_sheet(status, jobTitle, company, location, update, formattedDate, emailLink);
Logger.log("input 1 email to the sheet, " + " Total tokens used: " + totalusedtokensinloop);
} catch (parseError) {
Logger.log("Error parsing job info: " + parseError);
}
} else {
Logger.log("No valid content found in the response.");
}
}
else{
Logger.log("Skipped: " + subjectplusbodysnip.substring(0,60))
continue
}
}
}
}