You can automate the tracking of Bilibili follower counts by using a Kdocs spreadsheet and an AirScript script. The script fetches follower data from the Bilibili API, logs the date and count into the spreadsheet, calculates the difference from the previous entry, and optionally sends an email notification via SMTP.
Setup Steps:
- Create a new Office Spreadsheet in Kdocs.
- Navigate to Efficiency (效率) -> Advanced Development (高级开发) -> AirScript Script Editor (AirScript脚本编辑器).
- Create a Document Shared Script (文档共享脚本) and paste the provided script.
- Configure the required parameters in the spreadsheet cells (refer to the script's
Application.Range calls). - (Optional) To automate data collection, set up a schedule in Efficiency (效率) -> Advanced Development (高级开发) -> Scheduled Tasks (定时任务).
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 Bilibili follower stats
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 log data
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: `<div>...Bilibili Follower Notification...</div>`,
});
}