Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewmueller committed Mar 26, 2015
1 parent eb766b0 commit b0529b7
Showing 1 changed file with 8 additions and 58 deletions.
66 changes: 8 additions & 58 deletions examples/github-stars.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,19 @@
*/

var xray = require('..');
var array = require('array');
var fmt = require('util').format;

/**
* Urls
*/

var languages = [
'JavaScript',
'CSS',
'CoffeeScript',
'Ruby',
'Python',
'Shell',
'Go',
'C',
'C++',
'Objective-C',
'PHP',
'VimL',
'Java',
'Swift',
'Scala',
'TeX',
'Perl',
'Lua',
'Clojure',
'IDL',
'Objective-C++',
'Processing',
'R',
'Vala',
'Lisp',
'XSLT',
'LiveScript',
'TypeScript'
];

/**
* Get the urls
*/

var base = 'https:/stars/matthewmueller?direction=%s&language=%s&sort=created';
var urls = [];
languages.forEach(function(language) {
language = decodeURIComponent(language);
urls.push(fmt(base, 'asc', language));
urls.push(fmt(base, 'desc', language));
})

/**
* Use
*/

xray(urls)
.key('repo', 'div > ul > li.repo-list-item.public.source > h3.repo-list-name > a')
.key('url', 'div > ul > li.repo-list-item.public.source > h3.repo-list-name > a', 'href')
.key('author', 'ul > li.repo-list-item.public.source > h3.repo-list-name > a > span.prefix')
.key('description', 'div > div > ul > li > p.repo-list-description')
.key('time', '.repo-list-meta time', 'datetime')
.paginate('div.pagination > a:last-child')
.json(function(err, json) {
xray('https:/stars/matthewmueller')
.select([{
$root: '.repo-list-item',
link: '.repo-list-name a[href]'
}])
.paginate('div.pagination > a:last-child[href]')
.limit(3)
.run(function(err, json) {
if (err) throw err;
json = array(json).unique('repo').toArray();
console.log(JSON.stringify(json, true, 2));
})

0 comments on commit b0529b7

Please sign in to comment.