atlas-obscura-api 3.0.0 → 3.1.0
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 +11 -4
- package/index.d.ts +5 -5
- package/index.js +9 -9
- package/interfaces/global.d.ts +3 -0
- package/package.json +6 -3
- package/services/location.service.d.ts +5 -5
- 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
|
@@ -9,14 +9,21 @@ const USER_AGENTS = [
|
|
|
9
9
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
|
|
10
10
|
'Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/87.0.4280.77 Mobile/15E148 Safari/604.1',
|
|
11
11
|
'Mozilla/5.0 (Linux; Android 10; SM-A205U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.101 Mobile Safari/537.36',
|
|
12
|
-
'Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.101 Mobile Safari/537.36'
|
|
12
|
+
'Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.101 Mobile Safari/537.36',
|
|
13
|
+
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.1 Safari/605.1.15',
|
|
14
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0',
|
|
15
|
+
'Mozilla/5.0 (iPad; CPU OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1',
|
|
16
|
+
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
|
|
17
|
+
'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0',
|
|
18
|
+
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'
|
|
13
19
|
];
|
|
14
20
|
const headers = {
|
|
15
|
-
'User-Agent': USER_AGENTS[Math.floor(Math.random() * USER_AGENTS.length)]
|
|
21
|
+
'User-Agent': USER_AGENTS[Math.floor(Math.random() * USER_AGENTS.length)],
|
|
22
|
+
'Cache-Control': 'no-cache'
|
|
16
23
|
};
|
|
17
|
-
const fetchPage = async (url) => {
|
|
24
|
+
const fetchPage = async (url, headersCustom) => {
|
|
18
25
|
try {
|
|
19
|
-
const response = await (0, cross_fetch_1.default)(url, { headers });
|
|
26
|
+
const response = await (0, cross_fetch_1.default)(url, { headers: { ...headers, ...headersCustom }, credentials: 'omit' });
|
|
20
27
|
if (response.status >= 400 && response.status < 600) {
|
|
21
28
|
throw new Error(`atlas-obscura-api: Bad response ${response.status} for url: ${url}`);
|
|
22
29
|
}
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Coordinates } from 'interfaces/global';
|
|
1
|
+
import { Coordinates, FetchOptions } from 'interfaces/global';
|
|
2
2
|
import { Place, PlaceShort } from 'interfaces/placeId.interface';
|
|
3
3
|
import { PlacesAll } from 'interfaces/places-all.interface';
|
|
4
4
|
import { LocationResult } from './interfaces/locations.interface';
|
|
@@ -6,9 +6,9 @@ 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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "atlas-obscura-api",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
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>",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"tsc": "tsc",
|
|
13
13
|
"demo": "tsx demo",
|
|
14
14
|
"lint": "eslint ./src/**/**/* --fix",
|
|
15
|
-
"test": "
|
|
16
|
-
"publish:next": "yarn && yarn build && yarn test --coverage
|
|
15
|
+
"test": "vitest",
|
|
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,9 @@
|
|
|
49
49
|
"node": ">= 20"
|
|
50
50
|
},
|
|
51
51
|
"license": "MIT",
|
|
52
|
+
"lint-staged": {
|
|
53
|
+
"*.ts": "eslint --cache --fix"
|
|
54
|
+
},
|
|
52
55
|
"module": "./index.js",
|
|
53
56
|
"types": "./index.d.ts"
|
|
54
57
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Coordinates } from 'interfaces/global';
|
|
1
|
+
import { Coordinates, FetchOptions } from 'interfaces/global';
|
|
2
2
|
import { LocationResult } from 'interfaces/locations.interface';
|
|
3
3
|
import { PlaceExtend, PlaceShort } from 'interfaces/placeId.interface';
|
|
4
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) => {
|