Skip to content

Commit

Permalink
Add author insertion to fimfic stats
Browse files Browse the repository at this point in the history
  • Loading branch information
SilkRose committed Mar 9, 2024
1 parent b6b0bc5 commit ec3ae0c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions fimficstats/fimfic-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ async function mane() {
}

const api = api_schema.parse(api_json);
//console.dir(api, { depth: null });

db.query(
sql.insert_author(
Number(api.data.relationships.author.data.id),
api.included[0].attributes.name,
new Date(api.included[0].attributes.date_joined).getTime() / 1000,
api.included[0].attributes.num_followers,
api.included[0].attributes.num_blog_posts,
),
).run();

// Load the HTML with Cheerio.
const document = cheerio.load(stats_html);
Expand Down
11 changes: 11 additions & 0 deletions fimficstats/sql-patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ export const authors_table = `CREATE TABLE IF NOT EXISTS Authors (
blogs integer NOT NULL
)`;

export function insert_author(
id: number,
name: string,
date_joined: number,
followers: number,
blogs: number,
) {
return `INSERT OR IGNORE INTO Authors (id, name, date_joined, followers, blogs)
VALUES (${id}, '${name}', ${date_joined}, ${followers}, ${blogs})`;
}

export const stories_table = `CREATE TABLE IF NOT EXISTS Stories (
id integer PRIMARY KEY,
title text NOT NULL,
Expand Down

0 comments on commit ec3ae0c

Please sign in to comment.