0.0.1-alpha.13 • Published 7 years ago

hockeybar v0.0.1-alpha.13

Weekly downloads
1
License
GPL-3.0
Repository
github
Last release
7 years ago

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));
0.0.1-alpha.13

7 years ago

0.0.1-alpha.12

7 years ago

0.0.1-alpha.11

7 years ago

0.0.1-alpha.10

7 years ago

0.0.1-alpha.9

7 years ago

0.0.1-alpha.8

7 years ago

0.0.1-alpha.7

7 years ago

0.0.1-alpha.6

7 years ago

0.0.1-alpha.5

7 years ago

0.0.1-alpha.4

7 years ago

0.0.1-alpha.3

7 years ago

0.0.1-alpha.2

7 years ago

0.0.1-alpha.1

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago