hockeybar

0.0.1-alpha.13 • Public • Published

Installation

# move to a your project directory 
cd your-project/
 
# install HockeyBar 
npm i -S hockeybar
 
# require HockeyBar 
const HockeyBar = require('hockeybar');

Quick Start

 
# read sidebar template from a source (github, file system, etc) 
const fs = require('fs');
const sidebarTemplate = fs.readFileSync('sidebar.md''utf8');
 
# instantiate HockeyBar with team name, reddit authentication options (Snoowrap), and template 
var hb = new HockeyBar(
    'anaheim-ducks'
    , {
        clientId: process.env.CLIENT_ID,
        clientSecret: process.env.CLIENT_SECRET,
        userId: process.env.REDDIT_USER,
        userPassword: process.env.REDDIT_PASS,
        subreddit: process.env.SUBREDDIT
    }
    , sidebarTemplate);
 
# fetch data, build the markdown, update the template, and update the sidebar. 
var currentDate = new Date();
 
hb.fetchTeamSchedule()
    .then((data) => hb.asMarkdown(data))
    .then((markdown) => hb.updateTemplate('***TEAM_SCHEDULE***', markdown))
    .then(() => hb.fetchTeamSkaters())
    .then((data) => hb.asMarkdown(data))
    .then((markdown) => hb.updateTemplate('***TEAM_STATS***', markdown))
    .then(() => hb.fetchTeamGoalies())
    .then((data) => hb.asMarkdown(data))
    .then((markdown) => hb.updateTemplate('***GOALIE_STATS***', markdown))
    .then(() => hb.fetchDivisionStats())
    .then((data) => hb.asMarkdown(data))
    .then((markdown) => hb.updateTemplate('***DIV_STATS***', markdown))
    .then(() => hb.fetchConferenceStats())
    .then((data) => hb.asMarkdown(data))
    .then((markdown) => hb.updateTemplate('***CONF_STATS***', markdown))
    .then(() => hb.updateTemplate('***LAST_UPDATED***'`Last Updated: ${currentDate.toDateString()} at ${currentDate.toTimeString()}`))
    .then(() => hb.updateRedditSidebar())
    .then(() => console.log(hb.sidebarTemplate));

Advanced Usage

Overriding the default markdown generation

    hb.fetchTeamSchedule()
    .then((data) => hb.asMarkdown(data, () => {
        var buildEventMarkdown = (event) => {
            var markdown = `\n* ${event.isHome ? '[Home](#HOMEGAME)' : '[Away](#AWAYGAME)'}[${event.date} @ ${event.time}](#TIME)[Network: ${event.network}](#NETWORK)[${!event.isHome ? process.env.HOME_TEAM : event.opponent.abv} vs. ${event.isHome ? process.env.HOME_TEAM : event.opponent.abv}](#VS)[${process.env.HOME_TEAM} (0)](#HOMESCORE)[${event.opponent.abv} (0)](#AWAYSCORE)`;
            return markdown;
        };
        var eventMarkdown = '';
        for (var i = 0; i < data.length; i++) {
            eventMarkdown = eventMarkdown + buildEventMarkdown(data[i]);
        }
        return eventMarkdown;
    }))
    .then((markdown) => hb.updateTemplate('***TEAM_SCHEDULE***', markdown))
    .then(() => console.log(hb.sidebarTemplate));

Loading markdown from a subreddit wiki page

hb.loadSidebarTemplateFromReddit('sidebar')
    .then(() => fetchTeamSchedule())
    .then((data) => hb.asMarkdown(data))
    .then((markdown) => hb.updateTemplate('***TEAM_SCHEDULE***', markdown))
    .then(() => console.log(hb.sidebarTemplate));

Package Sidebar

Install

npm i hockeybar

Weekly Downloads

1

Version

0.0.1-alpha.13

License

GPL-3.0

Last publish

Collaborators

  • space0wl