atlas-obscura-api 0.0.1 → 2.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 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
- > Get place by id
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.placeById(494).then((place) => console.log(place));
124
- ```
128
+ atlasobscura.placeShort(494).then((place) => console.log(place));
129
+ ````
125
130
 
126
131
  #### Results
127
132
 
@@ -144,9 +149,24 @@ 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, directions and more, ... (TBD)
165
+
147
166
  ## Used by
148
167
 
149
- 🤷
168
+ - Atlas Obscura Offline mobile app (Android, iOS)
169
+ - 🤷
150
170
 
151
171
  ## Development
152
172
 
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Coordinates } from 'interfaces/global';
2
- import { PlaceById } from 'interfaces/placeId.interface';
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
- placeById(id: number): Promise<PlaceById>;
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 placeById(id) {
16
- return this.locationService.placeById(id);
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 PlaceById {
2
+ export interface PlaceShort {
3
3
  id: number;
4
4
  title: string;
5
5
  subtitle: string;
@@ -12,6 +12,17 @@ export interface PlaceById {
12
12
  thumbnail_url: string;
13
13
  thumbnail_url_3x2: string;
14
14
  coordinates: Coordinates;
15
- nearby_places: PlaceById[];
16
- nearby_foods: PlaceById[];
15
+ nearby_places: PlaceShort[];
16
+ nearby_foods: PlaceShort[];
17
+ }
18
+ export interface PlaceExtend {
19
+ description?: string[];
20
+ tags?: Tag[];
21
+ directions?: string[];
22
+ }
23
+ export interface Tag {
24
+ title: string;
25
+ link: string;
26
+ }
27
+ export interface Place extends PlaceShort, PlaceExtend {
17
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "atlas-obscura-api",
3
- "version": "0.0.1",
3
+ "version": "2.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>",
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "cross-fetch": "^3.1.5",
26
- "node-html-parser": "^5.4.2-0"
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 { PlaceById } from 'interfaces/placeId.interface';
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
- placeById(id: number): Promise<PlaceById>;
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 placeById(id) {
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,21 @@ 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 directions = html
39
+ .querySelectorAll('.DDP__direction-copy p')
40
+ .map((p) => p.innerHTML)
41
+ .filter((x) => x !== '');
42
+ const tags = html.querySelectorAll('.item-tags a.itemTags__link').map((x) => {
43
+ return {
44
+ title: x.innerHTML.trim(),
45
+ link: x.attributes.href
46
+ };
47
+ });
48
+ return { description: descriptions, directions: directions, tags: tags };
49
+ }
34
50
  }
35
51
  exports.PlacesScraper = PlacesScraper;