You can automate the tracking of Bilibili follower counts by creating a script in Kingsoft Docs (KDocs). The process involves creating a spreadsheet, using the AirScript editor to implement a script that calls the Bilibili API, and optionally setting up a scheduled task for periodic updates.
let fs;
let smtp_host = Application.Range("G2").Text;
let smtp_port = parseInt(Application.Range("G3").Text);
let smtp_username = Application.Range("G4").Text;
let smtp_password = Application.Range("G5").Text;
let smtp_secure = Application.Range("G6").Text.toLowerCase() === "true";
let smtp_to = Application.Range("G7").Text;
let blibli_uid = parseInt(Application.Range("G8").Text);
let config_message = Application.Range("G9").Text;
let config_message_send = Application.Range("G10").Text;
// Fetch follower count from Bilibili API
let url = "https://api.bilibili.com/x/relation/stat?vmid=" + blibli_uid;
let resp = HTTP.get(url);
if (resp.status !== 200) {
throw new Error("Error! Status is " + resp.status());
}
let data = resp.json();
if (data.code === 0) {
let follower = data.data.follower;
let sheet = Application.ActiveSheet;
// Find first empty cell in column B to record follower count
let row = 1;
while (sheet.Range('B' + row).Value !== "") {
row++;
}
var currentDate = new Date();
var options = { timeZone: 'Asia/Shanghai' };
var chinaTime = currentDate.toLocaleDateString('en-US', options);
sheet.Range('A' + row).Value = chinaTime;
sheet.Range('B' + row).Value = follower;
fs = follower;
// Calculate difference from previous record
let lastRow = row;
if (lastRow >= 2) {
let lastFollower = sheet.Range('B' + (lastRow - 1)).Value;
let diff = fs - lastFollower;
zj = diff;
if (config_message_send == "是") {
if (diff == 0) {
if (config_message == "是") {
smtp_message();
}
} else {
smtp_message();
}
}
}
} else {
console.error("API response error: " + data.message);
}
function smtp_message() {
let mailer = SMTP.login({
host: smtp_host,
port: smtp_port,
username: smtp_username,
password: smtp_password,
secure: smtp_secure,
});
mailer.send({
from: smtp_username,
to: smtp_to,
subject: "粉丝数通知",
html: `...` // HTML content for email notification
});
}