Set up input schema

This commit is contained in:
JakubDrobnik 2018-11-20 15:29:46 +01:00
parent 347207129f
commit 29e07e02d0
4 changed files with 1255 additions and 8 deletions

33
INPUT_SCHEMA.json Normal file
View File

@ -0,0 +1,33 @@
{
"title": "Crawler for Google places",
"type": "object",
"schemaVersion": 1,
"properties": {
"searchString": {
"title": "Search",
"type": "string",
"description": "String will be search on Google maps.",
"prefill": "New York Gym",
"editor": "textfield"
},
"lat": {
"title": "Viewport Latitude",
"type": "number",
"description": "Use it with combination with longitude and zoom to set up viewport to search on."
},
"lng": {
"title": "Viewport Longitude",
"type": "number",
"description": "Use it with combination with latitude and zoom to set up viewport to search on.",
},
"zoom": {
"title": "Viewport Zoom",
"type": "number",
"description": "Use it with combination with longitude and latitude to set up viewport to search on.",
"maximum": 15
}
},
"required": [
"searchString"
]
}

View File

@ -22,7 +22,6 @@ Example input:
On this input actor searches places on this start url: https://www.google.com/maps/search/%C4%8Dsob/@50.0860729,14.4135326,10z
- `searchString` - String will be search on Google maps
- `searchViewport` - Object where user can define start view port for searching (Google will search places in this area)
- `searchViewport.lat` - Viewport latitude
- `searchViewport.lng` - Viewport longitude
- `searchViewport.zoom` - Viewport zoom, e.g zoom: 10 -> https://www.google.com/maps/@50.0860729,14.4135326,10z vs zoom: 1 -> https://www.google.com/maps/@50.0860729,14.4135326,10z
- `lat` - Viewport latitude
- `lng` - Viewport longitude
- `zoom` - Viewport zoom, e.g zoom: 10 -> https://www.google.com/maps/@50.0860729,14.4135326,10z vs zoom: 1 -> https://www.google.com/maps/@50.0860729,14.4135326,10z

1215
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -30,16 +30,16 @@ const enqueueAllUrlsFromPagination = async (page, requestQueue) => {
};
Apify.main(async () => {
const { searchString, searchViewport } = await Apify.getValue('INPUT');
const { searchString, lat, lng } = await Apify.getValue('INPUT');
if (!searchString) throw new Error('Attribute searchString missing in input.');
console.log('Scraping Google Places for search string:', searchString);
let startUrl;
if (searchViewport) {
const { lat, lng, zoom = 10 } = searchViewport;
if (!lat || !lng) throw new Error('You have to defined lat and lng for searchViewport!');
if (lat || lng) {
const { zoom = 10 } = input;
if (!lat || !lng) throw new Error('You have to defined lat and lng!');
startUrl = `https://www.google.com/maps/@${lat},${lng},${zoom}z/search`;
} else {
startUrl = 'https://www.google.com/maps/search/';