Skip to content

Instantly share code, notes, and snippets.

@Celeo
Last active September 18, 2022 23:19
Show Gist options
  • Save Celeo/9e6e0fe5edf33bca26a5b592685935b9 to your computer and use it in GitHub Desktop.
Save Celeo/9e6e0fe5edf33bca26a5b592685935b9 to your computer and use it in GitHub Desktop.

Run via deno run --allow-net zla_membership_data.ts.

Take the results and put them into Excel / Google Sheets / etc.

import {
getUserRatings,
getInstance,
getV3Data,
UserRatingsSimple,
} from "https://deno.land/x/vatsim_wrapper@v0.2.0/mod.ts";
import { parse, HTMLElement } from "https://esm.sh/node-html-parser@5.3.3";
export interface Member {
name: string;
cid: number;
}
export async function getZlaMembers(): Promise<Array<Member>> {
const resp = await fetch("https://laartcc.org/roster");
if (resp.status !== 200) {
throw new Error(`Got status ${resp.status} from ZLA members site`);
}
const root = parse(await resp.text());
const rows = root.querySelector("#roster")?.querySelectorAll("tr") ?? [];
return rows
.map((row) => row.querySelector("a"))
.filter((link): link is HTMLElement => link !== null)
.map((link) => {
const name = link.innerHTML;
const cid = parseInt(link.getAttribute("href")!.split("/")[4]);
return { name, cid };
});
}
async function main(): Promise<void> {
const members = await getZlaMembers();
const vatsim = await getInstance();
const v3Data = await getV3Data(vatsim);
const counter: Record<string, number> = {
OBS: 0,
S1: 0,
S2: 0,
S3: 0,
C1: 0,
C2: 0,
C3: 0,
I1: 0,
I2: 0,
I3: 0,
SUP: 0,
ADM: 0,
};
function updateCounter(data: UserRatingsSimple): void {
const matching = v3Data.ratings.find(
(rating) => rating.id === data.rating
)!;
if (matching.short in counter) {
counter[matching.short] += 1;
}
}
for (const member of members) {
console.log(`Checking ${member.name}`);
updateCounter(await getUserRatings(member.cid));
await new Promise((resolve) => setTimeout(resolve, 250));
}
console.log(JSON.stringify(counter, null, 2));
}
if (import.meta.main) {
await main();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment