JamCam multiple historic images

Is it possible to retrieve multiple JamCam images from a single location created within a period of time in the very recent past through the API? For example could I fetch all images from a single camera created in the last 3 hours as oppose to just being able to fetch the most recent image? Thanks!

Hi,

I thought it might using https://archive.org/ mapping onto the endpoint https://s3-eu-west-1.amazonaws.com/jamcams.tfl.gov.uk but it only has a single error page from 2016.

http://www.nationalarchives.gov.uk/webarchive/ doesn’t seem to have one either.

You might expect https://tfl.gov.uk/corporate/about-tfl/culture-and-heritage/corporate-archives to help, but it’s not that kind of archive.

However, given that https://s3-eu-west-1.amazonaws.com is an AWS “S3 bucket” it will have a history, you might be able to FOI it from TfL.

@BrakelightTreerings We only provide the “real time” images for jamcams I’m afraid. Interested to know what your interest is in the past 3 hours worth of images though as I can ask the team that look after the jam cams feed if that is possible.

Thank you @briantist and @theochapple for your replies! great to get a better idea of what’s going on. I’m really asking completely out of curiosity and for artistic purposes (I’m an artist working with tech in my spare time). I was going gather the images to study and plot the changes in colour over time and perhaps also sort the pixel values to make something visually interesting. I’m also very curious about the uses of the feeds. Is there any machine learning being applied to them like object detection? Are they monitored by humans or machines? Is there only purpose to manage traffic flows or is there any interesting use-cases outside of this? I appreciate you may not have answers to these odd questions…

I wrote this collector process in PHP. It uses the XML from the rootof the S3 bucket to get the file timestamps. Each time you run it, bit copies all the Jamcams that have updated since the last run.

class JamCamArchive
{
const INPUTXML = "https://s3-eu-west-1.amazonaws.com/jamcams.tfl.gov.uk";
const ARCHVEFOLDER = "styles/images/jamcams";

public function runTest()
{
    if (!is_dir(self::ARCHVEFOLDER)) {
        mkdir(self::ARCHVEFOLDER);
    }
    $objDOMdoc = new DOMDocument();
    $objDOMdoc->loadXML(file_get_contents(self::INPUTXML));
    $xpath = new DOMXPath($objDOMdoc);
    $strQuery = "//*";
    {
        $entries = $xpath->query($strQuery);
        foreach ($entries as $entry)
            if ($entry->nodeName == "Contents") {
                if ($entry->hasChildNodes()) {
                    foreach ($entry->childNodes as $node) {
                        if ($node->nodeName == "Key") {
                            $strKey = ($node->nodeValue);
                        }
                        if ($node->nodeName == "LastModified") {
                            $LastModified = ($node->nodeValue);
                        }
                    }
                }
                $strArchiveFilename = self::ARCHVEFOLDER . "/{$strKey}/{$LastModified}." . pathinfo($strKey, PATHINFO_EXTENSION);
                $strArchiveFilename = strtr($strArchiveFilename, [":" => "_"]);
                if (!is_dir(self::ARCHVEFOLDER . "/$strKey")) {
                    mkdir(self::ARCHVEFOLDER . "/$strKey");
                }
                if (!file_exists($strArchiveFilename)) {
                    $strSrc = self::INPUTXML . "/$strKey";
                    file_put_contents($strArchiveFilename, file_get_contents($strSrc));
                    echo PHP_EOL . "copy $strArchiveFilename";
                } else {
                    echo "*";
                }
            }
    }
}
}
1 Like

Thanks @briantist, nice script, will have a play around and let you know of anything make!

Great bit of code @briantist:+1::+1:

This XML file only lists 500 cameras for some reason when the JSON feed lists over 900.

Would you know how to convert the JSON feed at https://api.tfl.gov.uk/Place/Type/JamCam to use your script?

Beyond my capabilities unfortunately :roll_eyes:

I can dissect the JSON feed with javascript for my maps project but not PHP and I’d like to save the images.
https://www.tfljamcams.net

Hi,

The code for the JSON goes like this. You need to replace the values in TFLAPISUFFIX with your own credentials.

 class JamCamArchive
{
const INPUTXML = "https://s3-eu-west-1.amazonaws.com/jamcams.tfl.gov.uk";
const INPUTJSON = "https://api.tfl.gov.uk/Place/Type/JamCam";
const ARCHVEFOLDER = "styles/images/jamcams";
const TFLAPISUFFIX = "app_id=eeeeeeee&app_key=eeeeeeeeeeeeeee";

public function runTest()
{
    if (!is_dir(self::ARCHVEFOLDER)) {
        mkdir(self::ARCHVEFOLDER);
    }
    $entries = json_decode(file_get_contents(self::INPUTJSON . "?" . self::TFLAPISUFFIX));
    {
        foreach ($entries as $entry) {
            foreach ($entry->additionalProperties as $node) {
                if ($node->key == "imageUrl"
//                        or $node->key=="videoUrl"
                ) {
                    $strKey = pathinfo($node->value, PATHINFO_FILENAME) . "." . pathinfo($node->value, PATHINFO_EXTENSION);
                    $LastModified = ($node->modified);
                }
            }
            $strArchiveFilename = self::ARCHVEFOLDER . "/{$strKey}/{$LastModified}." . pathinfo($strKey, PATHINFO_EXTENSION);
            $strArchiveFilename = strtr($strArchiveFilename, [":" => "_"]);
            if (!is_dir(self::ARCHVEFOLDER . "/$strKey")) {
                mkdir(self::ARCHVEFOLDER . "/$strKey");
            }
            if (!file_exists($strArchiveFilename)) {
                $strSrc = self::INPUTXML . "/$strKey";
                var_dump($strSrc);
                file_put_contents($strArchiveFilename, file_get_contents($strSrc));
                echo PHP_EOL . "copy $strArchiveFilename";
            } else {
                echo "*";
            }
        }
    }
}
}

I’m not sure how long the JSON API endpoint at https://api.tfl.gov.uk/Place/Type/JamCam caches for though. The XML one seems to be “live”.

@briantist, you’re an absolute Gent :+1:

Pure magic, thankyou…

Cams archive project page:
http://www.brooksy.org/jamcam/

1 Like

No problem!

The images are quite facinating…!