Camera API Demo Code

Simple Python Demo, Requesting data for a high resolution RGB photo and receiving URLs to the high res JPG images.


#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# This script will pull photos from ZEITDICE API (very simple)
# Written by Michael Schwanzer michael@zeitdice.com 2022 11 17

# You might need to install the requests library https://pypi.org/project/requests/ with 'pip install requests'
import requests
import json
from datetime import datetime

# TODO Change the VARIABLES and dates / times as you need, find your camera source ID and key in our camera SETTINGS Page, tab API
CAMERA_SOURCE_ID = '31a07e2420e424340b6dfbe16fdb6609'
CAMERA_SOURCE_KEY = '3dcbbf314c75d08e6ba8'

# TODO Adjust range as needed
DATE_RANGE_START ='1900-01-01'
DATE_RANGE_END ='2024-04-04'
TIME_RANGE_START ='07:00'
TIME_RANGE_END ='22:00'
TIME_RANGE_PER_DAY = 'false' # default 'true' and the API will respond with images only from 07:00-22:00 of each day for example 

API_endpoint = f'https://www.zeitdice.com/api/v2/sources/{CAMERA_SOURCE_ID}/stills?key={CAMERA_SOURCE_KEY}&time_range_per_day={TIME_RANGE_PER_DAY}&date_range_start={DATE_RANGE_START}&date_range_end={DATE_RANGE_END}&time_range_start={TIME_RANGE_START}&time_range_end={TIME_RANGE_END}'

if __name__ == "__main__":
  try: 
    response_API = requests.get(API_endpoint)
    if response_API.status_code == 200:
      #print(response_API.status_code)
      data = response_API.text
      photo_list = json.loads(data)
      #print(photo_list)
      for photo in photo_list:
        print(photo)
        image_url = photo["image_url"]
        local_file_location = photo["file_name"]
        print(image_url)

        # TODO Enable for download
        #photo_file = requests.get(image_url)
        #open(local_file_location, 'wb').write(photo_file.content)

        # TODO Open file if you need to process it 
        #with open(local_file_location, 'rb') as image_file:
        #  current_image = Image(image_file)

    else:
      print("Something wrong with API / API Call")
  except Exception as e:
    print("ERROR: %s" % str(e))