Пример #1
0
    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
Пример #2
0
def InitBlink():
    global blinkStatus, statusMessage
    if not os.path.exists(blinkCredentials):
        blinkStatus = -1
        statusMessage ='Blink credential file '+blinkCredentials+' does not exist.'
    else:
        auth = Auth(json_load(blinkCredentials))
        blink.auth = auth
        blink.start()
        blinkStatus = 1
        statusMessage = 'Blink started ok'
    print ('Initblink finished: '+statusMessage)
Пример #3
0
    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
Пример #4
0
def blink_video_schedule(event, context):
    """Triggered from a message on a Cloud Pub/Sub topic.
    Args:
         event (dict): Event payload.
         context (google.cloud.functions.Context): Metadata for the event."""

    FILENAME = 'blink_creds.json'

    #FILENAME = re.sub(r"\/.*\/(.*\.\w{1,4}",r'\1',FILE)
    #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)

    pubsub_message = base64.b64decode(event['data']).decode('utf-8')
    if pubsub_message == 'RUN':
        blink = Blink()
        blink.auth = AUTH
        blink.start()
        AUTH.send_auth_key(blink, '167363')
        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')
                print(name)  # Name of the camera
                print(
                    camera.attributes)  # Print available attributes of camera
        except ValueError:
            print('there is some error')

        blink.download_videos(since='2018/07/04 09:34')
        return "SUCCESS"
Пример #5
0
def start_blink_session(
    blink_config_file: str, blink_username, blink_password
) -> (bool, object, object):
    """Starts a blink cam session

    :param blink_config_file: blink session config file path
    :type blink_config_file: string
    :param blink_username: blink username
    :type blink_username: string
    :param blink_password: blink password
    :type blink_password: string
    :return: authentication_success for existing session or 2FA token required, blink instance, auth instance
    :rtype authentication_success: boolean
    :rtype blink: class
    :rtype auth: class
    """
    blink = Blink(refresh_rate=3)

    if os.path.exists(blink_config_file):
        logger.info("using existing blink_config.json")
        auth = Auth(json_load(blink_config_file), no_prompt=True)
        authentication_success = True
    else:
        logger.info(
            "no blink_config.json found - 2FA " + "authentication token required"
        )
        auth = Auth(
            {"username": blink_username, "password": blink_password}, no_prompt=True
        )
        authentication_success = None

    blink.auth = auth
    opts = {"retries": 10, "backoff": 2}
    blink.auth.session = blink.auth.create_session(opts=opts)
    try:
        logger.info("start blink session")
        blink.start()
    except Exception as err:
        logger.info("blink session exception occured: {0}".format(err))
        pass

    return authentication_success, blink, auth
Пример #6
0
    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)
Пример #7
0
 def test_json_load_bad_data(self):
     """Check that bad file is handled."""
     self.assertEqual(json_load("fake.file"), None)
     with mock.patch("builtins.open", mock.mock_open(read_data="")):
         self.assertEqual(json_load("fake.file"), None)
Пример #8
0
"""Login testing script."""
import sys
import os
from blinkpy.blinkpy import Blink
from blinkpy.auth import Auth
from blinkpy.helpers.util import json_load, json_save

save_session = False
print("")
print("Blink Login Debug Script ...")
print(" ... Loading previous session information.")
cwd = os.getcwd()
print(f" ... Looking in {cwd}.")
session_path = os.path.join(cwd, ".session_debug")
session = json_load(session_path)

try:
    auth_file = session["file"]
except (TypeError, KeyError):
    print(" ... Please input location of auth file")
    auth_file = input("     Must contain username and password: "******" ... Please fix file contents of {auth_file}.")
    print(" ... Exiting.")
    sys.exit(1)

try:
    username = data["username"]
Пример #9
0
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')
        print(name)                   # Name of the camera
        print(camera.attributes)      # Print available attributes of camera
Пример #10
0
def start():
    """Startup blink app."""
    blink = Blink()
    blink.auth = Auth(json_load(CREDFILE))
    blink.start()
    return blink