github Top100

nodejs 文件

var restify = require('restify'),
moment = require('moment'),
fs = require('fs'),
yesterday = moment().hour(-24).format('YYYY-MM-DD').toString(); function search(object) { if (object.q) {
var client = restify.createJsonClient({
url: 'https://api.github.com',
}); var path = '/search/repositories?q=' + object.q;
if (object.sort) path = path + '&sort=' + object.sort;
if (object.order) path = path + '&order=' + object.order;
if (object.per_page) path = path + '&per_page=' + object.per_page;
if (object.page) path = path + '&page=' + object.page; client.get(path, function(err, req_, res_, obj) {
if (err) {
console.log(err);
} else {
var items = obj.items;
var content = "语言|star|项目名称|描述\n---|---|---|---\n";
for (var i = 0; i < items.length; i++) {
var text = (items[i].language || " ") + "|" + (items[i].stargazers_count || " ") + "|[" + (items[i].full_name || " ") + "](" + items[i].html_url + ")|" + (items[i].description || " ") + "\n";
content = content + text;
}
fs.writeFile('./Top100/Top100_' + yesterday + '.md', content, function(err) {
if (err) throw err;
console.log('It\'s saved!');
});
}
});
}
} var object = {
q: 'created:' + yesterday,
sort: 'stars',
order: 'desc',
per_page: '100',
page: '1'
}; search(object);

g.sh 文件

#!/bin/bash
node github.js
cd Top100/
git add ./
git pull
git commit -am "update"
git push origin master
上一篇:python 识别图片验证码报IOError


下一篇:C#基础第二天