Scraping and storing actor profiles.

This commit is contained in:
2020-05-15 04:40:59 +02:00
parent 11eb66f834
commit 21d4dd6bfa
9 changed files with 311 additions and 25 deletions

View File

@@ -1,25 +1,34 @@
'use strict';
const bhttp = require('bhttp');
const logger = require('../logger')(__filename);
const http = require('./http');
async function resolvePlace(query) {
if (!query) {
return null;
}
const res = await bhttp.get(`https://nominatim.openstreetmap.org/search/${encodeURI(query)}?format=json&accept-language=en&addressdetails=1`);
const [item] = res.body;
try {
// https://operations.osmfoundation.org/policies/nominatim/
const res = await http.get(`https://nominatim.openstreetmap.org/search/${encodeURI(query)}?format=json&accept-language=en&addressdetails=1`, {
'User-Agent': 'contact at moonloop.adult@protonmail.com',
});
if (item && item.address) {
const rawPlace = item.address;
const place = {};
const [item] = res.body;
if (rawPlace.city) place.city = rawPlace.city;
if (rawPlace.state) place.state = rawPlace.state;
if (rawPlace.country_code) place.country = rawPlace.country_code.toUpperCase();
if (rawPlace.continent) place.continent = rawPlace.continent;
if (item && item.address) {
const rawPlace = item.address;
const place = {};
return place;
if (rawPlace.city) place.city = rawPlace.city;
if (rawPlace.state) place.state = rawPlace.state;
if (rawPlace.country_code) place.country = rawPlace.country_code.toUpperCase();
if (rawPlace.continent) place.continent = rawPlace.continent;
return place;
}
} catch (error) {
logger.error(`Failed to resolve place '${query}': ${error.message}`);
}
return null;