{"size": 908, "ext": "js", "max_stars_repo_path": "scripts/add_blog.js", "max_stars_repo_name": "ZhuPeng/mp-githubtrending", "max_stars_repo_stars_event_min_datetime": "2019-02-20T13:24:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T13:09:13.000Z", "max_issues_repo_path": "scripts/add_blog.js", "max_issues_repo_name": "ZhuPeng/mp-githubtrending", "max_issues_repo_issues_event_min_datetime": "2019-03-07T06:15:36.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-09T02:29:51.000Z", "max_forks_repo_path": "scripts/add_blog.js", "max_forks_repo_name": "ZhuPeng/mp-githubtrending", "max_forks_repo_forks_event_min_datetime": "2019-03-04T00:50:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-19T12:07:50.000Z"}
{"max_stars_count": 217, "max_issues_count": 27, "max_forks_count": 22, "avg_line_length": 25.9428571429, "max_line_length": 91, "alphanum_fraction": 0.6057268722}
// 初始化示例
const tcb = require('tcb-admin-node');
var url = require('url')

// 初始化资源
// 云函数下不需要secretId和secretKey。
// env如果不指定将使用默认环境
const app = tcb.init({
  secretId: '',
  secretKey: '',
  env: ''
})
const db = app.database();
var data = {"status": "online", "_crawl_time": "", "__tablename__": "github"}

// 需要填写的内容
data["title"] = ""
data["article-image_url"] = ""
data["url"] = ""

db.collection('blog').orderBy('_crawl_time', 'desc').limit(1).get().then(res => { 
    var last = res.data[0]
    var d = new Date(Date.parse(last._crawl_time))
    console.log(d.toISOString())
    d.setDate(d.getDate() + 1);
    if (d < new Date()) {
        d = new Date()
        console.log('Update date to now:', d.toISOString())
    }
    data["_crawl_time"] = d

    console.log('add blog:', data)
    db.collection('blog').add(data).then(res => { console.log(res) }).catch(console.error) 
}).catch(console.error) 
