-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor into affiliation abstraction
- Loading branch information
Showing
7 changed files
with
70 additions
and
36 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Affiliation } from "../types"; | ||
|
||
const TRANCO_URL = "https://tranco-list.eu/download/KJ94W/1000000"; | ||
|
||
export default async function load(): Promise<Affiliation[]> { | ||
const response = await fetch(TRANCO_URL); | ||
const data = await response.text(); | ||
const lines = data.split('\n').filter(line => line.trim() !== '').map(line => line.split(',')); | ||
return lines.map(([rank, domain]) => ({ | ||
identifier: domain, | ||
metadata: { | ||
rank: rank, | ||
}, | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { XMLParser } from "fast-xml-parser"; | ||
import { Affiliation } from "../types"; | ||
|
||
const SITEMAP_URL = "https://www.ycombinator.com/companies/sitemap.xml"; | ||
|
||
export default async function load(): Promise<Affiliation[]> { | ||
const response = await fetch(SITEMAP_URL); | ||
const data = await response.text(); | ||
const parser = new XMLParser(); | ||
const result = parser.parse(data); | ||
const relevantURLs = result.urlset.url.filter((url: { loc: string }) => url.loc.endsWith(".com") && !url.loc.includes("/industry/")); | ||
const affiliations: Affiliation[] = []; | ||
for (const url of relevantURLs) { | ||
try { | ||
const companyResponse = await fetch(url.loc); | ||
const companyHtml = await companyResponse.text(); | ||
const hrefMatch = companyHtml.match(/href="([^"]*)"[^>]*class="[^"]*mb-2[^"]*whitespace-nowrap[^"]*"/); | ||
|
||
if (hrefMatch && hrefMatch[1]) { | ||
affiliations.push({ | ||
identifier: hrefMatch[1], | ||
metadata: { | ||
source: 'ycombinator', | ||
originalUrl: url.loc | ||
} | ||
}); | ||
} | ||
} catch (error) { | ||
console.error(`Error fetching ${url.loc}:`, error); | ||
} | ||
} | ||
|
||
return affiliations; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import tranco from "./loaders/tranco"; | ||
import { Affiliation } from "./types"; | ||
|
||
type RegisteredAffiliation = { | ||
identifier: string; | ||
name: string; | ||
load: () => Promise<Affiliation[]>; | ||
}; | ||
|
||
export const REGISTRY: { [key in string]: RegisteredAffiliation } = { | ||
"tranco": { | ||
identifier: "tranco", | ||
name: "Tranco", | ||
load: tranco, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export type Affiliation = { | ||
identifier: string; | ||
metadata: Record<string, string>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters