From 08d753432f0e28591b8ddc7a4772037f76a256ac Mon Sep 17 00:00:00 2001 From: Zynh0722 Date: Tue, 2 Apr 2024 19:24:31 -0700 Subject: [PATCH] init --- .gitignore | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 15 +++++ bun.lockb | Bin 0 -> 7174 bytes index.ts | 53 +++++++++++++++ package.json | 14 ++++ tsconfig.json | 27 ++++++++ 6 files changed, 284 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100755 bun.lockb create mode 100644 index.ts create mode 100644 package.json create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9b1ee42 --- /dev/null +++ b/.gitignore @@ -0,0 +1,175 @@ +# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore + +# Logs + +logs +_.log +npm-debug.log_ +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Caches + +.cache + +# Diagnostic reports (https://nodejs.org/api/report.html) + +report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json + +# Runtime data + +pids +_.pid +_.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover + +lib-cov + +# Coverage directory used by tools like istanbul + +coverage +*.lcov + +# nyc test coverage + +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) + +.grunt + +# Bower dependency directory (https://bower.io/) + +bower_components + +# node-waf configuration + +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) + +build/Release + +# Dependency directories + +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) + +web_modules/ + +# TypeScript cache + +*.tsbuildinfo + +# Optional npm cache directory + +.npm + +# Optional eslint cache + +.eslintcache + +# Optional stylelint cache + +.stylelintcache + +# Microbundle cache + +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history + +.node_repl_history + +# Output of 'npm pack' + +*.tgz + +# Yarn Integrity file + +.yarn-integrity + +# dotenv environment variable files + +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) + +.parcel-cache + +# Next.js build output + +.next +out + +# Nuxt.js build / generate output + +.nuxt +dist + +# Gatsby files + +# Comment in the public line in if your project uses Gatsby and not Next.js + +# https://nextjs.org/blog/next-9-1#public-directory-support + +# public + +# vuepress build output + +.vuepress/dist + +# vuepress v2.x temp and cache directory + +.temp + +# Docusaurus cache and generated files + +.docusaurus + +# Serverless directories + +.serverless/ + +# FuseBox cache + +.fusebox/ + +# DynamoDB Local files + +.dynamodb/ + +# TernJS port file + +.tern-port + +# Stores VSCode versions used for testing VSCode extensions + +.vscode-test + +# yarn v2 + +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +# IntelliJ based IDEs +.idea + +# Finder (MacOS) folder config +.DS_Store diff --git a/README.md b/README.md new file mode 100644 index 0000000..1dbcdf9 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# nasa-patch-search + +To install dependencies: + +```bash +bun install +``` + +To run: + +```bash +bun run index.ts +``` + +This project was created using `bun init` in bun v1.1.0. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime. diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000000000000000000000000000000000000..07baf08a1980535921ce58b6303886814034157b GIT binary patch literal 7174 zcmeHMd010d7JtO3m^ucL#cCB0!Hpy&KtM!_wpx{O!3~${G=vut4GAU>5JZ8BN=012 z7KYXqP+LS>T#Btqk>XNZs#wLADs}m2p}16Bv53q$$-D5TGeYdlAN^)}zAv2n-o3xy zx%b?A&%N*9>LQ6Y8YE#ForKoKIEO{+1n?7S^~%L6jg}Uv^oB?UBZ~19@FhVo# z&ACY*MkLhO-F&65{^9UL^RsfSo0keM*tqRH!^HH5Mj*CkMOptwC$Z0yNCVSzZ;DEC zgOUwsHEnLP0+axre+AtGbeLYR4O1BDaD8MnqtP1gu=R(mD5@9Kf6QuH$7mQ0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{ parse } from "node-html-parser"; + +console.log("Hello via Bun!"); + +const BASE_URL = + "https://www.nasa.gov/gallery/human-spaceflight-mission-patches/"; + +async function getPatchesHrefs() { + function getGalleryPageHref(page: number) { + if (page > 1) { + return `${BASE_URL}page/${page}/`; + } else { + return BASE_URL; + } + } + + let patchHrefs: string[] = []; + + for (let i = 0; i <= 7; i++) { + const req = await fetch( + "https://www.nasa.gov/gallery/human-spaceflight-mission-patches/page/2/", + ); + const data = parse(await req.text()); + + const gallery = data + .getElementsByTagName("div") + .filter((el) => el.classList.contains("hds-gallery-items")) + .shift(); + + const links = gallery + ?.getElementsByTagName("a") + .map((el) => el.getAttribute("href")) + .filter((el) => el) as string[]; + + patchHrefs.push.apply(patchHrefs, links); + } +} + +const req = await fetch( + "https://www.nasa.gov/gallery/human-spaceflight-mission-patches/page/2/", +); +const data = parse(await req.text()); + +const gallery = data + .getElementsByTagName("div") + .filter((el) => el.classList.contains("hds-gallery-items")) + .shift(); + +const links = gallery + ?.getElementsByTagName("a") + .map((el) => el.getAttribute("href")); + +console.log(links); diff --git a/package.json b/package.json new file mode 100644 index 0000000..ab1ef50 --- /dev/null +++ b/package.json @@ -0,0 +1,14 @@ +{ + "name": "nasa-patch-search", + "module": "index.ts", + "devDependencies": { + "@types/bun": "latest" + }, + "peerDependencies": { + "typescript": "^5.0.0" + }, + "type": "module", + "dependencies": { + "node-html-parser": "^6.1.13" + } +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..238655f --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + // Enable latest features + "lib": ["ESNext", "DOM"], + "target": "ESNext", + "module": "ESNext", + "moduleDetection": "force", + "jsx": "react-jsx", + "allowJs": true, + + // Bundler mode + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, + + // Best practices + "strict": true, + "skipLibCheck": true, + "noFallthroughCasesInSwitch": true, + + // Some stricter flags (disabled by default) + "noUnusedLocals": false, + "noUnusedParameters": false, + "noPropertyAccessFromIndexSignature": false + } +}