Skip to content

Commit

Permalink
Fixes #24 Apply Code Quality Checks
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverspryn committed May 20, 2019
1 parent 2afec13 commit 5a899ee
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 62 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Indexer

[![Build Status](https://dev.azure.com/branham-player/indexer/_apis/build/status/branham-player.indexer%20(1)?branchName=develop)](https://dev.azure.com/branham-player/indexer/_build/latest?definitionId=3&branchName=develop)
[![Build Status](https://dev.azure.com/branham-player/indexer/_apis/build/status/branham-player.indexer?branchName=develop)](https://dev.azure.com/branham-player/indexer/_build/latest?definitionId=2&branchName=develop) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/ec56f20e947048bfa625922e210fe0fb)](https://www.codacy.com/app/branham-player/indexer?utm_source=github.com&utm_medium=referral&utm_content=branham-player/indexer&utm_campaign=Badge_Grade)

A parser which indexes unstructured collections of data representing William Branham's complete sermon library and structures them for loading into a data ingester.

This project is part of a three-part system which collectively stores, indexes, and then outputs a collection of sermons as JSON files:

1. [Original Sources](https://github.com/branham-player/original-sources): Sermon metadata from various online data sources
1. **[Indexer](https://github.com/branham-player/indexer): This project, takes the information from the above source and processes it as output into the next source**
1. [Golden Dataset](https://github.com/branham-player/golden-dataset): JSON files which are generated by the indexer and manually uploaded to the repository
1. [Original Sources](https://github.com/branham-player/original-sources): Sermon metadata from various online data sources
2. **[Indexer](https://github.com/branham-player/indexer): This project, takes the information from the above source and processes it as output into the next source**
3. [Golden Dataset](https://github.com/branham-player/golden-dataset): JSON files which are generated by the indexer and manually uploaded to the repository

## Run this Project

Expand All @@ -25,6 +25,6 @@ npm run all

The result of a successful execution is the presence of three new files in the root folder:

- `full.json`: A complete dataset which contains all of the information the program could gather from the original sources
- `condensed.json`: A shortened version of the `full.json` file which contains the most essential pieces of information for the everyday user
- `months.json`: Counts the number of years and months which are present in `full.json`
- `full.json`: A complete dataset which contains all of the information the program could gather from the original sources
- `condensed.json`: A shortened version of the `full.json` file which contains the most essential pieces of information for the everyday user
- `months.json`: Counts the number of years and months which are present in `full.json`
2 changes: 1 addition & 1 deletion constants/DateConstants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default class DateConstants {
// region Date Formatting

static get DAY_MISSING() {
return 'MMMM[,] YYYY'
return 'MMMM[,] YYYY';
}

static get FULL_DATE() {
Expand Down
2 changes: 1 addition & 1 deletion database.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import SpokenWordChurch from './sources/SpokenWordChurch.mjs';

const args = process.argv;

if (args.length != 5) {
if (args.length !== 5) {
console.error('Expected two arguments: <path to original sermons> <full database output file name> <condensed database output file name>');
process.exit(1);
}
Expand Down
4 changes: 2 additions & 2 deletions formatters/ArtworkFormatter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export default class ArtworkFormatter {
}

return {
"large": `https://cloudinary-a.akamaihd.net/branham-player/image/upload/c_fill,e_tint:30:black,g_center,h_${large},w_${large}/l_artwork:1:intermediate,o_50,g_center,h_${large},w_${large}/l_artwork:1:months:${month},g_center,h_${large},w_${large}/l_artwork:1:years:${year},g_center,h_${large},w_${large}/artwork/1/backgrounds/${year}/${month}.jpg`,
"thumbnail": `https://cloudinary-a.akamaihd.net/branham-player/image/upload/c_fill,e_tint:30:black,g_center,h_${thumbnail},w_${thumbnail}/l_artwork:1:intermediate,o_50,g_center,h_${thumbnail},w_${thumbnail}/l_artwork:1:months:${month},g_center,h_${thumbnail},w_${thumbnail}/l_artwork:1:years:${year},g_center,h_${thumbnail},w_${thumbnail}/artwork/1/backgrounds/${year}/${month}.jpg`
'large': `https://cloudinary-a.akamaihd.net/branham-player/image/upload/c_fill,e_tint:30:black,g_center,h_${large},w_${large}/l_artwork:1:intermediate,o_50,g_center,h_${large},w_${large}/l_artwork:1:months:${month},g_center,h_${large},w_${large}/l_artwork:1:years:${year},g_center,h_${large},w_${large}/artwork/1/backgrounds/${year}/${month}.jpg`,
'thumbnail': `https://cloudinary-a.akamaihd.net/branham-player/image/upload/c_fill,e_tint:30:black,g_center,h_${thumbnail},w_${thumbnail}/l_artwork:1:intermediate,o_50,g_center,h_${thumbnail},w_${thumbnail}/l_artwork:1:months:${month},g_center,h_${thumbnail},w_${thumbnail}/l_artwork:1:years:${year},g_center,h_${thumbnail},w_${thumbnail}/artwork/1/backgrounds/${year}/${month}.jpg`
};
}
}
2 changes: 1 addition & 1 deletion formatters/AudioFormatter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class AudioFormatter {

return {
insecure: this.audioUrl,
secure: secure
secure
};
}
}
8 changes: 4 additions & 4 deletions formatters/BuildingFormatter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class BuildingFormatter {
}

format() {
if (this.buildingName == '' || this.buildingName.toLowerCase() == 'unknown') {
if (this.buildingName === '' || this.buildingName.toLowerCase() === 'unknown') {
return {
displayName: 'Unknown Location',
givenName: this.buildingName,
Expand All @@ -20,12 +20,12 @@ export default class BuildingFormatter {
// Edge case: 51-0714
let displayName = title(this.buildingName);

if (displayName.toUpperCase().indexOf("IMA") != -1) {
displayName = displayName.replace("Ima", "IMA")
if (displayName.toUpperCase().indexOf('IMA') !== -1) {
displayName = displayName.replace('Ima', 'IMA');
}

return {
displayName: displayName,
displayName,
givenName: this.buildingName,
known: true
};
Expand Down
34 changes: 17 additions & 17 deletions formatters/DateFormatter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ export default class DateFormatter {
modifier = {
meaning: modifier.meaning,
symbol: modifier.symbol
}
};
}

return {
assumptions: assumptions,
assumptions,
date: determinedDate,
displayName: displayName,
displayName,
givenDate: this.givenDate,
known: assumptions == null,
modifier: modifier
modifier
};
}

Expand All @@ -51,30 +51,30 @@ export default class DateFormatter {
const givenDay = parseInt(this.givenDate.substr(5, 2));

// Edge cases: 48-0000, 53-0500
if (givenMonthIndex == -1 && givenDay == 0) {
if (givenMonthIndex === -1 && givenDay === 0) {
return {
day: {
assumedDay: 1,
givenDay: givenDay
givenDay
},
month: {
assumedMonthIndex: 0,
givenMonthIndex: givenMonthIndex
givenMonthIndex
}
};
} else if (givenMonthIndex == -1) {
} else if (givenMonthIndex === -1) {
return {
day: null,
month: {
assumedMonthIndex: 0,
givenMonthIndex: givenMonthIndex
givenMonthIndex
}
};
} else if (givenDay == 0) {
} else if (givenDay === 0) {
return {
day: {
assumedDay: 1,
givenDay: givenDay
givenDay
},
month: null
};
Expand All @@ -88,14 +88,14 @@ export default class DateFormatter {
let monthIndex = parseInt(this.givenDate.substr(3, 2)) - 1;

// When only the year is known, the month is given as "00"
if (monthIndex == -1) {
if (monthIndex === -1) {
monthIndex = 0;
}

let day = parseInt(this.givenDate.substr(5, 2));

// When only the month and year are known, the day is given as "00"
if (day == 0) {
if (day === 0) {
day = 1;
}

Expand All @@ -107,21 +107,21 @@ export default class DateFormatter {
const matches = pattern.exec(this.givenDate.toUpperCase());

if (matches != null) {
const symbol = matches.toString();
let symbol = matches.toString();

// Some places use "W" for wedding ceremonies, but Branham.org does not,
// which is our source of truth, so map them to "X", as it does
if (symbol == 'W') {
if (symbol === 'W') {
symbol = 'X';
}

const displayName = DateConstants.MODIFIER_FOR_DISPLAY_NAME[symbol];
const modifer = DateConstants.MODIFIERS[symbol];

return {
displayName: displayName,
displayName,
meaning: modifer,
symbol: symbol
symbol
};
}

Expand Down
28 changes: 14 additions & 14 deletions formatters/LocationFormatter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class LocationFormatter {

format() {
// Edge cases: 48-0000, 53-0500, 58-0500
if (this.location.toLowerCase() == LocationConstants.NEW_ENGLAND_AREA.toLowerCase()) {
if (this.location.toLowerCase() === LocationConstants.NEW_ENGLAND_AREA.toLowerCase()) {
return {
city: null,
country: {
Expand All @@ -26,8 +26,8 @@ export default class LocationFormatter {
givenName: this.location,
known: false,
state: null
}
} else if (this.location.toLowerCase() == LocationConstants.UNKNOWN.toLowerCase() || this.location == '') {
};
} else if (this.location.toLowerCase() === LocationConstants.UNKNOWN.toLowerCase() || this.location === '') {
return {
city: null,
country: null,
Expand All @@ -52,21 +52,21 @@ export default class LocationFormatter {
}

return {
city: city,
country: country,
city,
country,
displayName: formattedName,
givenName: this.location,
known: city != null,
state: state
}
state
};
}

getCity() {
const parts = this.sanitizedLocation.split(' ');
const presumedCity = parts.slice(0, parts.length - 1).join(' ');

// Edge case: 55-0400
if (presumedCity.toLowerCase() == LocationConstants.CANADA_PROVINCES['AB'].toLowerCase()) {
if (presumedCity.toLowerCase() === LocationConstants.CANADA_PROVINCES['AB'].toLowerCase()) {
return null;
}

Expand All @@ -80,18 +80,18 @@ export default class LocationFormatter {

// Canadaian territories and US states are always abbreviated to two
// letters, like 'PA' or 'AB'
if (presumedStateOrTerritory.length == 2) {
if (presumedStateOrTerritory.length === 2) {
if (LocationConstants.US_STATES.hasOwnProperty(stateOrTerritory)) {
return LocationConstants.UNITED_STATES;
} else if (LocationConstants.CANADA_PROVINCES.hasOwnProperty(stateOrTerritory)) {
return LocationConstants.CANADA;
}
} else {
if (stateOrTerritory == LocationConstants.GERMANY.name.toUpperCase()) {
if (stateOrTerritory === LocationConstants.GERMANY.name.toUpperCase()) {
return LocationConstants.GERMANY;
} else if (stateOrTerritory == LocationConstants.SWITZERLAND.name.toUpperCase()) {
} else if (stateOrTerritory === LocationConstants.SWITZERLAND.name.toUpperCase()) {
return LocationConstants.SWITZERLAND;
} else if (stateOrTerritory == LocationConstants.CANADA.name.toUpperCase()) {
} else if (stateOrTerritory === LocationConstants.CANADA.name.toUpperCase()) {
return LocationConstants.CANADA;
}
}
Expand All @@ -104,7 +104,7 @@ export default class LocationFormatter {
const presumedStateOrTerritory = parts[parts.length - 1];

// Edge case: 55-0400
if (parts[0].toLowerCase() == LocationConstants.CANADA_PROVINCES['AB'].toLowerCase()) {
if (parts[0].toLowerCase() === LocationConstants.CANADA_PROVINCES['AB'].toLowerCase()) {
const stateOrTerritory = 'AB';

return {
Expand All @@ -115,7 +115,7 @@ export default class LocationFormatter {

// Canadaian territories and US states are always abbreviated to two
// letters, like 'PA' or 'AB'
if (presumedStateOrTerritory.length == 2) {
if (presumedStateOrTerritory.length === 2) {
const stateOrTerritory = presumedStateOrTerritory.toUpperCase();

if (LocationConstants.US_STATES.hasOwnProperty(stateOrTerritory)) {
Expand Down
4 changes: 2 additions & 2 deletions months.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fs from 'fs';

const args = process.argv;

if (args.length != 4) {
if (args.length !== 4) {
console.error('Expected two arguments: <path to full database JSON file> <output file name>');
process.exit(1);
}
Expand All @@ -23,6 +23,6 @@ for (let index in json) {
const months = Object.keys(monthDictionary);

fs.writeFileSync(outputFileName, JSON.stringify({
months: months,
months,
total: months.length
}, null, 4));
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "database.mjs",
"scripts": {
"all": "npm run database && npm run months",
"database": "node --experimental-modules database.mjs ../original-sources/ ./full.json ./condensed.json",
"database": "node --experimental-modules database.mjs ../original-sources ./full.json ./condensed.json",
"months": "node --experimental-modules months.mjs ./full.json ./months.json"
},
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion printers/CondensedDatabasePrinter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class CondensedDatabasePrinter {
}

print() {
const masterArary = Object.keys(this.masterIndex).map(key => {
const masterArary = Object.keys(this.masterIndex).map((key) => {
const entry = this.masterIndex[key];

return {
Expand Down
2 changes: 1 addition & 1 deletion printers/FullDatabasePrinter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class FullDatabasePrinter {
}

print() {
const masterArary = Object.keys(this.masterIndex).map(key => {
const masterArary = Object.keys(this.masterIndex).map((key) => {
return this.masterIndex[key];
});

Expand Down
12 changes: 6 additions & 6 deletions sources/BranhamOrg.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import cheerio from 'cheerio';
import fs from 'fs';

import AudioFormatter from '../formatters/AudioFormatter.mjs'
import AudioFormatter from '../formatters/AudioFormatter.mjs';
import DateFormatter from '../formatters/DateFormatter.mjs';
import IDFormatter from '../formatters/IDFormatter.mjs';
import LocationFormatter from '../formatters/LocationFormatter.mjs';
Expand Down Expand Up @@ -37,7 +37,7 @@ export default class BranhamOrg {
const idFormatter = new IDFormatter(date);

// Edge case: 62-1030X
if (audioUrl != undefined && audioUrl != '') {
if (audioUrl !== undefined && audioUrl !== '') {
const audioFormatter = new AudioFormatter(audioUrl);

this.addToMasterIndex(
Expand Down Expand Up @@ -66,10 +66,10 @@ export default class BranhamOrg {

this.masterIndex[key] = {
id: key,
audio: audio,
date: date,
location: location,
title: title
audio,
date,
location,
title
};
}
}
4 changes: 2 additions & 2 deletions sources/Cloudinary.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class Cloudinary {
return;
}

console.log(`Unmatched sermon: ${key} ${artwork.large}`)
throw new Error()
console.log(`Unmatched sermon: ${key} ${artwork.large}`);
throw new Error();
}
}
4 changes: 2 additions & 2 deletions sources/SpokenWordChurch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class SpokenWordChurch {
return;
}

console.log(`Unmatched sermon: ${key} ${building.givenName}`)
throw new Error()
console.log(`Unmatched sermon: ${key} ${building.givenName}`);
throw new Error();
}
}

0 comments on commit 5a899ee

Please sign in to comment.