Socket
Socket
Sign inDemoInstall

geoscreenshot-api-example

Package Overview
Dependencies
5
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

geoscreenshot-api-example

Example for consuming basic operations of the GeoScreenshot web capture API. The example makes calls to the capture web service to retrieve capture data and stores the image as a PNG file. The simple use case captures Yahoo Weather for all available plus


Version published
Maintainers
1
Weekly downloads
1

Weekly downloads

Readme

Source

GeoScreenshot API Example

This is an example for the early release GS API Alpha. It captures Yahoo Weather Pages from several locations.

Usage

This simple script calls the GS API and generates PNG files.

For a given URL, it will simultaneously request screenshots for 1 or more locations and outputs PNGs and JSON Metadata in the specified directory.

The documentation for the web service can be found here: https://www.geoscreenshot.com/docs/

Examples

Capture from all locations of a country
"use strict";

const config = {
    'url': 'http://news.google.com',
    'imageDir': './out/',
    'verbose': true
};

const gs = require('./geoscreenshot')(config);

gs.locations()
    .then(gs.filter('IN')) // Filter by country code
    .then(gs.multicapture)
    .then((results) => {
        console.log("Captured ", results.length, "locations");
    }, (error) => {
        // Handle error
    });
    

Capture a single location

In your .js file:

// Set default URL, defaults to Yahoo Weather and current dir respectively
const config = {
'url': 'http://www.example.com',
'imageDir': './out/'
};
const gs = require('./geoscreenshot')(config);
gs.gsCapture('http://www.example.com').then((result) => {
    console.log("Retrieved base 64 image of length: ", result.image.length);
}, (error) => {
    // Handle error
});
Capture from all available locations

In your .js file:

"use strict";

const config = {
    'url': 'http://weather.yahoo.com',
    'imageDir': './out/',
    'verbose': true
};

const gs = require('./geoscreenshot')(config);

gs.locations().then(gs.multicapture)
    .then((results) => {
        console.log("Captured ", results.length, "locations");
    }, (error) => {
        // Handle error
    });

CLI Usage

Capture single screenshot
node geoscreenshot

or

node geoscreenshot single <url>
Capture 5 random locations
node geoscreenshot random <url>
Capture all locations
node geoscreenshot multi <url>

Output

The script will generate 2 files per capture

<id>.json, example:

{
  "date": 1474044949580,
  "id": "ws_0a986wrvn29_1474044949443",
  "location": {
    "name": "lv-rix-riga",
    "city": "Riga",
    "state": "RIX",
    "country_code": "LV",
    "country": "Latvia",
    "lat": 56.95,
    "lon": 24.1,
    "plan": "plus",
    "timezone": "Europe/Riga"
  },
  "request": {
    "url": "http://www.example.com",
    "viewport": "1336x1400",
    "delay": "5",
    "location": "lv-rix-riga",
    "useragent": "chrome",
    "fullpage": 0,
    "no_images": 0,
    "no_cache": 0
  },
  "size": 46284
}

and <id>.png

Getting Started

Sign up for an account

Note: As of 9/15/2016, GeoScreenshot API is still in beta, API access is disabled by default. To request access, send an email to contact@geoscreenshot.com with your use case and we will upgrade your account to have this feature

  1. Sign up for an account at https://www.geoscreenshot.com/register
  2. Set a unique password, it will serve as an API key until OAuth is implemented
  3. Upgrade to Plus

Installation

Requirements
  • Node.js > v4.5
Install scripts
git clone https://github.com/geoscreenshot/geoscreenshot-api-example.git
npm install 
Configure your environment

Use a strong alphanumeric password generator for added security DO NOT store credentials in source code DO NOT re-use credentials you use for other accounts

export GS_API_BASE="" // Optional, custom for advanced users
export GS_USERNAME="<YOURUSERNAME>" // Username used on WebUI
export GS_PASSWORD="<ALPHANUMERICPASSWORD>" // Password used on WebUI

Check if it works

node geoscreenshot.js

API Reference

The RESTful API is documented here: https://www.geoscreenshot.com/docs/

Tips

  • The public API is rate limited and your IP maybe temporarily blocked if you exceed 30 reqs / minute

Contributors

If you have a problem with this sample, please file an issue here. If you would like to contribute code you can do so through GitHub by forking the repository and sending a pull request.

Any issues related to API / Web Service, please send an email to contact@geoscreenshot.com. We are still in beta and appreciate all feedback.

License

Copyright 2016 TE Web Solutions

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Keywords

FAQs

Last updated on 19 Sep 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc