Skip to content

Commit

Permalink
Importing copyrights
Browse files Browse the repository at this point in the history
  • Loading branch information
jzongker committed Jan 28, 2025
1 parent 1a1e298 commit 82c6ac2
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 6 deletions.
25 changes: 25 additions & 0 deletions src/controllers/BibleController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,31 @@ export class BibleController extends ContentBaseController {
});
}

@httpGet("/updateCopyrights")
public async updateCopyrights(req: express.Request<{}, {}, null>, res: express.Response): Promise<interfaces.IHttpActionResult> {
return this.actionWrapperAnon(req, res, async () => {
const translations = await this.repositories.bibleTranslation.loadNeedingCopyrights();
for (const translation of translations) {
const copyright = await ApiBibleHelper.getCopyright(translation.sourceKey);
console.log(translation.name, copyright);
translation.copyright = copyright || "";
await this.repositories.bibleTranslation.save(translation);
}
return [];
});
}

@httpGet("/:translationKey/updateCopyright")
public async updateCopyright(@requestParam("translationKey") translationKey: string, req: express.Request<{}, {}, null>, res: express.Response): Promise<interfaces.IHttpActionResult> {
return this.actionWrapperAnon(req, res, async () => {
const copyright = await ApiBibleHelper.getCopyright(translationKey);
const bible = await this.repositories.bibleTranslation.loadBySourceKey("api.bible", translationKey);
bible.copyright = copyright || "";
await this.repositories.bibleTranslation.save(bible);
return bible;
});
}

@httpGet("/:translationKey/books")
public async getBooks(@requestParam("translationKey") translationKey: string, req: express.Request<{}, {}, null>, res: express.Response): Promise<interfaces.IHttpActionResult> {
return this.actionWrapperAnon(req, res, async () => {
Expand Down
21 changes: 19 additions & 2 deletions src/helpers/ApiBibleHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,44 @@ import axios from "axios";
import { Environment } from "./Environment";
import { BibleBook, BibleChapter, BibleTranslation, BibleVerse, BibleVerseText } from "../models";
import { ArrayHelper } from "@churchapps/apihelper";
import { parse } from "dotenv";

export class ApiBibleHelper {
static baseUrl: string = "https://api.scripture.api.bible/v1";
/*
static translationCopyrights: { [key: string]: string } = {
"a81b73293d3080c9-01": "Amplified® Bible Copyright © 2015 by The Lockman Foundation, La Habra, CA 90631 All rights reserved. http://www.lockman.org",
"e3f420b9665abaeb-01": "La Biblia de las Américas Copyright © 1986, 1995, 1997 by The Lockman Foundation Derechos Reservados All Rights Reserved",
"a761ca71e0b3ddcf-01": "NEW AMERICAN STANDARD BIBLE® NASB® Copyright © 1960, 1971, 1977,1995, 2020 by The Lockman Foundation A Corporation Not for Profit La Habra, CA All Rights Reserved www.lockman.org",
"b8ee27bcd1cae43a-01": "NEW AMERICAN STANDARD BIBLE® NASB® Copyright © 1960,1962,1963,1968,1971,1972,1973,1975,1977,1995 by The Lockman Foundation A Corporation Not for Profit La Habra, CA All Rights Reserved www.lockman.org",
"ce11b813f9a27e20-01": "Nueva Biblia de las Américas Copyright © 2005 by The Lockman Foundation La Habra, California 90631 Sociedad no comercial Derechos Reservados (All Rights Reserved) http://www.NuevaBiblia.com (Español) http://www.lockman.org (English) Versión de texto 2019 Texto derivado de La Biblia de las Américas © Copyright 1986, 1995, 1997 by The Lockman Foundation"
}*/

static async getCopyright(translationKey: string) {
const books = await ApiBibleHelper.getBooks(translationKey);
const verseKey = books[0].keyName + ".1.1";
const url = this.baseUrl + "/bibles/" + translationKey + "/verses/" + verseKey + "-" + verseKey + "?content-type=json&include-titles=false&include-verse-numbers=false";
const data = await this.getContent(url);
return data.data.copyright;
}

static async getTranslations() {
const result: BibleTranslation[] = [];
const url = this.baseUrl + "/bibles";
const data = await this.getContent(url);


data.data.forEach((d: any) => {
const translation: BibleTranslation = {
name: d.name,
nameLocal: d.nameLocal,
abbreviation: d.abbreviation,
description: d.description,
language: d.language.id,
source: "bible.api",
source: "api.bible",
sourceKey: d.id,
countryList: []
}
// copyright: this.translationCopyrights[d.id]


d.countries.forEach((c: any) => {
Expand Down
1 change: 1 addition & 0 deletions src/models/BibleTranslation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export class BibleTranslation {
public description?: string;
public countries?: string;
public countryList?: string[];
public copyright?: string;
}
16 changes: 12 additions & 4 deletions src/repositories/BibleTranslationRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ export class BibleTranslationRepository {
private async create(translation: BibleTranslation) {
translation.id = UniqueIdHelper.shortId();

const sql = "INSERT INTO bibleTranslations (id, abbreviation, name, nameLocal, description, source, sourceKey, language, countries) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);";
const params = [translation.id, translation.abbreviation, translation.name, translation.nameLocal, translation.description, translation.source, translation.sourceKey, translation.language, translation.countries];
const sql = "INSERT INTO bibleTranslations (id, abbreviation, name, nameLocal, description, source, sourceKey, language, countries, copyright) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
const params = [translation.id, translation.abbreviation, translation.name, translation.nameLocal, translation.description, translation.source, translation.sourceKey, translation.language, translation.countries, translation.copyright];
await DB.query(sql, params);
return translation;
}

private async update(translation: BibleTranslation) {
const sql = "UPDATE bibleTranslations SET abbreviation=?, name=?, nameLocal=?, description=?, source=?, sourceKey=?, language=?, countries=? WHERE id=?";
const params = [translation.abbreviation, translation.name, translation.nameLocal, translation.description, translation.source, translation.sourceKey, translation.language, translation.countries, translation.id];
const sql = "UPDATE bibleTranslations SET abbreviation=?, name=?, nameLocal=?, description=?, source=?, sourceKey=?, language=?, countries=?, copyright=? WHERE id=?";
const params = [translation.abbreviation, translation.name, translation.nameLocal, translation.description, translation.source, translation.sourceKey, translation.language, translation.countries, translation.copyright, translation.id];
await DB.query(sql, params);
return translation;
}
Expand All @@ -40,8 +40,16 @@ export class BibleTranslationRepository {
return DB.queryOne("SELECT * FROM bibleTranslations WHERE id=?;", [id]);
}

public loadBySourceKey(source: string, sourceKey: string) {
return DB.queryOne("SELECT * FROM bibleTranslations WHERE source=? and sourceKey=?;", [source, sourceKey]);
}

public loadAll() {
return DB.query("SELECT * FROM bibleTranslations order by name;", []);
}

public loadNeedingCopyrights() {
return DB.query("SELECT * FROM bibleTranslations where copyright is null;", []);
}

}
1 change: 1 addition & 0 deletions tools/dbScripts/bibleTranslations.mysql
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ CREATE TABLE `bibleTranslations` (
`sourceKey` varchar(45) DEFAULT NULL,
`language` varchar(45) DEFAULT NULL,
`countries` varchar(255) DEFAULT NULL,
`copyright` varchar(1000) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;

0 comments on commit 82c6ac2

Please sign in to comment.