AppScript
AppScript
const CONFIG = {
// Styling for Problem Column (Column A)
PROBLEM_BG: "#fce4d6",
PROBLEM_TEXT_COLOR: "#000000",
function updateSubmissions() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
// Fetch all submissions for your handle using the CodeForces API
var apiUrl = "https://codeforces.com/api/user.status?handle=" + cfHandle;
var response = UrlFetchApp.fetch(apiUrl);
var data = JSON.parse(response.getContentText());
if (data.status !== "OK") {
Logger.log("Error fetching submissions: " + data.comment);
return;
}
var submissions = data.result;
// Fetch the complete list of CodeForces problems to get their full names and
ratings.
// This is useful if you haven't solved or attempted a problem.
var allProblems = {};
try {
var responseProblems =
UrlFetchApp.fetch("https://codeforces.com/api/problemset.problems");
var dataProblems = JSON.parse(responseProblems.getContentText());
if (dataProblems.status === "OK") {
dataProblems.result.problems.forEach(function (prob) {
if (prob.contestId && prob.index) {
var key = prob.contestId.toString() + prob.index.toUpperCase();
allProblems[key] = {
name: prob.name,
rating: prob.rating || "N/A"
};
}
});
}
} catch (e) {
Logger.log("Error fetching problemset problems: " + e);
}
// -----------------------------
// Column B: Submission Status
// -----------------------------
var cellB = sheet.getRange(i + 2, 2);
var shortStatus = "N/A";
var emoji = "❔";
var bgColorStatus = CONFIG.STATUS_BG_DEFAULT;
var statusText = "";
var richTextB = null;
var chosenSub = null;
var submissionDateTime = null;
if (submissionMap.hasOwnProperty(key)) {
var record = submissionMap[key];
if (record.latestAccepted) {
chosenSub = record.latestAccepted;
shortStatus = "AC";
emoji = "✅";
bgColorStatus = CONFIG.STATUS_BG_AC;
} else if (record.latestSubmission) {
chosenSub = record.latestSubmission;
submissionDateTime = new Date(chosenSub.creationTimeSeconds * 1000);
var verdict = chosenSub.verdict;
switch (verdict) {
case "WRONG_ANSWER":
shortStatus = "WA";
emoji = "❌";
bgColorStatus = CONFIG.STATUS_BG_WA;
break;
case "TIME_LIMIT_EXCEEDED":
shortStatus = "TLE";
emoji = "⌛";
bgColorStatus = CONFIG.STATUS_BG_TLE;
break;
case "MEMORY_LIMIT_EXCEEDED":
shortStatus = "MLE";
emoji = "💾";
bgColorStatus = CONFIG.STATUS_BG_MLE;
break;
case "RUNTIME_ERROR":
shortStatus = "RE";
emoji = "⚠️";
bgColorStatus = CONFIG.STATUS_BG_WA;
break;
case "COMPILATION_ERROR":
shortStatus = "CE";
emoji = "🚫";
bgColorStatus = CONFIG.STATUS_BG_WA;
break;
default:
shortStatus = verdict.substring(0, 3).toUpperCase();
emoji = "❓";
bgColorStatus = CONFIG.STATUS_BG_WA;
break;
}
}
statusText = shortStatus + " " + emoji;
// Build the hyperlink for the status (linking to the submission).
if (chosenSub) {
var submissionUrl = "https://codeforces.com/contest/" + contestId +
"/submission/" + chosenSub.id;
var textStyleB = SpreadsheetApp.newTextStyle()
.setForegroundColor(CONFIG.PROBLEM_TEXT_COLOR)
.setUnderline(false)
.setBold(CONFIG.FONT_BOLD)
.build();
richTextB = SpreadsheetApp.newRichTextValue()
.setText(statusText)
.setLinkUrl(submissionUrl)
.setTextStyle(0, statusText.length, textStyleB)
.build();
cellB.setRichTextValue(richTextB);
} else {
cellB.setValue(statusText);
}
} else {
statusText = "N/A ❌";
cellB.setValue(statusText);
}
cellB.setHorizontalAlignment("center");
cellB.setFontSize(CONFIG.FONT_SIZE_STATUS);
cellB.setBackground(bgColorStatus);
// -----------------------------
// Column C: Problem Rating
// -----------------------------
var cellC = sheet.getRange(i + 2, 3);
cellC.setValue(problemRating);
cellC.setHorizontalAlignment("center");
cellC.setFontSize(CONFIG.FONT_SIZE_STATUS);
// -----------------------------
// Column D: Submission Date & Time
// -----------------------------
var cellD = sheet.getRange(i + 2, 4);
if (chosenSub && submissionDateTime) {
// Format the date as "dd/MM/yyyy - HH:mm"
var formattedDate = Utilities.formatDate(
submissionDateTime,
Session.getScriptTimeZone(),
"dd/MM/yyyy - HH:mm"
);
cellD.setValue(formattedDate);
} else {
cellD.setValue("N/A");
}
cellD.setHorizontalAlignment("center");
}
}