Last active
May 3, 2020 12:01
-
-
Save fython/e097993dfb04ffd776831f9fbf9efaa7 to your computer and use it in GitHub Desktop.
Watch followers count of specific Bilibili user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This script is used to watch followers count of specific user in Bilibili. | |
* Please change the constant "CHECK_UID" to user id you want to watch. | |
* | |
* Before running this script, please install following dependencies to global: | |
* - axios | |
* - node-notifier | |
* | |
* For example, when you are using NPM as package manager, | |
* run this command in shell: | |
* > npm install -g axios node-notifier | |
* | |
* @author Siubeng <[email protected]> | |
*/ | |
const { execSync } = require('child_process'); | |
const path = require('path'); | |
const root = execSync('npm root -g').toString().trim(); | |
const requireg = (name) => require(path.resolve(root, name)); | |
const axios = requireg('axios'); | |
const notifier = requireg('node-notifier'); | |
const INFO_URL = 'https://api.bilibili.com/x/space/acc/info'; | |
const RELATION_URL = 'https://api.bilibili.com/x/relation/stat'; | |
// Change specific user id here | |
const CHECK_UID = '375504219'; | |
// Check interval. Default: 60s | |
const CHECK_INTERVAL = 1000 * 60; | |
// Enable system notification | |
const NOTIFY_ENABLED = true; | |
let maxCount = 0; | |
let username = ''; | |
function normalize(num) { | |
return num < 10 ? '0' + num : num; | |
} | |
async function check() { | |
const req = await axios(RELATION_URL, {params: {vmid: CHECK_UID}}); | |
const date = new Date(Date.now()); | |
const count = req.data.data.follower; | |
const hh = normalize(date.getHours()); | |
const mm = normalize(date.getMinutes()); | |
const ss = normalize(date.getSeconds()); | |
console.log(`[${hh}:${mm}:${ss}] ${username} 粉丝数量:${count}`); | |
if (count > maxCount) { | |
maxCount = count; | |
if (NOTIFY_ENABLED) { | |
notifier.notify({ | |
title: username + ' 粉丝数量', | |
message: '当前粉丝数量:' + count, | |
}); | |
} | |
} | |
} | |
// Main procedure | |
async function main() { | |
const req = await axios(INFO_URL, {params: {mid: CHECK_UID}}); | |
username = req.data.data.name; | |
setInterval(check, CHECK_INTERVAL); | |
check(); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment