Skip to content

Instantly share code, notes, and snippets.

@jonschlinkert
Created January 6, 2021 03:29
Show Gist options
  • Select an option

  • Save jonschlinkert/8d4160d278bf075de33c2f8717733664 to your computer and use it in GitHub Desktop.

Select an option

Save jonschlinkert/8d4160d278bf075de33c2f8717733664 to your computer and use it in GitHub Desktop.

Revisions

  1. jonschlinkert created this gist Jan 6, 2021.
    37 changes: 37 additions & 0 deletions download-ballots.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    'use strict';

    const download = require('download');

    /**
    * Download all ballots
    */

    const dl = async (baseurl, dest) => {
    const pending = [];
    let finished = 0;

    for (let index = 1; index < 1326; index++) {
    const promise = download(baseurl.replace(/%n/, index), dest).then(() => {
    process.stdout.write(`\rDownloaded ${(++finished).toLocaleString()}`);
    pending.splice(pending.indexOf(promise), 1);
    });

    pending.push(promise);

    if (pending.length >= 100) {
    await Promise.all(pending);
    }
    }
    };

    /**
    * Usage
    */

    // define the desination directory
    const dest = 'replace_with_absolute_path_to_dest_directory';

    dl('https://apps.alleghenycounty.us/website/PDF_GEN/GEN%20(%n).pdf', dest)
    .then(() => {
    console.log('\nDone!');
    });