Skip to content

Commit

Permalink
fix country standings, fix test, remove submit token, update cli help
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-dinar committed Oct 29, 2016
1 parent 541e4a0 commit c8caaba
Show file tree
Hide file tree
Showing 17 changed files with 501 additions and 582 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ A simple and useful Command Line tool for Codeforces coders

## Releases
#### Work in progress
<img src="https://cdn.meme.am/instances/500x/67479527.jpg" width="300" >


## Inspirations
- [Codeforces API](http://codeforces.com/api/help)
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
"single": "./node_modules/.bin/nyc ./node_modules/.bin/mocha --compilers js:babel-register \"tests/crawler/test_ratings.js\" & npm run cov-html"
},
"nyc": {
"include": ["src/lib/crawler/*.js", "src/lib/api/*.js", "src/lib/utils/*.js", "tests/**/*.js"]
"include": [
"src/lib/crawler/*.js",
"src/lib/api/*.js",
"src/lib/utils/*.js",
"tests/**/*.js"
]
},
"repository": {
"type": "git",
Expand Down
51 changes: 36 additions & 15 deletions src/bin/cli/cf.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,31 @@ program
.version(version)
.usage('[options] [command]');

program.on('--help', () => {
log(' All options:');
log(' -r, --remember save/update handle');
log(' -c, --count total items to fetch and show');
log(' -w, --watch watch submission status live');
log(' -p, --problem also download problem statement');
log(' -u, --user <handle> codeforces user handle');
log(' -l, --language <language-id> programming language id of the solution');
log(' -d, --directory <directory> directory to save solutions');
log(' --logout delete saved password');
log(' --gym gym problem submit');
log(' --no-chart disable showing chart of user rating');
log(' --org show Organization of users');
log(' --unofficial unofficial standings');
log(' --handles <handles> comma separated codeforces handles');
log(' --offset <offset> offset of the items to fetch from');
log(' --limit <download-limit> maximum number of simultaneous downloads');
log(' --country <country-name> country name for rating');
log(' --delay <delay> refreshing delay of live submission status [in millisecond]');
log(' --contest <contestId> specific contest submissions');
});

program
.command('runs')
.option('-r, --remember', 'save handle for future')
.option('-r, --remember', 'save/update handle')
.option('-c, --count <total>', 'total submission status to display')
.option('-w, --watch', 'watch submission status live')
.option('--delay <delay>', 'refreshing delay of live submission status [in millisecond]')
Expand Down Expand Up @@ -104,10 +126,10 @@ program

program
.command('rating')
.option('-u, --user <handle>', 'user handle for rating')
.option('-u, --user <handle>', 'codeforces user handle')
.option('--country <country-name>', 'country name for rating')
.option('--no-chart', 'disable showing chart for user')
.option('--org', 'show Organization for country rating')
.option('--no-chart', 'disable showing chart of user rating')
.option('--org', 'show Organization of users')
.description('user ratings')
.action( (prg) => {

Expand All @@ -129,7 +151,7 @@ program

program
.command('tags')
.description('all tags and problem quantity')
.description('all tags distribution')
.action( () => {
CF.tags();
});
Expand Down Expand Up @@ -187,7 +209,7 @@ program
.command('solutions <handle>')
.option('-d, --directory <directory>','directory to save solutions')
.option('-p, --problem','also download problem statement')
.option('--limit <async-limit>','limit async task')
.option('--limit <download-limit>','maximum number of simultaneous downloads')
.description('user solution download')
.action( (handle,prg) => {

Expand All @@ -209,7 +231,7 @@ program
program
.command('standings <contestId>')
.description('contest standings')
.option('--handles <handles>', 'handles for standings')
.option('--handles <handles>', 'comma separated codeforces handles')
.option('--country <country-name>', 'country name for standings')
.option('-c, --count <total>', 'total standings to display')
.option('--offset <offset>', 'standings offset')
Expand Down Expand Up @@ -266,7 +288,7 @@ if( !program.args.length && has(program,'help') ){
// https://github.com/tj/programer.js/issues/57
//
if (!program.args.length) {
figlet('Codeforces CLI',{ font: 'ANSI Shadow' }, (err, data) => {
figlet('Codeforces CLI', (err, data) => {
log('');
log('');
if(!err){
Expand All @@ -279,19 +301,18 @@ if (!program.args.length) {
//warn aboud invalid programs
var validprograms = program.commands.map(function(cmd){
return cmd.name;
return cmd._name;
});
var invalidprograms = program.args.filter(function(cmd){
//if program executed it will be an object and not a string
return (typeof cmd === 'string' && validprograms.indexOf(cmd) === -1 );
var invalidprograms = program.args.map(function(cmd){
return cmd._name;
});
if (invalidprograms.length) {
// log('\n [ERROR] - Invalid program: "%s". See "--help" for a list of available programs.\n', invalidprograms.join(', '));
log('');
log(` [ERROR] - Invalid command: ${invalidprograms.join(', ')}. run "cf --help" for a list of available commands.`);
log('');
}
}
*/
Expand Down
21 changes: 8 additions & 13 deletions src/lib/api/Userrating.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ora from 'ora';
import Table from 'cli-table2';
import chalk from 'chalk';
import qs from 'qs';
import has from 'has';
import forEach from 'lodash/forEach';
import * as contrib from 'blessed-contrib';
import blessed from 'blessed';
Expand Down Expand Up @@ -50,33 +51,28 @@ export default class Userrating {

if (err) {
spinner.fail();
logr('Failed [Request]');
return;
return logr('Failed [Request]');
}

if (response.statusCode !== 200) {
let {statusCode} = response;
if (statusCode !== 200) {
spinner.fail();
logr('Failed HTTP');
return;
return logr( has(body,'comment') ? body.comment : `HTTP Failed with status ${statusCode}`);
}

let contentType = response.headers['content-type'];
if (contentType.indexOf('application/json') === -1) {
spinner.fail();
logr('Failed.Not valid data.');
return;
return logr('Failed.Not valid data.');
}

if (body.status !== 'OK') {
spinner.fail();
logr(body.comment);
return;
return logr(body.comment);
}

spinner.succeed();

if ( self.noChart ) {

let table = new Table({
head: [CB('Contest'), CB('Rank'), CB('Rating change'), CB('New rating')]
});
Expand All @@ -90,8 +86,7 @@ export default class Userrating {
]);
});

log(table.toString());
return;
return log(table.toString());
}

let axisX = [];
Expand Down

0 comments on commit c8caaba

Please sign in to comment.