nl_tokens: check Twitter rate limit status https : // developer . twitter . com / en / docs / developer - utilities / rate - limit - status / api - reference / get - application - rate_limit_status rate limit : 900calls / 15min
pl_tokens: function checkTwitterRateLimit ( need ) { _twitterAPIIndex = ( _twitterAPIIndex + 1 ) % twitterAPIs . <mask> ; let twitterAPI = twitterAPIs [ _twitterAPIIndex ] ; let which = twitterAPIs . length > 1 ? ( ' ' + ( _twitterAPIIndex + 1 ) ) : '' ; return twitterAPI . get ( 'application/rate_limit_status' , { resources : 'users' } ) . then ( result => { let now = Date . now ( ) / 1000 ; let stats = result . resources . users [ '/users/show/:id' ] ; let resetSec = Math . ceil ( stats . reset - now ) + 30 ; // +30sec in case server time is different console . log ( colors . green . bold ( ` ${ which } ${ need } ${ stats . remaining } ${ resetSec } ` ) ) ; if ( need > stats . remaining ) { let delaySec = clamp ( resetSec , 10 , 60 ) ; console . log ( colors . blue ( ` ${ delaySec } ` ) ) ; return delaySec ; } else { return 0 ; } } ) . then ( sec => { if ( sec > 0 ) { return delay ( sec * 1000 ) . then ( ( ) => checkTwitterRateLimit ( need ) ) ; } else { return Promise . resolve ( ) ; } } ) . catch ( e => { console . error ( colors . red ( ` ` + JSON . stringify ( e ) ) ) } ) ; }