!pip install -q blinkpy
Blink Camera
I have been tinkering with our new Blink camera to see if I can access it from Python; possibliy to use it for some Image-classification testing. Meet Blinkpy.
import asyncio
import os.path
from aiohttp import ClientSession
from blinkpy.blinkpy import Blink
from blinkpy.auth import Auth
from blinkpy.helpers.util import json_load
async def inital_connect():
= Blink(session=ClientSession())
blink await blink.start()
return blink
async def connect(credentials):
= Blink()
blink = Auth(await json_load(credentials))
auth = auth
blink.auth await blink.start()
return blink
First time you use it, it will ask for credentials and an MFA code. When you have done this once and saved the credentials, you will not have to reenter them.
= "./blink.credentials.txt"
CREDENTIALS_FILE if not os.path.isfile("./blink.credentials.txt"):
= await inital_connect()
blink await blink.save(CREDENTIALS_PATH)
else:
= await connect(CREDENTIALS_FILE) blink
Now you can access your cameras. Lets list them first:
for name, camera in blink.cameras.items():
print(name) # Name of the camera
print(camera.attributes) # Print available attributes of camera
Let’s take a picture from one of the cameras and write it to a file.
= blink.cameras['Froschi']
camera await camera.snap_picture()
await blink.refresh()
await camera.image_to_file("img.jpg")
Let’s print the image.
from PIL import Image
= Image.open("img.jpg")
pil_im pil_im