atlas-obscura-api 0.0.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 +212 -0
- package/fetchers/index.d.ts +1 -0
- package/fetchers/index.js +30 -0
- package/index.d.ts +13 -0
- package/index.js +21 -0
- package/interfaces/global.d.ts +4 -0
- package/interfaces/global.js +2 -0
- package/interfaces/locations.interface.d.ts +25 -0
- package/interfaces/locations.interface.js +2 -0
- package/interfaces/placeId.interface.d.ts +17 -0
- package/interfaces/placeId.interface.js +2 -0
- package/interfaces/places-all.interface.d.ts +4 -0
- package/interfaces/places-all.interface.js +2 -0
- package/package.json +54 -0
- package/services/location.service.d.ts +9 -0
- package/services/location.service.js +35 -0
- package/utils.d.ts +1 -0
- package/utils.js +17 -0
- package/vars.d.ts +6 -0
- package/vars.js +8 -0
package/README.md
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
[](https://badge.fury.io/js/atlas-obscura-api)
|
|
2
|
+
[](https://www.npmjs.com/atlas-obscura-api)
|
|
3
|
+
[](https://github.com/bartholomej/atlas-obscura-api/actions)
|
|
4
|
+
[](https://codecov.io/gh/bartholomej/atlas-obscura-api)
|
|
5
|
+
|
|
6
|
+
# Atlas Obscura API (Scraper)
|
|
7
|
+
|
|
8
|
+
> JavaScript NPM library for scraping **Atlas Obscura ([atlasobscura.com](atlasobscura.com))** [unofficial]
|
|
9
|
+
>
|
|
10
|
+
> - Browser + Node.js (SSR)
|
|
11
|
+
> - JavaScript / TypeScript
|
|
12
|
+
> - You can use in:
|
|
13
|
+
> - Firebase function
|
|
14
|
+
> - AWS λ (lambda function)
|
|
15
|
+
> - Chrome extension
|
|
16
|
+
> - React native app
|
|
17
|
+
> - ...
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install atlas-obscura-api --save
|
|
23
|
+
# yarn add atlas-obscura-api
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage and examples
|
|
27
|
+
|
|
28
|
+
- [All places](#All-places)
|
|
29
|
+
- [Search](#Search)
|
|
30
|
+
- [Show place by ID](#Show-place-by-ID)
|
|
31
|
+
|
|
32
|
+
### All Places
|
|
33
|
+
|
|
34
|
+
Give me all places locations
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
import { atlasobscura } from 'atlas-obscura-api';
|
|
38
|
+
|
|
39
|
+
atlasobscura.placesAll().then((places) => console.log(places));
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
#### Results
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
[
|
|
46
|
+
{ id: 46691, lat: 29.99022, lng: -95.336783 },
|
|
47
|
+
{ id: 46850, lat: 36.709674, lng: -92.266472 },
|
|
48
|
+
{ id: 46597, lat: 32.805765, lng: 35.169971 },
|
|
49
|
+
{ id: 43701, lat: 54.415365, lng: -1.260063 },
|
|
50
|
+
{ id: 46266, lat: 46.196648, lng: 8.848537 },
|
|
51
|
+
{ id: 46282, lat: 46.236906, lng: -60.100201 },
|
|
52
|
+
{ id: 46028, lat: 21.272772, lng: -157.823812 },
|
|
53
|
+
{ id: 46736, lat: 39.635311, lng: -76.268685 },
|
|
54
|
+
{ id: 45981, lat: 34.101644, lng: -118.329489 },
|
|
55
|
+
{ id: 45455, lat: 42.929702, lng: -75.852011 },
|
|
56
|
+
{ id: 46206, lat: 38.912474, lng: -77.037291 },
|
|
57
|
+
{ id: 46081, lat: 32.930318, lng: -110.709229 }
|
|
58
|
+
];
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Search
|
|
62
|
+
|
|
63
|
+
> Search places by coordinates
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
import { atlasobscura } from 'atlas-obscura-api';
|
|
67
|
+
|
|
68
|
+
atlasobscura.search({ lat: 34.0522, lng: -118.2437 }).then((search) => console.log(search));
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
#### Results
|
|
72
|
+
|
|
73
|
+
```javascript
|
|
74
|
+
[
|
|
75
|
+
{
|
|
76
|
+
title: 'Cathedral of Our Lady of the Angels',
|
|
77
|
+
subtitle:
|
|
78
|
+
"Crypt mausoleum in cathedral's basement contains relics of third century Roman martyr, Saint Vibiana.",
|
|
79
|
+
location: 'Los Angeles, California',
|
|
80
|
+
thumbnail_url:
|
|
81
|
+
'https://img.atlasobscura.com/YmNZy_5DUKw21Ppt5B4Ik8zo4qjrc9RkkgT1tnAghcE/rs:fill:200:200:1/g:ce/q:81/sm:1/scp:1/ar:1/aHR0cHM6Ly9hdGxh/cy1kZXYuczMuYW1h/em9uYXdzLmNvbS91/cGxvYWRzL3BsYWNl/X2ltYWdlcy8yMTky/MDAyOTQxXzEzNDEw/OTQxMDguanBn.jpg',
|
|
82
|
+
url: '/places/cathedral-our-lady-angels',
|
|
83
|
+
id: 1370,
|
|
84
|
+
hide_from_maps: 'false',
|
|
85
|
+
coordinates: [Object],
|
|
86
|
+
distance_from_query: '0.38'
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
title: 'The Last Bookstore',
|
|
90
|
+
subtitle: 'This iconic L.A. bookshop is housed in an abandoned bank—both symbolic and chic.',
|
|
91
|
+
location: 'Los Angeles, California',
|
|
92
|
+
thumbnail_url:
|
|
93
|
+
'https://img.atlasobscura.com/6XpPQSE2YVsqTDOuvfx9ZHsYY0NfmX7oLzEUL87DL4A/rs:fill:200:200:1/g:ce/q:81/sm:1/scp:1/ar:1/aHR0cHM6Ly9hdGxh/cy1kZXYuczMuYW1h/em9uYXdzLmNvbS91/cGxvYWRzL3BsYWNl/X2ltYWdlcy8xMmI0/MzBkMDJjZjc2MjBj/ODJfbGIxLmpwZw.jpg',
|
|
94
|
+
url: '/places/last-bookstore',
|
|
95
|
+
id: 6159,
|
|
96
|
+
hide_from_maps: 'false',
|
|
97
|
+
coordinates: [Object],
|
|
98
|
+
distance_from_query: '0.45'
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
title: 'Wells Fargo History Museum',
|
|
102
|
+
subtitle:
|
|
103
|
+
'Hidden in one of the skyscrapers on Bunker Hill, this museum features an 1895 stagecoach and peers into California’s gold-lined history.',
|
|
104
|
+
location: 'Los Angeles, California',
|
|
105
|
+
thumbnail_url:
|
|
106
|
+
'https://img.atlasobscura.com/27GLJ0vkGogC-l1AK5CuJKxS5FrBcNrcOROTWja4FAc/rs:fill:200:200:1/g:ce/c:2483:1655:nowe:2:126/q:81/sm:1/scp:1/ar:1/aHR0cHM6Ly9hdGxh/cy1kZXYuczMuYW1h/em9uYXdzLmNvbS91/cGxvYWRzL3BsYWNl/X2ltYWdlcy80Mjg4/ZWJjZC0zYmNhLTQw/MTgtYTMzOC0wMTkz/M2FjNzVmZGIxMmQ4/MmVlYTgyY2IwMTM4/NTZfSU1HXzIwMTgw/ODI5XzE0NTE0NS5q/cGc.jpg',
|
|
107
|
+
url: '/places/wells-fargo-history-museum-los-angeles',
|
|
108
|
+
id: 28174,
|
|
109
|
+
hide_from_maps: 'false',
|
|
110
|
+
coordinates: [Object],
|
|
111
|
+
distance_from_query: '0.47'
|
|
112
|
+
}
|
|
113
|
+
];
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Show place by ID
|
|
117
|
+
|
|
118
|
+
> Get place by id
|
|
119
|
+
|
|
120
|
+
```javascript
|
|
121
|
+
import { atlasobscura } from 'atlas-obscura-api';
|
|
122
|
+
|
|
123
|
+
atlasobscura.placeById(494).then((place) => console.log(place));
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
#### Results
|
|
127
|
+
|
|
128
|
+
```javascript
|
|
129
|
+
{
|
|
130
|
+
id: 494,
|
|
131
|
+
title: 'Bodie State Historic Park',
|
|
132
|
+
subtitle: 'Standing in a state of "arrested decay," this ghost town allows for a detailed peek into Gold Rush life in an unusually harsh climate.',
|
|
133
|
+
city: 'Bridgeport',
|
|
134
|
+
country: 'United States',
|
|
135
|
+
location: 'Bridgeport, California',
|
|
136
|
+
url: 'https://www.atlasobscura.com/places/bodie-state-historical-park',
|
|
137
|
+
hide_from_maps: 'false',
|
|
138
|
+
physical_status: '',
|
|
139
|
+
thumbnail_url: 'https://img.atlasobscura.com/DzPFF3feclAXS5apzZq6HqIgaKUSxGzIEKTfCpnfKxY/rs:fill:200:200:1/g:ce/c:815:543:nowe:0:633/q:81/sm:1/scp:1/ar:1/aHR0cHM6Ly9hdGxh/cy1kZXYuczMuYW1h/em9uYXdzLmNvbS91/cGxvYWRzL3BsYWNl/X2ltYWdlcy85MDY0/ZDNkODljYjdmNjI0/ZWViMzA0NjU0ZjM4/ZGI5MTYzODVkZTRh/LmpwZw.jpg',
|
|
140
|
+
thumbnail_url_3x2: 'https://img.atlasobscura.com/uCGcoetx8YfBtMOBo4oe1_6wUF7CM8AOK3L04aN9cg0/rs:fill:204:136:1/g:ce/c:815:543:nowe:0:633/q:81/sm:1/scp:1/ar:1/aHR0cHM6Ly9hdGxh/cy1kZXYuczMuYW1h/em9uYXdzLmNvbS91/cGxvYWRzL3BsYWNl/X2ltYWdlcy85MDY0/ZDNkODljYjdmNjI0/ZWViMzA0NjU0ZjM4/ZGI5MTYzODVkZTRh/LmpwZw.jpg',
|
|
141
|
+
coordinates: { lat: 38.208804, lng: -119.014163 },
|
|
142
|
+
nearby_places: [],
|
|
143
|
+
nearby_foods: []
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Used by
|
|
148
|
+
|
|
149
|
+
🤷
|
|
150
|
+
|
|
151
|
+
## Development
|
|
152
|
+
|
|
153
|
+
### Developing and debugging library
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
yarn start
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Run demo locally
|
|
160
|
+
|
|
161
|
+
You can find and modify it in [`./demo.ts`](https://github.com/bartholomej/atlas-obscura-api/blob/master/demo.ts) file
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
yarn demo
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Development (notes for me)
|
|
168
|
+
|
|
169
|
+
### Publish Stable
|
|
170
|
+
|
|
171
|
+
```shell
|
|
172
|
+
yarn release:patch
|
|
173
|
+
# yarn release:minor
|
|
174
|
+
# yarn release:major
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Publish next channel
|
|
178
|
+
|
|
179
|
+
1. Bump version `-beta.0` in `package.json`
|
|
180
|
+
2. `yarn release:beta`
|
|
181
|
+
|
|
182
|
+
## Contribution
|
|
183
|
+
|
|
184
|
+
I welcome you to customize this according to your needs ;)
|
|
185
|
+
|
|
186
|
+
Pull requests for any improvements would be great!
|
|
187
|
+
|
|
188
|
+
## ⭐️ Show your support
|
|
189
|
+
|
|
190
|
+
Give a ⭐️ if this project helped you!
|
|
191
|
+
|
|
192
|
+
Or if you are brave enough consider [making a donation](https://github.com/sponsors/bartholomej) for some 🍺 or 🍵 ;)
|
|
193
|
+
|
|
194
|
+
## Privacy Policy
|
|
195
|
+
|
|
196
|
+
I DO NOT STORE ANY DATA. PERIOD.
|
|
197
|
+
|
|
198
|
+
I physically can't. I have nowhere to store it. I don't even have a server database to store it. So even if Justin Bieber asked nicely to see your data, I wouldn't have anything to show him.
|
|
199
|
+
|
|
200
|
+
That's why, with atlas obscura api, what happens on your device stays on your device till disappear.
|
|
201
|
+
|
|
202
|
+
## License
|
|
203
|
+
|
|
204
|
+
Copyright © 2022 [Lukas Bartak](http://bartweb.cz)
|
|
205
|
+
|
|
206
|
+
Proudly powered by nature 🗻, wind 💨, tea 🍵 and beer 🍺 ;)
|
|
207
|
+
|
|
208
|
+
**This is unofficial, experimental, made for fun and it has nothing to do with Atlas Obscura ❤️ itself**
|
|
209
|
+
|
|
210
|
+
All contents are licensed under the [MIT license].
|
|
211
|
+
|
|
212
|
+
[mit license]: LICENSE
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const fetchPage: (url: string) => Promise<string>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.fetchPage = void 0;
|
|
7
|
+
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
8
|
+
const USER_AGENTS = [
|
|
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
|
+
'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
|
+
'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'
|
|
13
|
+
];
|
|
14
|
+
const headers = {
|
|
15
|
+
'User-Agent': USER_AGENTS[Math.floor(Math.random() * USER_AGENTS.length)]
|
|
16
|
+
};
|
|
17
|
+
const fetchPage = async (url) => {
|
|
18
|
+
try {
|
|
19
|
+
const response = await (0, cross_fetch_1.default)(url, { headers });
|
|
20
|
+
if (response.status >= 400 && response.status < 600) {
|
|
21
|
+
throw new Error(`atlas-obscura-api: Bad response ${response.status} for url: ${url}`);
|
|
22
|
+
}
|
|
23
|
+
return await response.text();
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
console.error(e);
|
|
27
|
+
return 'Error';
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.fetchPage = fetchPage;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Coordinates } from 'interfaces/global';
|
|
2
|
+
import { PlaceById } from 'interfaces/placeId.interface';
|
|
3
|
+
import { PlacesAll } from 'interfaces/places-all.interface';
|
|
4
|
+
import { LocationResult } from './interfaces/locations.interface';
|
|
5
|
+
import { PlacesScraper } from './services/location.service';
|
|
6
|
+
export declare class AtlasObscura {
|
|
7
|
+
private locationService;
|
|
8
|
+
constructor(locationService: PlacesScraper);
|
|
9
|
+
search(coords: Coordinates): Promise<LocationResult>;
|
|
10
|
+
placesAll(): Promise<PlacesAll[]>;
|
|
11
|
+
placeById(id: number): Promise<PlaceById>;
|
|
12
|
+
}
|
|
13
|
+
export declare const atlasobscura: AtlasObscura;
|
package/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.atlasobscura = exports.AtlasObscura = void 0;
|
|
4
|
+
const location_service_1 = require("./services/location.service");
|
|
5
|
+
class AtlasObscura {
|
|
6
|
+
constructor(locationService) {
|
|
7
|
+
this.locationService = locationService;
|
|
8
|
+
}
|
|
9
|
+
async search(coords) {
|
|
10
|
+
return this.locationService.search(coords);
|
|
11
|
+
}
|
|
12
|
+
async placesAll() {
|
|
13
|
+
return this.locationService.placesAll();
|
|
14
|
+
}
|
|
15
|
+
async placeById(id) {
|
|
16
|
+
return this.locationService.placeById(id);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.AtlasObscura = AtlasObscura;
|
|
20
|
+
const locationScraper = new location_service_1.PlacesScraper();
|
|
21
|
+
exports.atlasobscura = new AtlasObscura(locationScraper);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Coordinates } from './global';
|
|
2
|
+
export interface LocationResult {
|
|
3
|
+
total: Total;
|
|
4
|
+
per_page: number;
|
|
5
|
+
current_page: number;
|
|
6
|
+
location: string;
|
|
7
|
+
q: string;
|
|
8
|
+
coordinates: Coordinates;
|
|
9
|
+
results: Location[];
|
|
10
|
+
}
|
|
11
|
+
export interface Location {
|
|
12
|
+
title: string;
|
|
13
|
+
subtitle: string;
|
|
14
|
+
location: string;
|
|
15
|
+
thumbnail_url: string;
|
|
16
|
+
url: string;
|
|
17
|
+
id: number;
|
|
18
|
+
hide_from_maps?: string;
|
|
19
|
+
coordinates: Coordinates;
|
|
20
|
+
distance_from_query: string;
|
|
21
|
+
}
|
|
22
|
+
export interface Total {
|
|
23
|
+
value: number;
|
|
24
|
+
relation: string;
|
|
25
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Coordinates } from './global';
|
|
2
|
+
export interface PlaceById {
|
|
3
|
+
id: number;
|
|
4
|
+
title: string;
|
|
5
|
+
subtitle: string;
|
|
6
|
+
city: string;
|
|
7
|
+
country: string;
|
|
8
|
+
location: string;
|
|
9
|
+
url: string;
|
|
10
|
+
hide_from_maps?: boolean;
|
|
11
|
+
physical_status: string;
|
|
12
|
+
thumbnail_url: string;
|
|
13
|
+
thumbnail_url_3x2: string;
|
|
14
|
+
coordinates: Coordinates;
|
|
15
|
+
nearby_places: PlaceById[];
|
|
16
|
+
nearby_foods: PlaceById[];
|
|
17
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "atlas-obscura-api",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Atlas Obscura API in JavaScript. NPM library for scrapping atlasobscura.com",
|
|
5
|
+
"main": "./index.js",
|
|
6
|
+
"author": "BART! <bart@bartweb.cz>",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"start": "tsc -w",
|
|
9
|
+
"prebuild": "rimraf dist",
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"postbuild": "npm-prepare-dist -s postinstall -s prepare",
|
|
12
|
+
"tsc": "tsc",
|
|
13
|
+
"demo": "ts-node demo",
|
|
14
|
+
"lint": "eslint ./src/**/**/* --fix",
|
|
15
|
+
"test": "jest",
|
|
16
|
+
"publish:next": "yarn && yarn build && yarn test --coverage true && npm publish --folder dist --tag beta",
|
|
17
|
+
"postversion": "git push && git push --follow-tags",
|
|
18
|
+
"release:beta": "npm version preminor --preid=beta -m \"chore(update): prelease %s β\"",
|
|
19
|
+
"prerelease:beta": "npm version prerelease --preid=beta -m \"chore(update): prelease %s β\"",
|
|
20
|
+
"release:patch": "git checkout master && npm version patch -m \"chore(update): patch release %s 🐛\"",
|
|
21
|
+
"release:minor": "git checkout master && npm version minor -m \"chore(update): release %s 🚀\"",
|
|
22
|
+
"release:major": "git checkout master && npm version major -m \"chore(update): major release %s 💥\""
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"cross-fetch": "^3.1.5",
|
|
26
|
+
"node-html-parser": "^5.4.2-0"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"url": "git+https://github.com/bartholomej/atlas-obscura-api.git",
|
|
30
|
+
"type": "git"
|
|
31
|
+
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/bartholomej/atlas-obscura-api/issues"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/bartholomej/atlas-obscura-api#readme",
|
|
36
|
+
"keywords": [
|
|
37
|
+
"travellers",
|
|
38
|
+
"atlasobscura",
|
|
39
|
+
"places",
|
|
40
|
+
"maps",
|
|
41
|
+
"nodejs",
|
|
42
|
+
"node",
|
|
43
|
+
"typescript",
|
|
44
|
+
"scraper",
|
|
45
|
+
"parser",
|
|
46
|
+
"api"
|
|
47
|
+
],
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">= 14"
|
|
50
|
+
},
|
|
51
|
+
"license": "MIT",
|
|
52
|
+
"module": "./index.js",
|
|
53
|
+
"types": "./index.d.ts"
|
|
54
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Coordinates } from 'interfaces/global';
|
|
2
|
+
import { LocationResult } from 'interfaces/locations.interface';
|
|
3
|
+
import { PlaceById } from 'interfaces/placeId.interface';
|
|
4
|
+
import { PlacesAll } from 'interfaces/places-all.interface';
|
|
5
|
+
export declare class PlacesScraper {
|
|
6
|
+
placesAll(): Promise<PlacesAll[]>;
|
|
7
|
+
search(coords: Coordinates, page?: number): Promise<LocationResult>;
|
|
8
|
+
placeById(id: number): Promise<PlaceById>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlacesScraper = void 0;
|
|
4
|
+
const node_html_parser_1 = require("node-html-parser");
|
|
5
|
+
const fetchers_1 = require("../fetchers");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const vars_1 = require("../vars");
|
|
8
|
+
class PlacesScraper {
|
|
9
|
+
async placesAll() {
|
|
10
|
+
const response = await (0, fetchers_1.fetchPage)(vars_1.URL_PLACES_ALL);
|
|
11
|
+
const html = (0, node_html_parser_1.parse)(response).innerHTML;
|
|
12
|
+
const data = html.match(/AtlasObscura\.all_places = (.*?);/);
|
|
13
|
+
return (0, utils_1.parseResults)(data);
|
|
14
|
+
}
|
|
15
|
+
async search(coords, page = 1) {
|
|
16
|
+
const url = (0, vars_1.urlSearch)(coords, page);
|
|
17
|
+
const response = await (0, fetchers_1.fetchPage)(url);
|
|
18
|
+
const html = (0, node_html_parser_1.parse)(response).innerHTML;
|
|
19
|
+
const data = html.match(/AtlasObscura\.place_search = (.*?);/);
|
|
20
|
+
return (0, utils_1.parseResults)(data);
|
|
21
|
+
}
|
|
22
|
+
async placeById(id) {
|
|
23
|
+
const url = (0, vars_1.urlPlaceId)(id);
|
|
24
|
+
const data = await (0, fetchers_1.fetchPage)(url);
|
|
25
|
+
let place = null;
|
|
26
|
+
try {
|
|
27
|
+
place = JSON.parse(data);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
console.error('Error parsing placeById', id);
|
|
31
|
+
}
|
|
32
|
+
return place;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.PlacesScraper = PlacesScraper;
|
package/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const parseResults: <T>(matches: RegExpMatchArray) => T;
|
package/utils.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseResults = void 0;
|
|
4
|
+
const parseResults = (matches) => {
|
|
5
|
+
var _a;
|
|
6
|
+
let locations = null;
|
|
7
|
+
if (matches && ((_a = matches[1]) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
8
|
+
try {
|
|
9
|
+
locations = JSON.parse(matches[1]);
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
console.error('Error parsing all places');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return locations;
|
|
16
|
+
};
|
|
17
|
+
exports.parseResults = parseResults;
|
package/vars.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const URL_PLACES_ALL = "https://www.atlasobscura.com/articles/all-places-in-the-atlas-on-one-map";
|
|
2
|
+
export declare const urlSearch: (coord: {
|
|
3
|
+
lat: number;
|
|
4
|
+
lng: number;
|
|
5
|
+
}, page?: number) => string;
|
|
6
|
+
export declare const urlPlaceId: (id: number) => string;
|
package/vars.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.urlPlaceId = exports.urlSearch = exports.URL_PLACES_ALL = void 0;
|
|
4
|
+
exports.URL_PLACES_ALL = 'https://www.atlasobscura.com/articles/all-places-in-the-atlas-on-one-map';
|
|
5
|
+
const urlSearch = (coord, page) => `https://www.atlasobscura.com/search?utf8=%E2%9C%93&q=&location=&nearby=true&lat=${coord.lat}&lng=${coord.lng}${page ? '&page=' + page : ''}`;
|
|
6
|
+
exports.urlSearch = urlSearch;
|
|
7
|
+
const urlPlaceId = (id) => `https://www.atlasobscura.com/places/${id}.json?place_only=1`;
|
|
8
|
+
exports.urlPlaceId = urlPlaceId;
|