def recording_download(self, recording_id, filename=None, override=False):
        """Save a recording in MP4 format to a file or return raw."""
        if not self.has_subscription:
            msg = "Your Ring account does not have an active subscription."
            _LOGGER.warning(msg)
            return False

        url = API_URI + URL_RECORDING.format(recording_id)
        try:
            req = self._ring.query(url, raw=True)
            if req and req.status_code == 200:

                if filename:
                    if File.Exists(filename) and not override:
                        _LOGGER.error("%s", FILE_EXISTS.format(filename))
                        return False

                    with File(filename, 'wb') as recording:
                        recording.write(req.content)
                        return True
                else:
                    return req.content
        except IOError as error:
            _LOGGER.error("%s", error)
            raise
        return False
def _clean_cache(filename):
    """Remove filename if pickle version mismatch."""
    if File.Exists(filename):
        File.DeleteFile(filename)

    # initialize cache since file was removed
    initial_cache_data = CACHE_ATTRS
    _save_cache(initial_cache_data, filename)
    return initial_cache_data
Пример #3
0
    def read_file(self, file_name):

        try:
            if File.Exists(file_name):
                with File(file_name, 'r') as csv_file:
                    csv_reader = csv.DictReader(csv_file)
                    rows = list(csv_reader)
                if rows != []:
                    print('len of rows: {0}'.format(len(rows)))
                    self.build_contacts(rows)
            else:
                ProgramLog('File not found: {0}'.format(file_name))
        except Exception as e:
            ProgramLog('Error occured opening file: {0}\n{1}'.format(file_name, e))
def _read_cache(filename):
    """Read data from a pickle file."""
    try:
        if File.Exists(filename):
            data = json.loads(File(filename, 'r').read())

            # make sure pickle obj has the expected defined keys
            # if not reinitialize cache
            if data.keys() != CACHE_ATTRS.keys():
                raise EOFError
            return data

    except (EOFError, ValueError):
        pass
    return _clean_cache(filename)
Пример #5
0
 def write_file(self, file_name):
     
     data_to_write = 'first_name,last_name,phone_number\n'
     with File(file_name, 'w') as csv_file:
         for i in range(0, self._num_of_contacts):
             data_to_write += '{0},{1},{2}\n'.format(
                 self._first_names[i], 
                 self._last_names[i], 
                 self._phone_nums[i])
         csv_file.write(data_to_write)
Пример #6
0
    def Upload(self, src):
        '''
        https://developers.google.com/drive/api/v3/manage-uploads
        :param src: str
        :param dst:
        :return: dict like {
             "kind": "drive#file",
             "id": "this_is_a_fake_id",
             "name": "Untitled",
             "mimeType": "image/jpeg"
            }
        '''
        print('GoogleDrive.Upload(', src)
        name = Path(src).name
        print('name=', name)
        resp = self._Post(
            url=
            'https://www.googleapis.com/upload/drive/v3/files?uploadType=media',
            data=File(src, 'rb'),
            headers={
                'Content-Type': mimetypes.guess_type(src)[0],
            },
        )
        print('resp.text=', resp.text)
        ID = resp.json()['id']

        # the file has been uploaded, now update the file name in the metadata
        respPatchName = self._Patch(
            url='https://www.googleapis.com/drive/v3/files/{}'.format(ID),
            json={
                'name': name,
            },
        )
        print('respPatchName.json()=', respPatchName.json())

        return respPatchName.json()
Пример #7
0
from ring_doorbell_tools import Ring
import json
from extronlib.system import File
from extronlib import event

#with File('creds.json', mode='wt') as file:
#file.write(json.dumps({'username': '******', 'password': '******'}))

try:
    with File('creds.json', mode='rt') as file:
        d = json.loads(file.read())
        username = d.get('username', None)
        password = d.get('password', None)
    print('username='******'password='******'*' * len(password))
except Exception as e:
    print('No Username/password found:', e)
    username = None
    password = None

ring = Ring(username, password)


@event(ring, ['Connected', 'Disconnected'])
def ConnectionEvent(interface, state):
    print('ConnectionEvent(interface={}, state={})'.format(interface, state))


@event(ring, 'Motion')
def MotionEvent(deviceName, evt):
    print('MotionEvent(deviceName={}, evt={})'.format(deviceName, evt))
def _save_cache(data, filename):
    """Dump data into a pickle file."""
    with File(filename, 'w') as file:
        file.write(json.dumps(data, indent=2, sort_keys=True))
    return True
def _exists_cache(filename):
    """Check if filename exists and if is pickle object."""
    return File.Exists(filename)