atlas-obscura-api 4.2.0 → 4.3.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 +68 -7
- package/index.js +0 -24
- package/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -7,14 +7,17 @@
|
|
|
7
7
|
|
|
8
8
|
> JavaScript NPM library for scraping **Atlas Obscura ([atlasobscura.com](https://atlasobscura.com))** [unofficial]
|
|
9
9
|
>
|
|
10
|
-
> - Browser + Node.js
|
|
10
|
+
> - Browser + Node.js
|
|
11
11
|
> - JavaScript / TypeScript
|
|
12
|
+
> - ESM + CJS support
|
|
12
13
|
> - You can use in:
|
|
14
|
+
> - Serverless functions
|
|
13
15
|
> - Firebase function
|
|
14
16
|
> - AWS λ (lambda function)
|
|
15
17
|
> - Chrome extension
|
|
16
18
|
> - React native app
|
|
17
19
|
> - Docker container
|
|
20
|
+
> - Node.js app
|
|
18
21
|
> - ...
|
|
19
22
|
|
|
20
23
|
## 📦 Installation
|
|
@@ -33,6 +36,7 @@ Explore how to use the library with practical code snippets and sample outputs b
|
|
|
33
36
|
- [Search](#search)
|
|
34
37
|
- [Show place by ID (short)](#short-version-one-quick-request)
|
|
35
38
|
- [Show place by ID (full)](#full-detail-two-internal-requests)
|
|
39
|
+
- [User](#user)
|
|
36
40
|
|
|
37
41
|
### All Places
|
|
38
42
|
|
|
@@ -209,6 +213,62 @@ atlasObscura.placeFull(494).then((place) => console.log(place));
|
|
|
209
213
|
}
|
|
210
214
|
```
|
|
211
215
|
|
|
216
|
+
#### User
|
|
217
|
+
|
|
218
|
+
> Get user by nickname
|
|
219
|
+
|
|
220
|
+
```javascript
|
|
221
|
+
import { atlasObscura } from 'atlas-obscura-api';
|
|
222
|
+
|
|
223
|
+
atlasObscura.user('bartholomej').then((user) => console.log(user));
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
#### Results
|
|
227
|
+
|
|
228
|
+
```javascript
|
|
229
|
+
{
|
|
230
|
+
"id": 251656,
|
|
231
|
+
"places": [
|
|
232
|
+
{
|
|
233
|
+
"id": 15078,
|
|
234
|
+
"title": "Roskilde Viking Ship Museum ",
|
|
235
|
+
"subtitle": "Nordic giants resurrected from the sea and restored to their former greatness.",
|
|
236
|
+
"url": "https://www.atlasobscura.com/places/roskilde-viking-ship-museum",
|
|
237
|
+
"location": "Roskilde, Denmark",
|
|
238
|
+
"thumbnail_url": "https://img.atlasobscura.com/DjHjzdzd3l7b8AN47HKwpt8GYmG83Yo2pVJdmr2bhWY/rs:fill:200:200:1/g:ce/q:81/sm:1/scp:1/ar:1/aHR0cHM6Ly9hdGxh/cy1kZXYuczMuYW1h/em9uYXdzLmNvbS91/cGxvYWRzL3BsYWNl/X2ltYWdlcy8xODRm/NTFjYjAzMzM3OTFh/ZTBfSU1HXzAyODcu/SlBH.jpg",
|
|
239
|
+
"coordinates": {
|
|
240
|
+
"lat": 55.649645,
|
|
241
|
+
"lng": 12.077977
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
"id": 58990,
|
|
246
|
+
"title": "Grave of the Hel-Horse",
|
|
247
|
+
"subtitle": "According to legend, this is the burial place of a mythical three-legged death omen horse.",
|
|
248
|
+
"url": "https://www.atlasobscura.com/places/grave-of-the-hel-horse-roskilde",
|
|
249
|
+
"location": "Roskilde, Denmark",
|
|
250
|
+
"thumbnail_url": "https://img.atlasobscura.com/5jjvXXDD7Mravpa0EZiIluytCKiQYjfl_EtPakLaK-Q/rs:fill:200:200:1/g:ce/q:81/sm:1/scp:1/ar:1/aHR0cHM6Ly9hdGxh/cy1kZXYuczMuYW1h/em9uYXdzLmNvbS91/cGxvYWRzL3BsYWNl/X2ltYWdlcy9jYjk1/MjBjMy01NjNlLTRj/ZjItOTY4Yi1iNmY5/MGY5ZWFkZjZiY2Zi/NmE2NTgwYWQ5NGFl/ZTJfMjAyNDA1MThf/MTIwMDIyLmpwZw.jpg",
|
|
251
|
+
"coordinates": {
|
|
252
|
+
"lat": 55.642489,
|
|
253
|
+
"lng": 12.079727
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
"id": 51651,
|
|
258
|
+
"title": "Kamo River Turtle Stepping Stones ",
|
|
259
|
+
"subtitle": "These turtle-shaped concrete stepping stones provide a unique river crossing in central Kyoto. ",
|
|
260
|
+
"url": "https://www.atlasobscura.com/places/kamogawa-river-turtle-stepping-stones",
|
|
261
|
+
"location": "Kyoto, Japan",
|
|
262
|
+
"thumbnail_url": "https://img.atlasobscura.com/XmjRSPUfP2jQwVQrLFRckpb_UPUTCuDWJ8zqZJt9Wfc/rs:fill:200:200:1/g:ce/c:2997:1998:nowe:4:1914/q:81/sm:1/scp:1/ar:1/aHR0cHM6Ly9hdGxh/cy1kZXYuczMuYW1h/em9uYXdzLmNvbS91/cGxvYWRzL3BsYWNl/X2ltYWdlcy85ZDEz/M2FiMi0xMWFkLTQ5/ODgtYThiYy1hYmI3/N2E0NTBhNzc3MDNl/M2FjMjcyOTJmMjQ3/MTlfN0MxRUJFMUYt/REU1Ni00M0VBLTg0/ODctN0U4MEZGMDVD/RDNDLmpwZWc.jpg",
|
|
263
|
+
"coordinates": {
|
|
264
|
+
"lat": 35.029859,
|
|
265
|
+
"lng": 135.771764
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
]
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
|
|
212
272
|
## 📦 Docker
|
|
213
273
|
|
|
214
274
|
You can use this library in Docker.
|
|
@@ -241,15 +301,16 @@ docker run -p 3000:3000 atlas-obscura-api
|
|
|
241
301
|
|
|
242
302
|
> Some examples
|
|
243
303
|
|
|
244
|
-
- `/
|
|
245
|
-
- `/search/
|
|
246
|
-
- `/
|
|
247
|
-
- `/
|
|
304
|
+
- `/places-all`
|
|
305
|
+
- `/search/prague`
|
|
306
|
+
- `/place-short/465`
|
|
307
|
+
- `/place-full/456`
|
|
308
|
+
- `/user/bartholomej`
|
|
248
309
|
|
|
249
310
|
## Used By
|
|
250
311
|
|
|
251
|
-
- Atlas Obscura Offline
|
|
252
|
-
-
|
|
312
|
+
- Mobile app: Atlas Obscura: Offline → [Play Store](https://play.google.com/store/apps/details?id=com.aquasoup.atlasobscura)
|
|
313
|
+
- Chrome extension: Atlas Obscura Tabs → [Chrome Web Store](https://chromewebstore.google.com/detail/atlas-obscura-tabs-unoffi/jdbhojildmiebfbfepepcampalojdpdc)
|
|
253
314
|
|
|
254
315
|
## Development
|
|
255
316
|
|
package/index.js
CHANGED
|
@@ -1,28 +1,4 @@
|
|
|
1
|
-
//#region rolldown:runtime
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
-
key = keys[i];
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
-
get: ((k) => from[k]).bind(null, key),
|
|
13
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
-
value: mod,
|
|
20
|
-
enumerable: true
|
|
21
|
-
}) : target, mod));
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
1
|
let node_html_parser = require("node-html-parser");
|
|
25
|
-
node_html_parser = __toESM(node_html_parser);
|
|
26
2
|
|
|
27
3
|
//#region src/fetchers/index.ts
|
|
28
4
|
const USER_AGENTS = [
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["USER_AGENTS: string[]","locations: T","place: AOPlaceShort","locationService: PlacesScraper","atlasObscura: AtlasObscura"],"sources":["../src/fetchers/index.ts","../src/utils.ts","../src/vars.ts","../src/services/location.service.ts","../src/index.ts"],"sourcesContent":["const USER_AGENTS: string[] = [\n 'Dalvik/2.1.0 (Linux; U; Android 8.1.0; C6L Build/OPM2.171019.012)',\n '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',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/14E5239e Safari/602.1',\n 'Dalvik/2.1.0 (Linux; U; Android 11; SM-A505GT Build/RP1A.200720.012)',\n 'Mozilla/5.0 (Windows NT 10.3;; en-US) AppleWebKit/602.25 (KHTML, like Gecko) Chrome/54.0.2457.241 Safari/534.5 Edge/9.65405',\n 'Mozilla/5.0 (Windows; U; Windows NT 10.4; x64) AppleWebKit/536.41 (KHTML, like Gecko) Chrome/53.0.3535.112 Safari/600.5 Edge/14.39786',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_4_0; like Mac OS X) AppleWebKit/601.9 (KHTML, like Gecko) Chrome/47.0.2876.394 Mobile Safari/600.5',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_6_3; like Mac OS X) AppleWebKit/602.24 (KHTML, like Gecko) Chrome/54.0.3204.297 Mobile Safari/537.0',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_9_6; like Mac OS X) AppleWebKit/601.4 (KHTML, like Gecko) Chrome/55.0.2808.105 Mobile Safari/600.4',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_2_1; like Mac OS X) AppleWebKit/600.14 (KHTML, like Gecko) Chrome/50.0.3808.259 Mobile Safari/534.1',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_4_2; like Mac OS X) AppleWebKit/534.21 (KHTML, like Gecko) Chrome/47.0.3531.351 Mobile Safari/533.0'\n];\n\nconst DEFAULT_HEADERS = {\n 'User-Agent': USER_AGENTS[Math.floor(Math.random() * USER_AGENTS.length)],\n 'Cache-Control': 'no-cache',\n};\n\nexport const fetchPage = async (url: string, headersCustom?: Headers): Promise<string> => {\n try {\n const response = await fetch(url, {\n headers: { ...DEFAULT_HEADERS, ...headersCustom },\n credentials: 'omit'\n });\n\n if (!response.ok) {\n throw new Error(`atlas-obscura-api: Bad response ${response.status} for url: ${url}`);\n }\n\n return await response.text();\n } catch (error) {\n console.error('fetchPage error:', error);\n return 'Error';\n }\n};\n","export const parseResults = <T>(matches: RegExpMatchArray): T => {\n let locations: T = null;\n\n if (matches && matches[1]?.length) {\n try {\n locations = JSON.parse(matches[1]);\n } catch (error) {\n console.error('Error parsing all places');\n }\n }\n return locations;\n};\n","export const URL_PLACES_ALL =\n 'https://www.atlasobscura.com/articles/all-places-in-the-atlas-on-one-map';\n\nexport const urlSearch = (coord: { lat: number; lng: number }, page?: number): string =>\n `https://www.atlasobscura.com/search?utf8=%E2%9C%93&q=&location=&nearby=true&lat=${coord.lat\n }&lng=${coord.lng}${page ? '&page=' + page : ''}`;\n\nexport const urlPlaceId = (id: number): string =>\n `https://www.atlasobscura.com/places/${id}.json?place_only=1`;\n\nexport const urlUser = (name: string): string =>\n `https://www.atlasobscura.com/users/${name}`;\n","import { parse } from 'node-html-parser';\nimport { fetchPage } from '../fetchers/index.js';\nimport { AOUser } from '../interfaces/user.interface.js';\nimport { parseResults } from '../utils.js';\nimport { URL_PLACES_ALL, urlPlaceId, urlSearch, urlUser } from '../vars.js';\nimport { AOCoordinates, AOFetchOptions } from './../interfaces/global.js';\nimport { AOLocationResult } from './../interfaces/locations.interface.js';\nimport { AOPlaceExtend, AOPlaceShort } from './../interfaces/placeId.interface.js';\nimport { AOPlacesAll } from './../interfaces/places-all.interface.js';\n\nexport class PlacesScraper {\n public async placesAll(options?: AOFetchOptions): Promise<AOPlacesAll[]> {\n const response = await fetchPage(URL_PLACES_ALL, options?.headers);\n const html = parse(response).innerHTML;\n\n const data = html.match(/AtlasObscura\\.all_places = (.*?);/);\n\n return parseResults<AOPlacesAll[]>(data);\n }\n\n public async search(coords: AOCoordinates, page = 1, options?: AOFetchOptions): Promise<AOLocationResult> {\n const url = urlSearch(coords, page);\n const response = await fetchPage(url, options?.headers);\n const html = parse(response).innerHTML;\n\n const data = html.match(/AtlasObscura\\.place_search = (.*?);/);\n\n return parseResults<AOLocationResult>(data);\n }\n\n public async placeByIdShort(id: number, options?: AOFetchOptions): Promise<AOPlaceShort> {\n const url = urlPlaceId(id);\n const data = await fetchPage(url, options?.headers);\n\n let place: AOPlaceShort = null;\n\n try {\n place = JSON.parse(data);\n if (place && typeof place.hide_from_maps === 'string') {\n (place as any).hide_from_maps = place.hide_from_maps === 'true';\n }\n } catch (error) {\n console.error('Error parsing placeById', id);\n }\n return place;\n }\n\n public async placeFull(url: string, options?: AOFetchOptions): Promise<AOPlaceExtend> {\n const data = await fetchPage(url, options?.headers);\n const html = parse(data);\n\n const descriptions = html.querySelectorAll('.place-body p').map((p) => p.innerHTML);\n\n const sectionDirections = Array.from(html.querySelectorAll('section')).find((sec) => {\n const h2 = sec.querySelector('h2');\n return h2 && h2.textContent.trim() === 'Know Before You Go';\n });\n const directions = sectionDirections\n ? Array.from(sectionDirections.querySelectorAll('p')).map((p) => p.textContent.trim())\n : [];\n\n const tags = html.querySelectorAll('.aon-pill-badge-component').map((x) => {\n return {\n title: x.querySelector('.aon-pill-badge-text')?.innerHTML.trim(),\n link: x.attributes.href\n };\n });\n\n const slides = html.querySelectorAll('.swiper-slide');\n const images = Array.from(slides)\n .map((slide) => {\n const img = slide.querySelector('img');\n return img ? img.getAttribute('src') : null;\n })\n .filter(Boolean);\n\n const imageCover = images[0];\n\n return { description: descriptions, directions, tags, imageCover, images };\n }\n\n public async user(user: string, options?: AOFetchOptions): Promise<AOUser> {\n const url = urlUser(user);\n const response = await fetchPage(url, options?.headers);\n const html = parse(response).innerHTML;\n\n const data = html.match(/AtlasObscura\\.user_profile = (.*?);/);\n\n const usr = parseResults<{ user: AOUser }>(data);\n\n return usr.user;\n }\n}\n","import { AOCoordinates, AOFetchOptions } from './interfaces/global.js';\nimport { AOLocationResult } from './interfaces/locations.interface.js';\nimport { AOPlace, AOPlaceShort } from './interfaces/placeId.interface.js';\nimport { AOPlacesAll } from './interfaces/places-all.interface.js';\nimport { AOUser } from './interfaces/user.interface.js';\nimport { PlacesScraper } from './services/location.service.js';\n\nexport class AtlasObscura {\n constructor(private locationService: PlacesScraper) { }\n\n public async search(coords: AOCoordinates, options?: AOFetchOptions): Promise<AOLocationResult> {\n return this.locationService.search(coords, 1, options);\n }\n\n public async placesAll(options?: AOFetchOptions): Promise<AOPlacesAll[]> {\n return this.locationService.placesAll(options);\n }\n\n public async placeShort(id: number, options?: AOFetchOptions): Promise<AOPlaceShort> {\n return this.locationService.placeByIdShort(id, options);\n }\n\n public async placeFull(id: number, options?: AOFetchOptions): Promise<AOPlace> {\n const place = await this.locationService.placeByIdShort(id, options);\n const placeRich = await this.locationService.placeFull(place.url, options);\n return { ...place, ...placeRich };\n }\n\n public async user(user: string, options?: AOFetchOptions): Promise<AOUser> {\n return this.locationService.user(user, options);\n }\n}\n\nconst locationScraper = new PlacesScraper();\nexport const atlasObscura: AtlasObscura = new AtlasObscura(locationScraper);\nexport type * from './interfaces/index.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAMA,cAAwB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAM,kBAAkB;CACtB,cAAc,YAAY,KAAK,MAAM,KAAK,QAAQ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AK,gBAAgB,OAAO,QAAQ,GAAG,QAAQ;;CAGxD,MAAa,UAAU,SAAkD;AACvE,SAAO,KAAK,gBAAgB,UAAU,QAAQ;;CAGhD,MAAa,WAAW,IAAY,SAAiD;AACnF,SAAO,KAAK,gBAAgB,eAAe,IAAI,QAAQ;;CAGzD,MAAa,UAAU,IAAY,SAA4C;EAC7E,MAAM,QAAQ,MAAM,KAAK,gBAAgB,eAAe,IAAI,QAAQ;EACpE,MAAM,YAAY,MAAM,KAAK,gBAAgB,UAAU,MAAM,KAAK,QAAQ;AAC1E,SAAO;GAAE,GAAG;GAAO,GAAG;GAAW;;CAGnC,MAAa,KAAK,MAAc,SAA2C;AACzE,SAAO,KAAK,gBAAgB,KAAK,MAAM,QAAQ;;;AAInD,MAAM,kBAAkB,IAAI,eAAe;AAC3C,MAAaC,eAA6B,IAAI,aAAa,gBAAgB"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["USER_AGENTS: string[]","locations: T","place: AOPlaceShort","locationService: PlacesScraper","atlasObscura: AtlasObscura"],"sources":["../src/fetchers/index.ts","../src/utils.ts","../src/vars.ts","../src/services/location.service.ts","../src/index.ts"],"sourcesContent":["const USER_AGENTS: string[] = [\n 'Dalvik/2.1.0 (Linux; U; Android 8.1.0; C6L Build/OPM2.171019.012)',\n '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',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/14E5239e Safari/602.1',\n 'Dalvik/2.1.0 (Linux; U; Android 11; SM-A505GT Build/RP1A.200720.012)',\n 'Mozilla/5.0 (Windows NT 10.3;; en-US) AppleWebKit/602.25 (KHTML, like Gecko) Chrome/54.0.2457.241 Safari/534.5 Edge/9.65405',\n 'Mozilla/5.0 (Windows; U; Windows NT 10.4; x64) AppleWebKit/536.41 (KHTML, like Gecko) Chrome/53.0.3535.112 Safari/600.5 Edge/14.39786',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_4_0; like Mac OS X) AppleWebKit/601.9 (KHTML, like Gecko) Chrome/47.0.2876.394 Mobile Safari/600.5',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_6_3; like Mac OS X) AppleWebKit/602.24 (KHTML, like Gecko) Chrome/54.0.3204.297 Mobile Safari/537.0',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_9_6; like Mac OS X) AppleWebKit/601.4 (KHTML, like Gecko) Chrome/55.0.2808.105 Mobile Safari/600.4',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_2_1; like Mac OS X) AppleWebKit/600.14 (KHTML, like Gecko) Chrome/50.0.3808.259 Mobile Safari/534.1',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_4_2; like Mac OS X) AppleWebKit/534.21 (KHTML, like Gecko) Chrome/47.0.3531.351 Mobile Safari/533.0'\n];\n\nconst DEFAULT_HEADERS = {\n 'User-Agent': USER_AGENTS[Math.floor(Math.random() * USER_AGENTS.length)],\n 'Cache-Control': 'no-cache',\n};\n\nexport const fetchPage = async (url: string, headersCustom?: Headers): Promise<string> => {\n try {\n const response = await fetch(url, {\n headers: { ...DEFAULT_HEADERS, ...headersCustom },\n credentials: 'omit'\n });\n\n if (!response.ok) {\n throw new Error(`atlas-obscura-api: Bad response ${response.status} for url: ${url}`);\n }\n\n return await response.text();\n } catch (error) {\n console.error('fetchPage error:', error);\n return 'Error';\n }\n};\n","export const parseResults = <T>(matches: RegExpMatchArray): T => {\n let locations: T = null;\n\n if (matches && matches[1]?.length) {\n try {\n locations = JSON.parse(matches[1]);\n } catch (error) {\n console.error('Error parsing all places');\n }\n }\n return locations;\n};\n","export const URL_PLACES_ALL =\n 'https://www.atlasobscura.com/articles/all-places-in-the-atlas-on-one-map';\n\nexport const urlSearch = (coord: { lat: number; lng: number }, page?: number): string =>\n `https://www.atlasobscura.com/search?utf8=%E2%9C%93&q=&location=&nearby=true&lat=${coord.lat\n }&lng=${coord.lng}${page ? '&page=' + page : ''}`;\n\nexport const urlPlaceId = (id: number): string =>\n `https://www.atlasobscura.com/places/${id}.json?place_only=1`;\n\nexport const urlUser = (name: string): string =>\n `https://www.atlasobscura.com/users/${name}`;\n","import { parse } from 'node-html-parser';\nimport { fetchPage } from '../fetchers/index.js';\nimport { AOUser } from '../interfaces/user.interface.js';\nimport { parseResults } from '../utils.js';\nimport { URL_PLACES_ALL, urlPlaceId, urlSearch, urlUser } from '../vars.js';\nimport { AOCoordinates, AOFetchOptions } from './../interfaces/global.js';\nimport { AOLocationResult } from './../interfaces/locations.interface.js';\nimport { AOPlaceExtend, AOPlaceShort } from './../interfaces/placeId.interface.js';\nimport { AOPlacesAll } from './../interfaces/places-all.interface.js';\n\nexport class PlacesScraper {\n public async placesAll(options?: AOFetchOptions): Promise<AOPlacesAll[]> {\n const response = await fetchPage(URL_PLACES_ALL, options?.headers);\n const html = parse(response).innerHTML;\n\n const data = html.match(/AtlasObscura\\.all_places = (.*?);/);\n\n return parseResults<AOPlacesAll[]>(data);\n }\n\n public async search(coords: AOCoordinates, page = 1, options?: AOFetchOptions): Promise<AOLocationResult> {\n const url = urlSearch(coords, page);\n const response = await fetchPage(url, options?.headers);\n const html = parse(response).innerHTML;\n\n const data = html.match(/AtlasObscura\\.place_search = (.*?);/);\n\n return parseResults<AOLocationResult>(data);\n }\n\n public async placeByIdShort(id: number, options?: AOFetchOptions): Promise<AOPlaceShort> {\n const url = urlPlaceId(id);\n const data = await fetchPage(url, options?.headers);\n\n let place: AOPlaceShort = null;\n\n try {\n place = JSON.parse(data);\n if (place && typeof place.hide_from_maps === 'string') {\n (place as any).hide_from_maps = place.hide_from_maps === 'true';\n }\n } catch (error) {\n console.error('Error parsing placeById', id);\n }\n return place;\n }\n\n public async placeFull(url: string, options?: AOFetchOptions): Promise<AOPlaceExtend> {\n const data = await fetchPage(url, options?.headers);\n const html = parse(data);\n\n const descriptions = html.querySelectorAll('.place-body p').map((p) => p.innerHTML);\n\n const sectionDirections = Array.from(html.querySelectorAll('section')).find((sec) => {\n const h2 = sec.querySelector('h2');\n return h2 && h2.textContent.trim() === 'Know Before You Go';\n });\n const directions = sectionDirections\n ? Array.from(sectionDirections.querySelectorAll('p')).map((p) => p.textContent.trim())\n : [];\n\n const tags = html.querySelectorAll('.aon-pill-badge-component').map((x) => {\n return {\n title: x.querySelector('.aon-pill-badge-text')?.innerHTML.trim(),\n link: x.attributes.href\n };\n });\n\n const slides = html.querySelectorAll('.swiper-slide');\n const images = Array.from(slides)\n .map((slide) => {\n const img = slide.querySelector('img');\n return img ? img.getAttribute('src') : null;\n })\n .filter(Boolean);\n\n const imageCover = images[0];\n\n return { description: descriptions, directions, tags, imageCover, images };\n }\n\n public async user(user: string, options?: AOFetchOptions): Promise<AOUser> {\n const url = urlUser(user);\n const response = await fetchPage(url, options?.headers);\n const html = parse(response).innerHTML;\n\n const data = html.match(/AtlasObscura\\.user_profile = (.*?);/);\n\n const usr = parseResults<{ user: AOUser }>(data);\n\n return usr.user;\n }\n}\n","import { AOCoordinates, AOFetchOptions } from './interfaces/global.js';\nimport { AOLocationResult } from './interfaces/locations.interface.js';\nimport { AOPlace, AOPlaceShort } from './interfaces/placeId.interface.js';\nimport { AOPlacesAll } from './interfaces/places-all.interface.js';\nimport { AOUser } from './interfaces/user.interface.js';\nimport { PlacesScraper } from './services/location.service.js';\n\nexport class AtlasObscura {\n constructor(private locationService: PlacesScraper) { }\n\n public async search(coords: AOCoordinates, options?: AOFetchOptions): Promise<AOLocationResult> {\n return this.locationService.search(coords, 1, options);\n }\n\n public async placesAll(options?: AOFetchOptions): Promise<AOPlacesAll[]> {\n return this.locationService.placesAll(options);\n }\n\n public async placeShort(id: number, options?: AOFetchOptions): Promise<AOPlaceShort> {\n return this.locationService.placeByIdShort(id, options);\n }\n\n public async placeFull(id: number, options?: AOFetchOptions): Promise<AOPlace> {\n const place = await this.locationService.placeByIdShort(id, options);\n const placeRich = await this.locationService.placeFull(place.url, options);\n return { ...place, ...placeRich };\n }\n\n public async user(user: string, options?: AOFetchOptions): Promise<AOUser> {\n return this.locationService.user(user, options);\n }\n}\n\nconst locationScraper = new PlacesScraper();\nexport const atlasObscura: AtlasObscura = new AtlasObscura(locationScraper);\nexport type * from './interfaces/index.js';\n"],"mappings":";;;AAAA,MAAMA,cAAwB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAM,kBAAkB;CACtB,cAAc,YAAY,KAAK,MAAM,KAAK,QAAQ,GAAG,YAAY,OAAO;CACxE,iBAAiB;CAClB;AAED,MAAa,YAAY,OAAO,KAAa,kBAA6C;AACxF,KAAI;EACF,MAAM,WAAW,MAAM,MAAM,KAAK;GAChC,SAAS;IAAE,GAAG;IAAiB,GAAG;IAAe;GACjD,aAAa;GACd,CAAC;AAEF,MAAI,CAAC,SAAS,GACZ,OAAM,IAAI,MAAM,mCAAmC,SAAS,OAAO,YAAY,MAAM;AAGvF,SAAO,MAAM,SAAS,MAAM;UACrB,OAAO;AACd,UAAQ,MAAM,oBAAoB,MAAM;AACxC,SAAO;;;;;;ACjCX,MAAa,gBAAmB,YAAiC;CAC/D,IAAIC,YAAe;AAEnB,KAAI,WAAW,QAAQ,IAAI,OACzB,KAAI;AACF,cAAY,KAAK,MAAM,QAAQ,GAAG;UAC3B,OAAO;AACd,UAAQ,MAAM,2BAA2B;;AAG7C,QAAO;;;;;ACVT,MAAa,iBACX;AAEF,MAAa,aAAa,OAAqC,SAC7D,mFAAmF,MAAM,IACxF,OAAO,MAAM,MAAM,OAAO,WAAW,OAAO;AAE/C,MAAa,cAAc,OACzB,uCAAuC,GAAG;AAE5C,MAAa,WAAW,SACtB,sCAAsC;;;;ACDxC,IAAa,gBAAb,MAA2B;CACzB,MAAa,UAAU,SAAkD;AAMvE,SAAO,yCALU,MAAM,UAAU,gBAAgB,SAAS,QAAQ,CACtC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MAAM,IAAI,aAAa,MAAM,GAAG;IACvC,CACD,OAAO,QAAQ;AAIlB,SAAO;GAAE,aAAa;GAAc;GAAY;GAAM,YAFnC,OAAO;GAEwC;GAAQ;;CAG5E,MAAa,KAAK,MAAc,SAA2C;AASzE,SAFY,yCALK,MAAM,UADX,QAAQ,KAAK,EACa,SAAS,QAAQ,CAC3B,CAAC,UAEX,MAAM,sCAAsC,CAEd,CAErC;;;;;;ACnFf,IAAa,eAAb,MAA0B;CACxB,YAAY,AAAQC,iBAAgC;EAAhC;;CAEpB,MAAa,OAAO,QAAuB,SAAqD;AAC9F,SAAO,KAAK,gBAAgB,OAAO,QAAQ,GAAG,QAAQ;;CAGxD,MAAa,UAAU,SAAkD;AACvE,SAAO,KAAK,gBAAgB,UAAU,QAAQ;;CAGhD,MAAa,WAAW,IAAY,SAAiD;AACnF,SAAO,KAAK,gBAAgB,eAAe,IAAI,QAAQ;;CAGzD,MAAa,UAAU,IAAY,SAA4C;EAC7E,MAAM,QAAQ,MAAM,KAAK,gBAAgB,eAAe,IAAI,QAAQ;EACpE,MAAM,YAAY,MAAM,KAAK,gBAAgB,UAAU,MAAM,KAAK,QAAQ;AAC1E,SAAO;GAAE,GAAG;GAAO,GAAG;GAAW;;CAGnC,MAAa,KAAK,MAAc,SAA2C;AACzE,SAAO,KAAK,gBAAgB,KAAK,MAAM,QAAQ;;;AAInD,MAAM,kBAAkB,IAAI,eAAe;AAC3C,MAAaC,eAA6B,IAAI,aAAa,gBAAgB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "atlas-obscura-api",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"description": "Atlas Obscura API in JavaScript. NPM library for scrapping atlasobscura.com",
|
|
5
5
|
"author": "BART! <bart@bartweb.cz>",
|
|
6
6
|
"dependencies": {
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"types": "./index.d.ts",
|
|
36
36
|
"exports": {
|
|
37
37
|
".": {
|
|
38
|
-
"
|
|
39
|
-
"
|
|
38
|
+
"require": "./index.js",
|
|
39
|
+
"import": "./index.mjs"
|
|
40
40
|
},
|
|
41
41
|
"./package.json": "./package.json"
|
|
42
42
|
}
|