Ejemplo n.º 1
0
def _send_blink_2fa_pin(auth, pin):
    """Send 2FA pin to blink servers."""
    blink = Blink()
    blink.auth = auth
    blink.setup_login_ids()
    blink.setup_urls()
    return auth.send_auth_key(blink, pin)
Ejemplo n.º 2
0
def _blink_startup_wrapper(hass, entry):
    """Startup wrapper for blink."""
    blink = Blink()
    auth_data = deepcopy(dict(entry.data))
    blink.auth = Auth(auth_data, no_prompt=True)
    blink.refresh_rate = entry.options.get(CONF_SCAN_INTERVAL,
                                           DEFAULT_SCAN_INTERVAL)

    if blink.start():
        blink.setup_post_verify()
    elif blink.auth.check_key_required():
        _LOGGER.debug("Attempting a reauth flow")
        _reauth_flow_wrapper(hass, auth_data)

    return blink
Ejemplo n.º 3
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"
Ejemplo n.º 4
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
Ejemplo n.º 5
0
from html.parser import HTMLParser
from urllib.request import urlopen
import json, time
from blinkpy.blinkpy import Blink
from blinkpy.auth import Auth

blink = Blink()
# https://pypi.org/project/blinkpy/
auth = Auth(
    {
        "username": "******",
        "password": "******"
    },
    no_prompt=False)
trusted_mac_addresses = ["aa:bb:cc:dd:ee:ff"]
blink.auth = auth
blink.start()

# all this shit below here is to parse my router's device list properly. i love proper object notation, and tried to do this without regex. ;p
in_table = False
this_device = []
row_name = ""
last_tag = ""
device_list = {}


class MyHTMLParser(HTMLParser):
    def handle_starttag(self, tag, attrs):
        global in_table, this_device, row_name, last_tag, device_list
        if tag == "table":
            in_table = True
Ejemplo n.º 6
0
	year = datetime.datetime.now().strftime("%Y")
	month = datetime.datetime.now().strftime("%m")
	file_path = f'/uploads/{year}/{month}'
	return file_path

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)

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'
Ejemplo n.º 7
0
def start():
    """Startup blink app."""
    blink = Blink()
    blink.auth = Auth(json_load(CREDFILE))
    blink.start()
    return blink