码迷,mamicode.com
首页 > 其他好文 > 详细

github Top100

时间:2016-06-18 18:20:49      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:

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

 

github Top100

标签:

原文地址:http://www.cnblogs.com/levy/p/5596435.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!