Example Golden Gate Webcam avatar

Example Golden Gate Webcam

Deprecated
View all Actors
This Actor is deprecated

This Actor is unavailable because the developer has decided to deprecate it. Would you like to try a similar Actor instead?

See alternative Actors
Example Golden Gate Webcam

Example Golden Gate Webcam

apify/example-golden-gate-webcam

Example actor that opens a webpage with Golden Gate webcam. It takes a screenshot from the cam and saves it as output to the key-value store. You can easily use it as API that returns a screenshot with https://api.apify.com/v2/acts/apify~example-golden-gate-webcam/run-sync?token=[YOUR_API_TOKEN]

Dockerfile

1# This is a template for a Dockerfile used to run acts in Actor system.
2# The base image name below is set during the act build, based on user settings.
3# IMPORTANT: The base image must set a correct working directory, such as /usr/src/app or /home/user
4FROM apify/actor-node-chrome:v0.21.10
5
6# Second, copy just package.json and package-lock.json since it should be
7# the only file that affects "npm install" in the next step, to speed up the build
8COPY package*.json ./
9
10# Install NPM packages, skip optional and development dependencies to
11# keep the image small. Avoid logging too much and print the dependency
12# tree for debugging
13RUN npm --quiet set progress=false \
14 && npm install --only=prod --no-optional \
15 && echo "Installed NPM packages:" \
16 && (npm list --all || true) \
17 && echo "Node.js version:" \
18 && node --version \
19 && echo "NPM version:" \
20 && npm --version
21
22# Copy source code to container
23# Do this in the last step, to have fast build if only the source code changed
24COPY --chown=myuser:myuser . ./
25
26# NOTE: The CMD is already defined by the base image.
27# Uncomment this for local node inspector debugging:
28# CMD [ "node", "--inspect=0.0.0.0:9229", "main.js" ]

package.json

1{
2    "name": "apify-project",
3    "version": "0.0.1",
4    "description": "",
5    "author": "It's not you it's me",
6    "license": "ISC",
7    "dependencies": {
8        "apify": "0.21.10"
9    },
10    "scripts": {
11        "start": "node main.js"
12    }
13}

main.js

1const Apify = require('apify');
2
3Apify.main(async () => {
4    // Launch web browser.
5    const browser = await Apify.launchPuppeteer({ headless: true });
6
7    // Load http://goldengatebridge75.org/news/webcam.html and get an IFRAME with the webcam stream
8    console.log('Opening web page...');
9    const page = await browser.newPage();
10    await page.goto('http://goldengatebridge75.org/news/webcam.html');
11    const frames = await page.frames();
12    const iframeWithVideo = frames[1];
13
14    // Wait for the webcam to load.
15    console.log('Waiting for the webcam image.');
16    const imageElementHandle = await iframeWithVideo.waitForSelector('.VideoColm img[src^="blob:"]');
17    // Wait a little more to give the browser a chance to display the image.
18    await page.waitFor(1000);
19
20    // Get a screenshot of that image.
21    const imageBuffer = await imageElementHandle.screenshot();
22    console.log('Screenshot captured.');
23
24    // Save the screenshot as the actor's output. By convention, similarly to "INPUT",
25    // the actor's output is stored in the default key-value store under the "OUTPUT" key.
26    await Apify.setValue('OUTPUT', imageBuffer, { contentType: 'image/jpeg' });
27    console.log('Actor finished.');
28});
Developer
Maintained by Community
Categories