npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

new-scraping

v0.0.1

Published

scraping application for Finciero

Downloads

1

Readme

Tasks Structure

'use strict';

var CONSTANTS, Classes, dependencies, taskName;

function helperFunction () {
}
// ...

Class = require('class');
// ...

CONSTANT1 = 'foo';
// ...

taskName = Yakuza.task('scraper', 'agent', 'taskName');

taskName.builder(function (job) {
  // ...
});

taskName.main(function (task, http, params) {
  var opts;
  
  loginFormOpts = http.optionsTemplate({
    'headers': LOGIN_HEADERS,
    'follow_max': 1
  });
  
  // Request: Request summary
  // ========================
  // Detailed explanation if necessary.
  // lorem ipsum dolor sit amet
  // ...
  http.get('FormRetrieval', opts.build({url: URL_FORM}), function (err, res, body) {
    var a, b, c;
    
    if (err) {
      task.fail(err, 'Request error');
    }
    
    // Parsing: Parsing explanation
    // ----------------------------
    try {
      // Parse account name
      superComplexOperation(/[a-b]+/g).match();
    } catch (error) {
      task.fail(error, 'Failed parsing form');
      return;
    }
    
    task.success(data);
  });
});

Handling Asyncrony

Lodash Loops

Stopping a loop

  
  // DO NOT DO
  _.each(collection, function (elem) {
    return false;
  });
  
  // Do this instead
  noErrors = _.every(collection, function (elem) {
    try {
      // .. Parsing
    } catch (error) {
      // .. Handle error
      return false;
    }
    return true;
  });
  
  if (!noErrors) {
    return;
  }
  
  // Wont reach this line if error happened

Handling asyncronous requests

  var promise1, promise2;
  
  getChecking = Q.defer();
  getCredit = Q.defer();
  
  // Request: Get Checking accounts
  // ==============================
  http.get(..., function (){
    // Parsing:
    try {
      // Parse stuff
      getChecking.resolve(result);
    catch (error) {
      getChecking.reject({error: error, message: 'Something happened'});
      return; 
    }
  });
  
  // Request: Get Credit accounts
  // ==============================
  http.get(..., function (){
    // Parsing:
    try {
      // Parse stuff
      getCredit.resolve(result);
    catch (error) {
      getCredit.reject({error: error, message: 'Something happened'});
      return; 
    }
  });
  
  Q.all([getChecking, getCredit]).then(function (results) {
    // results[0] => get checking results
    // results[1] => get credit results
    
    task.success(...);
  }, function (error) {
  
    task.fail(error.error, error.message);
  });

Directory structure

  • app.js
  • banks
    • bank1
      • login
        • login.task.js ...
      • bank1.agent.js Readme.md ... banks.scraper.js

Component declarations

  • Should always be CapitalizedCamelCase: SomeTask, SomeScraper

Documenting scrapers

  • Agents should have a Readme.md with details about the bank and important info/links etc.
  • Tasks should have exaplations for all requests unless they are extremely trivial
  • Tasks can have a general explanation, detailing how requests are made by the task.
  • Code which is not easily understood on its own should be preceeded with a comment that briefly explains it
  • Shares should be preceeded by a comment explaining why it is necessary and which tasks require the shared value
  • Parsing blocks should be explained in a preceeding comment block

Example:

// This awesome task handles tasking taskfulness, it is important to keep track of
// the awesomes received and re-send them to the awesome-receiver and bla bla bla
Yakuza.task('Scraper', 'Agent', 'Task').main(function (task, http, params) {
  var awesomeOpts;
  
  awesomeOpts = http.build({
    url: URL_AWESOME,
    data: {
      important: 'things'
    },
    follow_max: 1
  });
  
  // Request: send important things
  // ==============================
  // important things need to be sent to set important session cookies
  http.post(http.build(awesomeOpts, function (err, res, body) {
    
    // Parsing: retrieve important things
    // ----------------------------------
    // This parses important things and skips the last to rows so that nothing explodes and stuff
    try {
      // Replaces all letters with 'awesome' because why not
      body.replace(/[a-zA-Z]+/g, 'awesome');
    } catch (error) {
      // ...
    }
    
    // Share: Used by `FooTask` for its requests
    task.share('importantThings', body);
    
    task.success('hi');
  });
});