예제 #1
0
class CustBlink:
    def __init__(self, blink_location, blink_period):
        self.blink_location = blink_location
        self.blink_period = blink_period
        if not blink_location.is_dir():
            blink_location.mkdir()

    def login_only(self):
        self.blink = Blink()
        creds = self.blink_location / "creds.json"
        started = self.blink.start()
        if started:
            self.blink.save(creds)
        return started

    def reauth(self):
        self.blink = Blink()

        creds = self.blink_location / "creds.json"
        started = False

        print("Logging in to Blink...")
        if creds.is_file():
            auth = Auth(json_load(creds))
            auth.no_prompt = True
            self.blink.auth = auth
            started = self.blink.start()

        return started
예제 #2
0
class BlinkSession:

    def __init__(
            self
    ):
        self.auth_file = AUTH_FILE
        self.blink = Blink()

    def _auth_file_exists(self):
        return os.path.exists(self.auth_file)

    def _refresh_auth(self, reset=False):
        self.blink = Blink()
        with_sleep = False

        if not reset and self._auth_file_exists():
            self.blink.auth = Auth(json_load(self.auth_file))
            with_sleep = True
        else:
            self.blink.auth = Auth()

        self.blink.start()

        # write auth file
        self.blink.save(self.auth_file)
        print('Auth file updated: ' + self.auth_file)

        if with_sleep:
            time.sleep(3)

        return self.get(force_reset=False)

    def get(self, force_reset=False):
        if force_reset or not self._auth_file_exists():
            self.blink = self._refresh_auth(reset=True)
        else:
            self.blink.auth = Auth(login_data=json_load(self.auth_file), no_prompt=True)
            self.blink.start()

            if not self.blink.available:
                return self._refresh_auth(reset=False)

        return self.blink
예제 #3
0
#BLOB_UPLOAD = BLINK_BUCKET.blob(f"{create_file_path()[1:]}/{FILENAME}") #Set filename format (uploads/year/month/filename).
#BLOB_UPLOAD.upload_from_filename(FILE)

USER_NAME, PASSWORD = load_credentials()

AUTH = Auth({"username": USER_NAME, "password": PASSWORD}, no_prompt=True)

blink = Blink()
blink.auth = AUTH
blink.start()
AUTH.send_auth_key(blink, '399587')
blink.setup_post_verify()



print(type(blink.save(f'{FILENAME}')))

CREDS = json_load("blink_creds.json")

blob_blink = BLINK_BUCKET.blob('blink_creds.json')

blob_blink.upload_from_string(
   data=json.dumps(CREDS),
   content_type='application/json'
 )

print('i am before the cameras')
print(blink.cameras.items())
try:
    for name, camera in blink.cameras.items():
        print('i am inside the camera')