atlas-obscura-api 3.0.0 → 3.1.1
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.
- package/README.md +37 -0
- package/fetchers/index.d.ts +1 -1
- package/fetchers/index.js +10 -7
- package/index.d.ts +7 -7
- package/index.js +9 -9
- package/interfaces/global.d.ts +3 -0
- package/package.json +9 -5
- package/services/location.service.d.ts +8 -8
- package/services/location.service.js +8 -8
package/README.md
CHANGED
|
@@ -209,6 +209,43 @@ atlasobscura.placeFull(494).then((place) => console.log(place));
|
|
|
209
209
|
}
|
|
210
210
|
```
|
|
211
211
|
|
|
212
|
+
## 📦 Docker
|
|
213
|
+
|
|
214
|
+
You can use this library in Docker.
|
|
215
|
+
|
|
216
|
+
We have [prepared a Docker image](https://hub.docker.com/r/bartholomej/atlas-obscura-api) for you.
|
|
217
|
+
|
|
218
|
+
### Prebuilt image
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
docker pull bartholomej/atlas-obscura-api
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Build & run your own image
|
|
225
|
+
|
|
226
|
+
> Build image
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
docker build -t atlas-obscura-api .
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
> Run image on port 3000
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
docker run -p 3000:3000 atlas-obscura-api
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
> Open http://localhost:3000
|
|
239
|
+
|
|
240
|
+
### API endpoints
|
|
241
|
+
|
|
242
|
+
> Some examples
|
|
243
|
+
|
|
244
|
+
- `/movie/535121`
|
|
245
|
+
- `/search/quentin+tarantino`
|
|
246
|
+
- `/creator/2120`
|
|
247
|
+
- `/user-ratings/912-bart`
|
|
248
|
+
|
|
212
249
|
## Used By
|
|
213
250
|
|
|
214
251
|
- Atlas Obscura Offline mobile app (Android, iOS)
|
package/fetchers/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const fetchPage: (url: string) => Promise<string>;
|
|
1
|
+
export declare const fetchPage: (url: string, headersCustom?: Headers) => Promise<string>;
|
package/fetchers/index.js
CHANGED
|
@@ -6,17 +6,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.fetchPage = void 0;
|
|
7
7
|
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
8
8
|
const USER_AGENTS = [
|
|
9
|
-
'Mozilla/5.0 (Windows NT 10.0; Win64; x64
|
|
10
|
-
'Mozilla/5.0 (
|
|
11
|
-
'
|
|
12
|
-
'Mozilla/5.0 (
|
|
9
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0',
|
|
10
|
+
'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0',
|
|
11
|
+
'Dalvik/2.1.0 (Linux; U; Android 8.1.0; C6L Build/OPM2.171019.012)',
|
|
12
|
+
'Mozilla/5.0 (Windows; Windows NT 10.0; x64) AppleWebKit/537.50 (KHTML, like Gecko) Chrome/48.0.2572.385 Safari/537.9 Edge/8.37913',
|
|
13
|
+
'Mozilla/5.0 (Linux; Android 12; SM-A127F Build/SP1A.210812.016; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/96.0.4664.104 Mobile Safari/537.36 Instagram 243.0.0.16.111 Android (31/12; 300dpi; 720x1467; samsung; SM-A127F; a12s; exynos850; in_ID; 382290496)',
|
|
14
|
+
'Mozilla/5.0 (Linux; Android 11; M2101K7BNY Build/RP1A.200720.011; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/103.0.5060.70 Mobile Safari/537.36 [FB_IAB/Orca-Android;FBAV/369.0.0.7.111;]'
|
|
13
15
|
];
|
|
14
16
|
const headers = {
|
|
15
|
-
'User-Agent': USER_AGENTS[Math.floor(Math.random() * USER_AGENTS.length)]
|
|
17
|
+
'User-Agent': USER_AGENTS[Math.floor(Math.random() * USER_AGENTS.length)],
|
|
18
|
+
'Cache-Control': 'no-cache'
|
|
16
19
|
};
|
|
17
|
-
const fetchPage = async (url) => {
|
|
20
|
+
const fetchPage = async (url, headersCustom) => {
|
|
18
21
|
try {
|
|
19
|
-
const response = await (0, cross_fetch_1.default)(url, { headers });
|
|
22
|
+
const response = await (0, cross_fetch_1.default)(url, { headers: { ...headers, ...headersCustom }, credentials: 'omit' });
|
|
20
23
|
if (response.status >= 400 && response.status < 600) {
|
|
21
24
|
throw new Error(`atlas-obscura-api: Bad response ${response.status} for url: ${url}`);
|
|
22
25
|
}
|
package/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Coordinates } from 'interfaces/global';
|
|
2
|
-
import { Place, PlaceShort } from 'interfaces/placeId.interface';
|
|
3
|
-
import { PlacesAll } from 'interfaces/places-all.interface';
|
|
1
|
+
import { Coordinates, FetchOptions } from './interfaces/global';
|
|
4
2
|
import { LocationResult } from './interfaces/locations.interface';
|
|
3
|
+
import { Place, PlaceShort } from './interfaces/placeId.interface';
|
|
4
|
+
import { PlacesAll } from './interfaces/places-all.interface';
|
|
5
5
|
import { PlacesScraper } from './services/location.service';
|
|
6
6
|
export declare class AtlasObscura {
|
|
7
7
|
private locationService;
|
|
8
8
|
constructor(locationService: PlacesScraper);
|
|
9
|
-
search(coords: Coordinates): Promise<LocationResult>;
|
|
10
|
-
placesAll(): Promise<PlacesAll[]>;
|
|
11
|
-
placeShort(id: number): Promise<PlaceShort>;
|
|
12
|
-
placeFull(id: number): Promise<Place>;
|
|
9
|
+
search(coords: Coordinates, options?: FetchOptions): Promise<LocationResult>;
|
|
10
|
+
placesAll(options?: FetchOptions): Promise<PlacesAll[]>;
|
|
11
|
+
placeShort(id: number, options?: FetchOptions): Promise<PlaceShort>;
|
|
12
|
+
placeFull(id: number, options?: FetchOptions): Promise<Place>;
|
|
13
13
|
}
|
|
14
14
|
export declare const atlasobscura: AtlasObscura;
|
package/index.js
CHANGED
|
@@ -7,18 +7,18 @@ class AtlasObscura {
|
|
|
7
7
|
constructor(locationService) {
|
|
8
8
|
this.locationService = locationService;
|
|
9
9
|
}
|
|
10
|
-
async search(coords) {
|
|
11
|
-
return this.locationService.search(coords);
|
|
10
|
+
async search(coords, options) {
|
|
11
|
+
return this.locationService.search(coords, 1, options);
|
|
12
12
|
}
|
|
13
|
-
async placesAll() {
|
|
14
|
-
return this.locationService.placesAll();
|
|
13
|
+
async placesAll(options) {
|
|
14
|
+
return this.locationService.placesAll(options);
|
|
15
15
|
}
|
|
16
|
-
async placeShort(id) {
|
|
17
|
-
return this.locationService.placeByIdShort(id);
|
|
16
|
+
async placeShort(id, options) {
|
|
17
|
+
return this.locationService.placeByIdShort(id, options);
|
|
18
18
|
}
|
|
19
|
-
async placeFull(id) {
|
|
20
|
-
const place = await this.locationService.placeByIdShort(id);
|
|
21
|
-
const placeRich = await this.locationService.placeFull(place.url);
|
|
19
|
+
async placeFull(id, options) {
|
|
20
|
+
const place = await this.locationService.placeByIdShort(id, options);
|
|
21
|
+
const placeRich = await this.locationService.placeFull(place.url, options);
|
|
22
22
|
return { ...place, ...placeRich };
|
|
23
23
|
}
|
|
24
24
|
}
|
package/interfaces/global.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "atlas-obscura-api",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "Atlas Obscura API in JavaScript. NPM library for scrapping atlasobscura.com",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"author": "BART! <bart@bartweb.cz>",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"start": "tsc -w",
|
|
9
9
|
"prebuild": "rimraf dist",
|
|
10
|
-
"build": "tsc",
|
|
11
|
-
"postbuild": "npm-prepare-dist -s postinstall -s prepare",
|
|
10
|
+
"build": "tsc && npm-prepare-dist -s postinstall -s prepare",
|
|
12
11
|
"tsc": "tsc",
|
|
13
12
|
"demo": "tsx demo",
|
|
14
13
|
"lint": "eslint ./src/**/**/* --fix",
|
|
15
|
-
"test": "
|
|
16
|
-
"
|
|
14
|
+
"test": "vitest",
|
|
15
|
+
"test:coverage": "yarn test run --coverage",
|
|
16
|
+
"publish:next": "yarn && yarn build && yarn test --coverage && npm publish --folder dist --tag beta",
|
|
17
17
|
"postversion": "git push && git push --follow-tags",
|
|
18
18
|
"release:beta": "npm version preminor --preid=beta -m \"chore(update): prelease %s β\"",
|
|
19
19
|
"prerelease:beta": "npm version prerelease --preid=beta -m \"chore(update): prelease %s β\"",
|
|
@@ -49,6 +49,10 @@
|
|
|
49
49
|
"node": ">= 20"
|
|
50
50
|
},
|
|
51
51
|
"license": "MIT",
|
|
52
|
+
"lint-staged": {
|
|
53
|
+
"*.ts": "eslint --cache --fix"
|
|
54
|
+
},
|
|
55
|
+
"packageManager": "yarn@4.10.3",
|
|
52
56
|
"module": "./index.js",
|
|
53
57
|
"types": "./index.d.ts"
|
|
54
58
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Coordinates } from 'interfaces/global';
|
|
2
|
-
import { LocationResult } from 'interfaces/locations.interface';
|
|
3
|
-
import { PlaceExtend, PlaceShort } from 'interfaces/placeId.interface';
|
|
4
|
-
import { PlacesAll } from 'interfaces/places-all.interface';
|
|
1
|
+
import { Coordinates, FetchOptions } from './../interfaces/global';
|
|
2
|
+
import { LocationResult } from './../interfaces/locations.interface';
|
|
3
|
+
import { PlaceExtend, PlaceShort } from './../interfaces/placeId.interface';
|
|
4
|
+
import { PlacesAll } from './../interfaces/places-all.interface';
|
|
5
5
|
export declare class PlacesScraper {
|
|
6
|
-
placesAll(): Promise<PlacesAll[]>;
|
|
7
|
-
search(coords: Coordinates, page?: number): Promise<LocationResult>;
|
|
8
|
-
placeByIdShort(id: number): Promise<PlaceShort>;
|
|
9
|
-
placeFull(url: string): Promise<PlaceExtend>;
|
|
6
|
+
placesAll(options?: FetchOptions): Promise<PlacesAll[]>;
|
|
7
|
+
search(coords: Coordinates, page?: number, options?: FetchOptions): Promise<LocationResult>;
|
|
8
|
+
placeByIdShort(id: number, options?: FetchOptions): Promise<PlaceShort>;
|
|
9
|
+
placeFull(url: string, options?: FetchOptions): Promise<PlaceExtend>;
|
|
10
10
|
}
|
|
@@ -6,22 +6,22 @@ const fetchers_1 = require("../fetchers");
|
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
7
|
const vars_1 = require("../vars");
|
|
8
8
|
class PlacesScraper {
|
|
9
|
-
async placesAll() {
|
|
10
|
-
const response = await (0, fetchers_1.fetchPage)(vars_1.URL_PLACES_ALL);
|
|
9
|
+
async placesAll(options) {
|
|
10
|
+
const response = await (0, fetchers_1.fetchPage)(vars_1.URL_PLACES_ALL, options?.headers);
|
|
11
11
|
const html = (0, node_html_parser_1.parse)(response).innerHTML;
|
|
12
12
|
const data = html.match(/AtlasObscura\.all_places = (.*?);/);
|
|
13
13
|
return (0, utils_1.parseResults)(data);
|
|
14
14
|
}
|
|
15
|
-
async search(coords, page = 1) {
|
|
15
|
+
async search(coords, page = 1, options) {
|
|
16
16
|
const url = (0, vars_1.urlSearch)(coords, page);
|
|
17
|
-
const response = await (0, fetchers_1.fetchPage)(url);
|
|
17
|
+
const response = await (0, fetchers_1.fetchPage)(url, options?.headers);
|
|
18
18
|
const html = (0, node_html_parser_1.parse)(response).innerHTML;
|
|
19
19
|
const data = html.match(/AtlasObscura\.place_search = (.*?);/);
|
|
20
20
|
return (0, utils_1.parseResults)(data);
|
|
21
21
|
}
|
|
22
|
-
async placeByIdShort(id) {
|
|
22
|
+
async placeByIdShort(id, options) {
|
|
23
23
|
const url = (0, vars_1.urlPlaceId)(id);
|
|
24
|
-
const data = await (0, fetchers_1.fetchPage)(url);
|
|
24
|
+
const data = await (0, fetchers_1.fetchPage)(url, options?.headers);
|
|
25
25
|
let place = null;
|
|
26
26
|
try {
|
|
27
27
|
place = JSON.parse(data);
|
|
@@ -34,8 +34,8 @@ class PlacesScraper {
|
|
|
34
34
|
}
|
|
35
35
|
return place;
|
|
36
36
|
}
|
|
37
|
-
async placeFull(url) {
|
|
38
|
-
const data = await (0, fetchers_1.fetchPage)(url);
|
|
37
|
+
async placeFull(url, options) {
|
|
38
|
+
const data = await (0, fetchers_1.fetchPage)(url, options?.headers);
|
|
39
39
|
const html = (0, node_html_parser_1.parse)(data);
|
|
40
40
|
const descriptions = html.querySelectorAll('.place-body p').map((p) => p.innerHTML);
|
|
41
41
|
const sectionDirections = Array.from(html.querySelectorAll('section')).find((sec) => {
|