Coder Social home page Coder Social logo

kodie / stack-fanatic Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 131 KB

A node module that uses Google's Puppeteer library to visit your Stack Overflow profile and check the progress of the badge you are currently tracking.

License: MIT License

JavaScript 100.00%
badges badge stackoverflow stackexchange stack-overflow nodejs node-js node node-module puppeteer google profile

stack-fanatic's Introduction

Stack Fanatic

npm package version Travis build status npm package downloads code style license

A node module that uses Google's Puppeteer library to visit your Stack Overflow profile and check the progress of the badge you are currently tracking.

Installation

npm install stack-fanatic

Usage

Options

The following options can be passed to any functions (however none of them are required):

  • debug - A boolean stating wether or not debugging information should be displayed in the console (Default: false)

  • loginEmail - A string containing the email address asssociated with the StackOverflow account that you would like to log in to.

  • loginPassword - A string containing the password for the StackOverflow account that you would like to log in to.

  • puppeteerOpts - An object containing any options you wish to pass to the puppeteer.launch() function. (Sets the user agent to Google Chrome and the user data directory to ./userData by default)

  • site - A string containing the URL for the Stack Exchange site that you would like to pull badge info from. Should include the protocol at the beginning and no trailing slash. (Default: https://stackoverflow.com)

check(options)

Visits your StackOverflow profile page and returns a promise that resolves with information about your tracked badge.

Note: The login function will automatically be ran if loginEmail and loginPassword are passed as options and you are not currently logged in.

const stackFanatic = require('stack-fanatic')

stackFanatic
  .check({
    loginEmail: '[email protected]',
    loginPassword: 'password1234',
    site: 'https://stackoverflow.com'
  })
  .then(res => {
    console.log('Badge Name:', res.badge)
    console.log('Badge Type:', res.type)
    console.log('Current Progress:', res.now)
    console.log('Percent Completed:', res.percent)
  })
  .catch(err => {
    console.log(err.message)
  })

Example Response

{
  badge: 'Fanatic',
  max: 100,
  min: 0,
  now: 20,
  percent: 20,
  profile: 'https://stackoverflow.com/users/5463842/kodie-grantham',
  type: 'Gold'
}

login(options)

Logs into a StackOverflow account and returns a promise that resolves with true or false depending on if the login was successful or not.

Note: After you are logged in, your session info will be saved in ./userData so that you can run the check function without having to log in again.

const stackFanatic = require('stack-fanatic')

stackFanatic
  .login({
    loginEmail: '[email protected]',
    loginPassword: 'password1234'
  })
  .then(loggedIn => {
    if (loggedIn) {
      console.log('Yay! You are logged in! :D')
    } else {
      console.log('Aw dang! You are not logged in. :(')
    }
  })
  .catch(err => {
    console.log(err.message)
  })

Tips/Tricks

Check badge progress without logging in

Just set site to the URL of your Stack Overflow profile and make sure that you have ?tab=topactivity at the end of it.

While you're at it, set Puppeteer's userDataDir option to false so that no session data or cache is saved.

stackFanatic
  .check({
    site: 'https://stackoverflow.com/users/5463842/kodie-grantham?tab=topactivity',
    puppeteerOpts: {
      userDataDir: false
    }
  })

Related

License

MIT. See the LICENSE file for more info.

stack-fanatic's People

Contributors

kodie avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.