diff --git a/fimficstats/fimfic-stats.ts b/fimficstats/fimfic-stats.ts index 8af5d91..bc351f0 100644 --- a/fimficstats/fimfic-stats.ts +++ b/fimficstats/fimfic-stats.ts @@ -161,6 +161,18 @@ async function mane() { ), ).run(); + tags.forEach((tag) => { + db.query( + sql.insert_tag( + tag.id, + tag.title, + tag.type.replace("tag-", ""), + tag.text, + tag.href.replace("/tag/", ""), + ), + ).run(); + }); + await sleep(start_time, Date.now(), request_interval); } } @@ -171,6 +183,7 @@ function sleep( interval: number, ): Promise { const elapsed_time = current_time - start_time; + console.log(elapsed_time); if (elapsed_time > interval) return Promise.resolve(); const remaining_time = interval - elapsed_time; return new Promise((res) => setTimeout(res, remaining_time)); diff --git a/fimficstats/sql-patterns.ts b/fimficstats/sql-patterns.ts index 934a2e6..b407f7d 100644 --- a/fimficstats/sql-patterns.ts +++ b/fimficstats/sql-patterns.ts @@ -109,12 +109,24 @@ export const tags_table = `CREATE TABLE IF NOT EXISTS Tags ( href text NOT NULL )`; +export function insert_tag( + id: number, + title: string, + type: string, + text: string, + href: string, +) { + return `INSERT OR IGNORE INTO Tags (id, title, type, text, href) + VALUES (${id}, '${title}', '${type}', '${text}', '${href}')`; +} + export const tag_links_table = `CREATE TABLE IF NOT EXISTS Tags_links ( story_id integer, tag_id integer, CONSTRAINT tag_links_story_id_fk FOREIGN KEY (story_id) REFERENCES Stories (id), + CONSTRAINT tag_links_tag_id_fk FOREIGN KEY (tag_id) REFERENCES Tags (id),