-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
3,166 additions
and
87 deletions.
There are no files selected for viewing
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
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,28 @@ | ||
name: Package Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- owo | ||
pull_request: | ||
branches: | ||
- owo | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
# Checkout repo @ latest release | ||
- uses: actions/checkout@v2 | ||
# Install languages | ||
- name: Set up Nodejs 14.x | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 14.x | ||
# Install dependencies | ||
- name: npm ci | ||
run: npm ci | ||
# Run tests | ||
- name: Run tests | ||
run: npm run test |
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
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,50 @@ | ||
import argparse from 'argparse'; | ||
import { getTLDData } from './fetchData.js'; | ||
|
||
// Reads full buffer out of stream | ||
async function read(stream) { | ||
const chunks = []; | ||
for await (const chunk of stream) chunks.push(chunk); | ||
return Buffer.concat(chunks).toString('utf8'); | ||
} | ||
|
||
// Checks stream for any previously output data to use to supplement request | ||
// heavy portions of the update loop | ||
async function readPrevious(stream) { | ||
const inStr = await read(stream); | ||
if(inStr) { | ||
// Parse the previous data and return the JSON | ||
// object, but with the TLDs mapped to keys | ||
const inObj = JSON.parse(inStr); | ||
return inObj | ||
.map(({tld, isBrand, hasRestrictions}) => { | ||
return { | ||
[tld]: { isBrand, hasRestrictions } | ||
}; | ||
}) | ||
.reduce(Object.assign, {}); | ||
} | ||
} | ||
|
||
async function main() { | ||
// Parse args | ||
const parser = new argparse.ArgumentParser({ | ||
description: 'Fetch TLD Data' | ||
}); | ||
|
||
// TODO: Version... why does node make it so hard to just make normal modules | ||
// work... | ||
parser.add_argument('-v', '--version', { action: 'version', version: '1.1.0' }); | ||
parser.add_argument('-s', '--stdin', { action: 'store_true', help: 'Read previously output data on STDIN to reuse some old data to reduce amount of web scraping requests needed.' }); | ||
parser.add_argument('--color', { action: 'store_true', help: 'Pass in for chalk to force color output (should work by default... but doesnt)' }); | ||
|
||
const args = parser.parse_args(); | ||
let prevData; | ||
if(args.stdin) { | ||
prevData = await readPrevious(process.stdin); | ||
} | ||
const tldObjs = await getTLDData(prevData); | ||
process.stdout.write(JSON.stringify(tldObjs, null, 2)); | ||
} | ||
|
||
main(); |
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
Oops, something went wrong.