diff --git a/fimficstats/fimfic-stats.ts b/fimficstats/fimfic-stats.ts index 0de129d..80c95a6 100644 --- a/fimficstats/fimfic-stats.ts +++ b/fimficstats/fimfic-stats.ts @@ -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); diff --git a/fimficstats/sql-patterns.ts b/fimficstats/sql-patterns.ts index 346f291..5de3d82 100644 --- a/fimficstats/sql-patterns.ts +++ b/fimficstats/sql-patterns.ts @@ -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,