Skip to content

Commit

Permalink
Add tag insertion to fimfic stats
Browse files Browse the repository at this point in the history
  • Loading branch information
SilkRose committed Mar 11, 2024
1 parent 9656593 commit 02dd1cc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions fimficstats/fimfic-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -171,6 +183,7 @@ function sleep(
interval: number,
): Promise<void> {
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));
Expand Down
12 changes: 12 additions & 0 deletions fimficstats/sql-patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 02dd1cc

Please sign in to comment.