open-backlink-checker 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- open_backlink_checker-1.0.0/.gitignore +3 -0
- open_backlink_checker-1.0.0/LICENSE +21 -0
- open_backlink_checker-1.0.0/PKG-INFO +140 -0
- open_backlink_checker-1.0.0/README.md +118 -0
- open_backlink_checker-1.0.0/check-authority.mjs +96 -0
- open_backlink_checker-1.0.0/check_authority.py +289 -0
- open_backlink_checker-1.0.0/package.json +15 -0
- open_backlink_checker-1.0.0/pyproject.toml +42 -0
- open_backlink_checker-1.0.0/sample_top_500.csv +501 -0
- open_backlink_checker-1.0.0/test_check_authority.py +187 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SpecStream SAS
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: open-backlink-checker
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Bulk Domain Authority, backlinks, anchor texts and live authority badges from your terminal, on the SpecStream Link Graph API (223.9M scored domains).
|
|
5
|
+
Project-URL: Homepage, https://specstream.ai/tools/backlink-checker
|
|
6
|
+
Project-URL: Backlinks API, https://specstream.ai/backlinks-api
|
|
7
|
+
Project-URL: Pricing, https://specstream.ai/pricing
|
|
8
|
+
Project-URL: Source, https://github.com/Specstreamai/open-backlink-checker
|
|
9
|
+
Project-URL: Issues, https://github.com/Specstreamai/open-backlink-checker/issues
|
|
10
|
+
Author-email: SpecStream <support@specstream.ai>
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: anchor-text,backlink-checker,backlinks,bulk-da-checker,domain-authority,link-graph,referring-domains,seo,specstream
|
|
14
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
15
|
+
Classifier: Environment :: Console
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
|
|
20
|
+
Requires-Python: >=3.8
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# open-backlink-checker
|
|
24
|
+
|
|
25
|
+
[](https://specstream.ai/tools/backlink-checker?domain=github.com)
|
|
26
|
+
[](https://specstream.ai/tools/backlink-checker?domain=stripe.com)
|
|
27
|
+
[](LICENSE)
|
|
28
|
+
|
|
29
|
+
Bulk Domain Authority, backlinks, anchor texts and live authority badges from your terminal. One Python file and one Node.js file, zero dependencies, powered by the [SpecStream Link Graph API](https://specstream.ai/backlinks-api), which scores **223.9 million domains** from SpecStream's own web index.
|
|
30
|
+
|
|
31
|
+
Try it in two seconds with no key and no sign up:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pipx install open-backlink-checker # or: pip install open-backlink-checker
|
|
35
|
+
open-backlink-checker authority github.com stripe.com notion.so --offline-sample
|
|
36
|
+
|
|
37
|
+
npx @specstream/open-backlink-checker authority github.com stripe.com --offline-sample
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
PyPI: [open-backlink-checker](https://pypi.org/project/open-backlink-checker/). npm: [@specstream/open-backlink-checker](https://www.npmjs.com/package/@specstream/open-backlink-checker). From a clone, `python3 check_authority.py` and `node check-authority.mjs` take the same commands.
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
domain DA rank source
|
|
44
|
+
github.com 84.7 #19 offline-sample
|
|
45
|
+
stripe.com 71.0 #265 offline-sample
|
|
46
|
+
notion.so 68.6 #422 offline-sample
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
`--offline-sample` reads the bundled `sample_top_500.csv`: the top 500 domains of the open [open-web-authority-10k](https://github.com/Specstreamai/open-web-authority-10k) dataset (CC BY 4.0). Every other domain, plus backlinks, anchors and site profiles, comes live from the API.
|
|
50
|
+
|
|
51
|
+
## Add a live Domain Authority badge to your README
|
|
52
|
+
|
|
53
|
+
```markdown
|
|
54
|
+
[](https://specstream.ai/tools/backlink-checker?domain=YOURDOMAIN.com)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The badge is free, needs no key and updates itself. Generate it for any domain:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
open-backlink-checker badge yourdomain.com # Markdown
|
|
61
|
+
open-backlink-checker badge yourdomain.com --format html # HTML
|
|
62
|
+
open-backlink-checker badge yourdomain.com --format rst # reStructuredText
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Live API in one minute
|
|
66
|
+
|
|
67
|
+
1. Sign up at [specstream.ai/workspace](https://specstream.ai/workspace): **$2 of free credit, no card**. That is 4,000 authority calls.
|
|
68
|
+
2. `export SPECSTREAM_API_KEY=sk_...`
|
|
69
|
+
3. Run:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
open-backlink-checker authority stripe.com notion.so linear.app
|
|
73
|
+
open-backlink-checker backlinks stripe.com --limit 20
|
|
74
|
+
open-backlink-checker anchors stripe.com
|
|
75
|
+
open-backlink-checker site-intel stripe.com
|
|
76
|
+
open-backlink-checker bulk --csv domains.csv --out report.csv
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Node.js 18+ has the same commands:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
npx @specstream/open-backlink-checker authority stripe.com notion.so
|
|
83
|
+
npx @specstream/open-backlink-checker badge stripe.com --format html
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`bulk` reads the `domain`, `url`, `website` or `site` column of any CSV (or the first column), cleans `https://www.` and paths, removes duplicates, and sends 100 domains per call. The report has `domain, known, domain_authority, global_rank, referring_domains, source`. Add `--offline-sample` to run it on the bundled top 500 with no key.
|
|
87
|
+
|
|
88
|
+
## Endpoints
|
|
89
|
+
|
|
90
|
+
| Command | Endpoint | Price |
|
|
91
|
+
|---|---|---|
|
|
92
|
+
| `authority` | `GET /v1/authority?domains=stripe.com,notion.so` | $0.50 per 1,000 calls (1 to 10 domains), $2 per 1,000 calls (11 to 100) |
|
|
93
|
+
| `backlinks` | `GET /v1/backlinks?target=stripe.com&limit=50` | $4 per 1,000 calls |
|
|
94
|
+
| `anchors` | `GET /v1/anchors?target=stripe.com&limit=50` | $3 per 1,000 calls |
|
|
95
|
+
| `site-intel` | `GET /v1/site-intel?domain=stripe.com` | $10 per 1,000 calls |
|
|
96
|
+
| `badge` | `GET /v1/badge/authority?domain=stripe.com` | Free, no key |
|
|
97
|
+
|
|
98
|
+
Base URL `https://api.specstream.ai`, header `Authorization: Bearer $SPECSTREAM_API_KEY`. Full reference: [specstream.ai/backlinks-api](https://specstream.ai/backlinks-api).
|
|
99
|
+
|
|
100
|
+
## Price next to the usual backlink APIs
|
|
101
|
+
|
|
102
|
+
| | API access | Price | Least you pay |
|
|
103
|
+
|---|---|---|---|
|
|
104
|
+
| **SpecStream** | Pay per call, every plan | $0.50 per 1,000 authority calls, $4 per 1,000 backlink calls | **$2 free credit, no card** |
|
|
105
|
+
| Ahrefs | API on the Enterprise plan | $1,499 a month, billed yearly | $17,988 a year |
|
|
106
|
+
| Semrush | SEO API units on Business | $499.92 a month billed yearly, or $599 monthly | $5,999 a year |
|
|
107
|
+
| DataForSEO | Backlinks API, pay as you go | From $0.02 per request plus a charge per row | $50 minimum top up |
|
|
108
|
+
|
|
109
|
+
No seats and no monthly fee. A call the index does not answer is free.
|
|
110
|
+
|
|
111
|
+
## More
|
|
112
|
+
|
|
113
|
+
* Check any domain in the browser: [specstream.ai/tools/backlink-checker](https://specstream.ai/tools/backlink-checker)
|
|
114
|
+
* API page and docs: [specstream.ai/backlinks-api](https://specstream.ai/backlinks-api)
|
|
115
|
+
* Search API, with a drop in for Google Custom Search: [specstream.ai/search-api](https://specstream.ai/search-api)
|
|
116
|
+
* Pricing: [specstream.ai/pricing](https://specstream.ai/pricing)
|
|
117
|
+
* Open dataset, 10,000 domains, CC BY 4.0: [GitHub](https://github.com/Specstreamai/open-web-authority-10k), [Hugging Face](https://huggingface.co/datasets/SpecStreamAI/open-web-authority-10k), [Kaggle](https://www.kaggle.com/datasets/specstream/open-web-authority-10k)
|
|
118
|
+
|
|
119
|
+
## Free tools and the MCP server
|
|
120
|
+
|
|
121
|
+
In the browser, no signup:
|
|
122
|
+
|
|
123
|
+
* [Domain profile, stripe.com](https://specstream.ai/data/domain/stripe.com): the public page for one domain, with its authority, referring domains, rank and top backlinks.
|
|
124
|
+
* [DORA subprocessor check](https://specstream.ai/tools/dora-subprocessor-check): a SaaS vendor's subprocessors with their LEIs, as Register of Information rows.
|
|
125
|
+
* [Google CSE migrator](https://specstream.ai/tools/google-cse-migrator): run a Custom Search query on the drop in endpoint in the browser.
|
|
126
|
+
* [Token tax calculator](https://specstream.ai/tools/token-tax-calculator): how many tokens a search reply puts in front of your model, and what that costs. Measured script and results: [web-search-api-benchmarks/token-tax](https://github.com/Specstreamai/web-search-api-benchmarks/tree/main/token-tax).
|
|
127
|
+
|
|
128
|
+
For agents:
|
|
129
|
+
|
|
130
|
+
* MCP server: `https://api.specstream.ai/mcp` (Streamable HTTP, Bearer key or OAuth) gives an agent the same calls. Setup for each client: [specstream.ai/docs/mcp](https://specstream.ai/docs/mcp).
|
|
131
|
+
|
|
132
|
+
## Tests
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
python3 -m unittest -v
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
|
|
140
|
+
MIT. The bundled sample is from open-web-authority-10k by SpecStream, CC BY 4.0.
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# open-backlink-checker
|
|
2
|
+
|
|
3
|
+
[](https://specstream.ai/tools/backlink-checker?domain=github.com)
|
|
4
|
+
[](https://specstream.ai/tools/backlink-checker?domain=stripe.com)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
Bulk Domain Authority, backlinks, anchor texts and live authority badges from your terminal. One Python file and one Node.js file, zero dependencies, powered by the [SpecStream Link Graph API](https://specstream.ai/backlinks-api), which scores **223.9 million domains** from SpecStream's own web index.
|
|
8
|
+
|
|
9
|
+
Try it in two seconds with no key and no sign up:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pipx install open-backlink-checker # or: pip install open-backlink-checker
|
|
13
|
+
open-backlink-checker authority github.com stripe.com notion.so --offline-sample
|
|
14
|
+
|
|
15
|
+
npx @specstream/open-backlink-checker authority github.com stripe.com --offline-sample
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
PyPI: [open-backlink-checker](https://pypi.org/project/open-backlink-checker/). npm: [@specstream/open-backlink-checker](https://www.npmjs.com/package/@specstream/open-backlink-checker). From a clone, `python3 check_authority.py` and `node check-authority.mjs` take the same commands.
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
domain DA rank source
|
|
22
|
+
github.com 84.7 #19 offline-sample
|
|
23
|
+
stripe.com 71.0 #265 offline-sample
|
|
24
|
+
notion.so 68.6 #422 offline-sample
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`--offline-sample` reads the bundled `sample_top_500.csv`: the top 500 domains of the open [open-web-authority-10k](https://github.com/Specstreamai/open-web-authority-10k) dataset (CC BY 4.0). Every other domain, plus backlinks, anchors and site profiles, comes live from the API.
|
|
28
|
+
|
|
29
|
+
## Add a live Domain Authority badge to your README
|
|
30
|
+
|
|
31
|
+
```markdown
|
|
32
|
+
[](https://specstream.ai/tools/backlink-checker?domain=YOURDOMAIN.com)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The badge is free, needs no key and updates itself. Generate it for any domain:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
open-backlink-checker badge yourdomain.com # Markdown
|
|
39
|
+
open-backlink-checker badge yourdomain.com --format html # HTML
|
|
40
|
+
open-backlink-checker badge yourdomain.com --format rst # reStructuredText
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Live API in one minute
|
|
44
|
+
|
|
45
|
+
1. Sign up at [specstream.ai/workspace](https://specstream.ai/workspace): **$2 of free credit, no card**. That is 4,000 authority calls.
|
|
46
|
+
2. `export SPECSTREAM_API_KEY=sk_...`
|
|
47
|
+
3. Run:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
open-backlink-checker authority stripe.com notion.so linear.app
|
|
51
|
+
open-backlink-checker backlinks stripe.com --limit 20
|
|
52
|
+
open-backlink-checker anchors stripe.com
|
|
53
|
+
open-backlink-checker site-intel stripe.com
|
|
54
|
+
open-backlink-checker bulk --csv domains.csv --out report.csv
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Node.js 18+ has the same commands:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npx @specstream/open-backlink-checker authority stripe.com notion.so
|
|
61
|
+
npx @specstream/open-backlink-checker badge stripe.com --format html
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
`bulk` reads the `domain`, `url`, `website` or `site` column of any CSV (or the first column), cleans `https://www.` and paths, removes duplicates, and sends 100 domains per call. The report has `domain, known, domain_authority, global_rank, referring_domains, source`. Add `--offline-sample` to run it on the bundled top 500 with no key.
|
|
65
|
+
|
|
66
|
+
## Endpoints
|
|
67
|
+
|
|
68
|
+
| Command | Endpoint | Price |
|
|
69
|
+
|---|---|---|
|
|
70
|
+
| `authority` | `GET /v1/authority?domains=stripe.com,notion.so` | $0.50 per 1,000 calls (1 to 10 domains), $2 per 1,000 calls (11 to 100) |
|
|
71
|
+
| `backlinks` | `GET /v1/backlinks?target=stripe.com&limit=50` | $4 per 1,000 calls |
|
|
72
|
+
| `anchors` | `GET /v1/anchors?target=stripe.com&limit=50` | $3 per 1,000 calls |
|
|
73
|
+
| `site-intel` | `GET /v1/site-intel?domain=stripe.com` | $10 per 1,000 calls |
|
|
74
|
+
| `badge` | `GET /v1/badge/authority?domain=stripe.com` | Free, no key |
|
|
75
|
+
|
|
76
|
+
Base URL `https://api.specstream.ai`, header `Authorization: Bearer $SPECSTREAM_API_KEY`. Full reference: [specstream.ai/backlinks-api](https://specstream.ai/backlinks-api).
|
|
77
|
+
|
|
78
|
+
## Price next to the usual backlink APIs
|
|
79
|
+
|
|
80
|
+
| | API access | Price | Least you pay |
|
|
81
|
+
|---|---|---|---|
|
|
82
|
+
| **SpecStream** | Pay per call, every plan | $0.50 per 1,000 authority calls, $4 per 1,000 backlink calls | **$2 free credit, no card** |
|
|
83
|
+
| Ahrefs | API on the Enterprise plan | $1,499 a month, billed yearly | $17,988 a year |
|
|
84
|
+
| Semrush | SEO API units on Business | $499.92 a month billed yearly, or $599 monthly | $5,999 a year |
|
|
85
|
+
| DataForSEO | Backlinks API, pay as you go | From $0.02 per request plus a charge per row | $50 minimum top up |
|
|
86
|
+
|
|
87
|
+
No seats and no monthly fee. A call the index does not answer is free.
|
|
88
|
+
|
|
89
|
+
## More
|
|
90
|
+
|
|
91
|
+
* Check any domain in the browser: [specstream.ai/tools/backlink-checker](https://specstream.ai/tools/backlink-checker)
|
|
92
|
+
* API page and docs: [specstream.ai/backlinks-api](https://specstream.ai/backlinks-api)
|
|
93
|
+
* Search API, with a drop in for Google Custom Search: [specstream.ai/search-api](https://specstream.ai/search-api)
|
|
94
|
+
* Pricing: [specstream.ai/pricing](https://specstream.ai/pricing)
|
|
95
|
+
* Open dataset, 10,000 domains, CC BY 4.0: [GitHub](https://github.com/Specstreamai/open-web-authority-10k), [Hugging Face](https://huggingface.co/datasets/SpecStreamAI/open-web-authority-10k), [Kaggle](https://www.kaggle.com/datasets/specstream/open-web-authority-10k)
|
|
96
|
+
|
|
97
|
+
## Free tools and the MCP server
|
|
98
|
+
|
|
99
|
+
In the browser, no signup:
|
|
100
|
+
|
|
101
|
+
* [Domain profile, stripe.com](https://specstream.ai/data/domain/stripe.com): the public page for one domain, with its authority, referring domains, rank and top backlinks.
|
|
102
|
+
* [DORA subprocessor check](https://specstream.ai/tools/dora-subprocessor-check): a SaaS vendor's subprocessors with their LEIs, as Register of Information rows.
|
|
103
|
+
* [Google CSE migrator](https://specstream.ai/tools/google-cse-migrator): run a Custom Search query on the drop in endpoint in the browser.
|
|
104
|
+
* [Token tax calculator](https://specstream.ai/tools/token-tax-calculator): how many tokens a search reply puts in front of your model, and what that costs. Measured script and results: [web-search-api-benchmarks/token-tax](https://github.com/Specstreamai/web-search-api-benchmarks/tree/main/token-tax).
|
|
105
|
+
|
|
106
|
+
For agents:
|
|
107
|
+
|
|
108
|
+
* MCP server: `https://api.specstream.ai/mcp` (Streamable HTTP, Bearer key or OAuth) gives an agent the same calls. Setup for each client: [specstream.ai/docs/mcp](https://specstream.ai/docs/mcp).
|
|
109
|
+
|
|
110
|
+
## Tests
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
python3 -m unittest -v
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## License
|
|
117
|
+
|
|
118
|
+
MIT. The bundled sample is from open-web-authority-10k by SpecStream, CC BY 4.0.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// open-backlink-checker for Node.js 18+, zero dependencies. Same commands as check_authority.py:
|
|
3
|
+
// node check-authority.mjs authority stripe.com notion.so [--offline-sample] [--json]
|
|
4
|
+
// node check-authority.mjs backlinks stripe.com [--limit 50]
|
|
5
|
+
// node check-authority.mjs anchors stripe.com [--limit 50]
|
|
6
|
+
// node check-authority.mjs site-intel stripe.com
|
|
7
|
+
// node check-authority.mjs badge stripe.com [--format markdown|html|url]
|
|
8
|
+
// Live calls read SPECSTREAM_API_KEY. Free $2 credit, no card: https://specstream.ai/workspace
|
|
9
|
+
import { readFileSync, realpathSync } from 'node:fs';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
|
+
import { dirname, join } from 'node:path';
|
|
12
|
+
|
|
13
|
+
const API = process.env.SPECSTREAM_API_BASE || 'https://api.specstream.ai/v1';
|
|
14
|
+
const BADGE = 'https://api.specstream.ai/v1/badge/authority';
|
|
15
|
+
const CHECKER = 'https://specstream.ai/tools/backlink-checker';
|
|
16
|
+
|
|
17
|
+
export function cleanDomain(raw) {
|
|
18
|
+
let t = String(raw || '').trim().toLowerCase();
|
|
19
|
+
if (!t.includes('://')) t = 'http://' + t;
|
|
20
|
+
let host;
|
|
21
|
+
try { host = new URL(t).hostname.replace(/^www\./, '').replace(/\.$/, ''); } catch { host = ''; }
|
|
22
|
+
if (!/^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)+$/.test(host)) throw new Error(`not a domain: ${raw}`);
|
|
23
|
+
return host;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function loadSample() {
|
|
27
|
+
const path = join(dirname(fileURLToPath(import.meta.url)), 'sample_top_500.csv');
|
|
28
|
+
const [, ...lines] = readFileSync(path, 'utf8').trim().split('\n');
|
|
29
|
+
return new Map(lines.map((l) => {
|
|
30
|
+
const [domain, rank, raw, da, country] = l.split(',');
|
|
31
|
+
return [domain, { domain, known: true, domain_authority: Number(da), global_rank: Number(rank), authority_raw: Number(raw), country: country || null, source: 'offline-sample' }];
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function badgeSnippet(domain, format = 'markdown') {
|
|
36
|
+
const d = cleanDomain(domain);
|
|
37
|
+
const img = `${BADGE}?domain=${d}`;
|
|
38
|
+
const link = `${CHECKER}?domain=${d}`;
|
|
39
|
+
if (format === 'html') return `<a href="${link}"><img src="${img}" alt="SpecStream DA"></a>`;
|
|
40
|
+
if (format === 'url') return img;
|
|
41
|
+
return `[](${link})`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function get(path, params) {
|
|
45
|
+
const key = process.env.SPECSTREAM_API_KEY;
|
|
46
|
+
if (!key) throw new Error('no API key: set SPECSTREAM_API_KEY (free $2 credit, no card: https://specstream.ai/workspace), or try --offline-sample');
|
|
47
|
+
const res = await fetch(`${API}${path}?${new URLSearchParams(params)}`, {
|
|
48
|
+
headers: { Authorization: `Bearer ${key}`, Accept: 'application/json', 'User-Agent': 'open-backlink-checker/1.0.0' },
|
|
49
|
+
});
|
|
50
|
+
if (!res.ok) throw new Error(`HTTP ${res.status} on ${path}: ${(await res.text()).slice(0, 300)}`);
|
|
51
|
+
const body = await res.json();
|
|
52
|
+
return body.data ?? body;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function main(argv) {
|
|
56
|
+
const flags = new Map();
|
|
57
|
+
const pos = [];
|
|
58
|
+
for (let i = 0; i < argv.length; i++) {
|
|
59
|
+
const a = argv[i];
|
|
60
|
+
if (a === '--offline-sample' || a === '--json') flags.set(a, true);
|
|
61
|
+
else if (a.startsWith('--')) flags.set(a, argv[++i]);
|
|
62
|
+
else pos.push(a);
|
|
63
|
+
}
|
|
64
|
+
const [cmd, ...args] = pos;
|
|
65
|
+
const limit = flags.get('--limit') || 50;
|
|
66
|
+
if (cmd === 'authority') {
|
|
67
|
+
const domains = [...new Set(args.map(cleanDomain))];
|
|
68
|
+
let rows;
|
|
69
|
+
if (flags.get('--offline-sample')) {
|
|
70
|
+
const s = loadSample();
|
|
71
|
+
rows = domains.map((d) => s.get(d) || { domain: d, known: false, domain_authority: null, global_rank: null, source: 'offline-sample' });
|
|
72
|
+
} else {
|
|
73
|
+
rows = [];
|
|
74
|
+
for (let i = 0; i < domains.length; i += 100) {
|
|
75
|
+
const data = await get('/authority', { domains: domains.slice(i, i + 100).join(',') });
|
|
76
|
+
rows.push(...(data.results || []).map((r) => ({ ...r, source: 'live' })));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (flags.get('--json')) console.log(JSON.stringify(rows, null, 2));
|
|
80
|
+
else console.table(rows.map((r) => ({ domain: r.domain, DA: r.known ? r.domain_authority : '-', rank: r.global_rank || '-', source: r.source })));
|
|
81
|
+
} else if (cmd === 'backlinks' || cmd === 'anchors') {
|
|
82
|
+
console.log(JSON.stringify(await get(`/${cmd}`, { target: cleanDomain(args[0]), limit }), null, 2));
|
|
83
|
+
} else if (cmd === 'site-intel') {
|
|
84
|
+
console.log(JSON.stringify(await get('/site-intel', { domain: cleanDomain(args[0]) }), null, 2));
|
|
85
|
+
} else if (cmd === 'badge') {
|
|
86
|
+
console.log(badgeSnippet(args[0], flags.get('--format')));
|
|
87
|
+
} else {
|
|
88
|
+
console.log('usage: node check-authority.mjs authority|backlinks|anchors|site-intel|badge <domain...> [--offline-sample] [--json]');
|
|
89
|
+
return cmd ? 1 : 0;
|
|
90
|
+
}
|
|
91
|
+
return 0;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (process.argv[1] && realpathSync(fileURLToPath(import.meta.url)) === realpathSync(process.argv[1])) {
|
|
95
|
+
main(process.argv.slice(2)).then((c) => process.exit(c), (e) => { console.error(`error: ${e.message}`); process.exit(1); });
|
|
96
|
+
}
|