Skip to content

Commit

Permalink
chore: add author_madeinnigeria and author_link_madeinnigeria columns
Browse files Browse the repository at this point in the history
  • Loading branch information
rotimi-best committed Dec 3, 2024
1 parent c25272c commit 36ecdc4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
21 changes: 19 additions & 2 deletions utils/scrape/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ const fetchDataFromGithub = async (
description: apiData.description || '',
author: apiData.owner.login,
author_link: apiData.owner.html_url,

// Let's store the author's name and link from the scraped data
author_madeinnigeria: repository.author,
author_link_madeinnigeria: repository.authorLink,

author_avatar: apiData.owner.avatar_url,
stars: apiData.watchers_count || 0,
topics: apiData.topics || [],
Expand Down Expand Up @@ -80,9 +85,15 @@ function convertToJSON(repositories: string[]): ScrapedRepository[] {
const name = doc.querySelector('a')?.textContent?.trim() || '';
const link = doc.querySelector('a')?.getAttribute('href') || '';

const author = doc.querySelector('strong a')?.textContent?.trim() || '';
const authorLink =
doc.querySelector('strong a')?.getAttribute('href') || '';

return {
name,
link,
author,
authorLink,
};
});
}
Expand Down Expand Up @@ -133,7 +144,9 @@ const getData = async () => {
archived,
disabled,
original_created_at,
original_updated_at
original_updated_at,
author_madeinnigeria,
author_link_madeinnigeria
) VALUES (
${repo.name},
${repo.link},
Expand All @@ -149,11 +162,15 @@ const getData = async () => {
${repo.archived},
${repo.disabled},
${repo.original_created_at},
${repo.original_updated_at}
${repo.original_updated_at},
${repo.author_madeinnigeria},
${repo.author_link_madeinnigeria}
)
ON CONFLICT (link) DO UPDATE
SET
stars = EXCLUDED.stars,
author_madeinnigeria = EXCLUDED.author_madeinnigeria,
author_link_madeinnigeria = EXCLUDED.author_link_madeinnigeria,
forks = EXCLUDED.forks,
open_issues_count = EXCLUDED.open_issues_count,
original_updated_at = EXCLUDED.original_updated_at,
Expand Down
6 changes: 6 additions & 0 deletions utils/types/repository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export interface ScrapedRepository {
name: string;
link: string;

author: string;
authorLink: string;
}

export interface DBRepository {
Expand All @@ -11,6 +14,9 @@ export interface DBRepository {
author_link: string;
author_avatar: string;

author_madeinnigeria: string;
author_link_madeinnigeria: string;

stars: number;
topics: string[];
license: {
Expand Down

0 comments on commit 36ecdc4

Please sign in to comment.