atlas-obscura-api 0.0.1 → 2.0.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 +23 -4
- package/index.d.ts +3 -2
- package/index.js +7 -2
- package/interfaces/placeId.interface.d.ts +13 -3
- package/package.json +2 -2
- package/services/location.service.d.ts +3 -2
- package/services/location.service.js +13 -1
package/README.md
CHANGED
|
@@ -27,7 +27,8 @@ npm install atlas-obscura-api --save
|
|
|
27
27
|
|
|
28
28
|
- [All places](#All-places)
|
|
29
29
|
- [Search](#Search)
|
|
30
|
-
- [Show place by ID](#Show-place-by-ID)
|
|
30
|
+
- [Show place by ID (short)](#Show-place-by-ID)
|
|
31
|
+
- [Show place by ID (full)](#Show-place-by-ID)
|
|
31
32
|
|
|
32
33
|
### All Places
|
|
33
34
|
|
|
@@ -115,13 +116,17 @@ atlasobscura.search({ lat: 34.0522, lng: -118.2437 }).then((search) => console.l
|
|
|
115
116
|
|
|
116
117
|
### Show place by ID
|
|
117
118
|
|
|
118
|
-
|
|
119
|
+
#### Short version (one quick request)
|
|
120
|
+
|
|
121
|
+
> Get place by id (short version)
|
|
122
|
+
|
|
123
|
+
````javascript
|
|
119
124
|
|
|
120
125
|
```javascript
|
|
121
126
|
import { atlasobscura } from 'atlas-obscura-api';
|
|
122
127
|
|
|
123
|
-
atlasobscura.
|
|
124
|
-
|
|
128
|
+
atlasobscura.placeShort(494).then((place) => console.log(place));
|
|
129
|
+
````
|
|
125
130
|
|
|
126
131
|
#### Results
|
|
127
132
|
|
|
@@ -144,6 +149,20 @@ atlasobscura.placeById(494).then((place) => console.log(place));
|
|
|
144
149
|
}
|
|
145
150
|
```
|
|
146
151
|
|
|
152
|
+
#### Full version (two internal requests)
|
|
153
|
+
|
|
154
|
+
> Get place by id (FULL version)
|
|
155
|
+
|
|
156
|
+
```javascript
|
|
157
|
+
import { atlasobscura } from 'atlas-obscura-api';
|
|
158
|
+
|
|
159
|
+
atlasobscura.placeFull(494).then((place) => console.log(place));
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
#### Results
|
|
163
|
+
|
|
164
|
+
Same as short but with full description, tags and more, ... (TBD)
|
|
165
|
+
|
|
147
166
|
## Used by
|
|
148
167
|
|
|
149
168
|
🤷
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Coordinates } from 'interfaces/global';
|
|
2
|
-
import {
|
|
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';
|
|
5
5
|
import { PlacesScraper } from './services/location.service';
|
|
@@ -8,6 +8,7 @@ export declare class AtlasObscura {
|
|
|
8
8
|
constructor(locationService: PlacesScraper);
|
|
9
9
|
search(coords: Coordinates): Promise<LocationResult>;
|
|
10
10
|
placesAll(): Promise<PlacesAll[]>;
|
|
11
|
-
|
|
11
|
+
placeShort(id: number): Promise<PlaceShort>;
|
|
12
|
+
placeFull(id: number): Promise<Place>;
|
|
12
13
|
}
|
|
13
14
|
export declare const atlasobscura: AtlasObscura;
|
package/index.js
CHANGED
|
@@ -12,8 +12,13 @@ class AtlasObscura {
|
|
|
12
12
|
async placesAll() {
|
|
13
13
|
return this.locationService.placesAll();
|
|
14
14
|
}
|
|
15
|
-
async
|
|
16
|
-
return this.locationService.
|
|
15
|
+
async placeShort(id) {
|
|
16
|
+
return this.locationService.placeByIdShort(id);
|
|
17
|
+
}
|
|
18
|
+
async placeFull(id) {
|
|
19
|
+
const place = await this.locationService.placeByIdShort(id);
|
|
20
|
+
const placeRich = await this.locationService.placeFull(place.url);
|
|
21
|
+
return Object.assign(Object.assign({}, place), placeRich);
|
|
17
22
|
}
|
|
18
23
|
}
|
|
19
24
|
exports.AtlasObscura = AtlasObscura;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Coordinates } from './global';
|
|
2
|
-
export interface
|
|
2
|
+
export interface PlaceShort {
|
|
3
3
|
id: number;
|
|
4
4
|
title: string;
|
|
5
5
|
subtitle: string;
|
|
@@ -12,6 +12,16 @@ export interface PlaceById {
|
|
|
12
12
|
thumbnail_url: string;
|
|
13
13
|
thumbnail_url_3x2: string;
|
|
14
14
|
coordinates: Coordinates;
|
|
15
|
-
nearby_places:
|
|
16
|
-
nearby_foods:
|
|
15
|
+
nearby_places: PlaceShort[];
|
|
16
|
+
nearby_foods: PlaceShort[];
|
|
17
|
+
}
|
|
18
|
+
export interface PlaceExtend {
|
|
19
|
+
description?: string[];
|
|
20
|
+
tags?: Tag[];
|
|
21
|
+
}
|
|
22
|
+
export interface Tag {
|
|
23
|
+
title: string;
|
|
24
|
+
link: string;
|
|
25
|
+
}
|
|
26
|
+
export interface Place extends PlaceShort, PlaceExtend {
|
|
17
27
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "atlas-obscura-api",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "2.0.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>",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"cross-fetch": "^3.1.5",
|
|
26
|
-
"node-html-parser": "^
|
|
26
|
+
"node-html-parser": "^6.1.4"
|
|
27
27
|
},
|
|
28
28
|
"repository": {
|
|
29
29
|
"url": "git+https://github.com/bartholomej/atlas-obscura-api.git",
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Coordinates } from 'interfaces/global';
|
|
2
2
|
import { LocationResult } from 'interfaces/locations.interface';
|
|
3
|
-
import {
|
|
3
|
+
import { PlaceExtend, PlaceShort } from 'interfaces/placeId.interface';
|
|
4
4
|
import { PlacesAll } from 'interfaces/places-all.interface';
|
|
5
5
|
export declare class PlacesScraper {
|
|
6
6
|
placesAll(): Promise<PlacesAll[]>;
|
|
7
7
|
search(coords: Coordinates, page?: number): Promise<LocationResult>;
|
|
8
|
-
|
|
8
|
+
placeByIdShort(id: number): Promise<PlaceShort>;
|
|
9
|
+
placeFull(url: string): Promise<PlaceExtend>;
|
|
9
10
|
}
|
|
@@ -19,7 +19,7 @@ class PlacesScraper {
|
|
|
19
19
|
const data = html.match(/AtlasObscura\.place_search = (.*?);/);
|
|
20
20
|
return (0, utils_1.parseResults)(data);
|
|
21
21
|
}
|
|
22
|
-
async
|
|
22
|
+
async placeByIdShort(id) {
|
|
23
23
|
const url = (0, vars_1.urlPlaceId)(id);
|
|
24
24
|
const data = await (0, fetchers_1.fetchPage)(url);
|
|
25
25
|
let place = null;
|
|
@@ -31,5 +31,17 @@ class PlacesScraper {
|
|
|
31
31
|
}
|
|
32
32
|
return place;
|
|
33
33
|
}
|
|
34
|
+
async placeFull(url) {
|
|
35
|
+
const data = await (0, fetchers_1.fetchPage)(url);
|
|
36
|
+
const html = (0, node_html_parser_1.parse)(data);
|
|
37
|
+
const descriptions = html.querySelectorAll('#place-body p').map((p) => p.innerHTML);
|
|
38
|
+
const tags = html.querySelectorAll('.item-tags a.itemTags__link').map((x) => {
|
|
39
|
+
return {
|
|
40
|
+
title: x.innerHTML.trim(),
|
|
41
|
+
link: x.attributes.href
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
return { description: descriptions, tags: tags };
|
|
45
|
+
}
|
|
34
46
|
}
|
|
35
47
|
exports.PlacesScraper = PlacesScraper;
|