How to use the gspread.models.Spreadsheet function in gspread

To help you get started, we’ve selected a few gspread examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scrapd / scrapd / tests / core / test_gsheets.py View on Github external
def test_add_csv_data_00(self, mocker):
        """Ensure the data is appended to the worksheet."""
        fake_fields = self.fake.pylist(10, True, str)
        fake_data = []
        for _ in range(self.fake.random_digit()):
            fake_entry = {}
            for field in fake_fields:
                fake_entry[field] = self.fake.word()
            fake_data.append(fake_entry)

        g = GSheets(self.fake.file_path(depth=1, category=None, extension='json'), [])
        g.spreadsheet = Spreadsheet(None, None)
        g.worksheet = mocker.MagicMock()
        g.worksheet.append_row = mocker.MagicMock()
        g.add_csv_data(fake_fields, fake_data)

        assert not g.worksheet.append_row.call_count == len(fake_data)
github scrapd / scrapd / tests / core / test_gsheets.py View on Github external
def test_share_00(self, mocker):
        """Ensure the document is shared with valid contributors."""
        contributors = ['alice@gmail.com:user:writer', 'alice@gmail.com:user:reader']
        g = GSheets(self.fake.file_path(depth=1, category=None, extension='json'), contributors)
        g.spreadsheet = Spreadsheet(None, None)
        g.spreadsheet.share = mocker.MagicMock()

        g.share()

        assert g.spreadsheet.share.call_count == len(contributors)
github scrapd / scrapd / tests / core / test_gsheets.py View on Github external
def test_share_01(self, mocker):
        """Ensure the document is not shared with invalid contributors."""
        contributors = ['alice@gmail.com']
        g = GSheets(self.fake.file_path(depth=1, category=None, extension='json'), contributors)
        g.spreadsheet = Spreadsheet(None, None)
        g.spreadsheet.share = mocker.MagicMock()

        g.share()

        assert not g.spreadsheet.share.called
github aiguofer / gspread-pandas / gspread_pandas / __init__.py View on Github external
Returns
    -------
    dict
        Response body
    """
    if params is None:
        params = {}

    params.update(ranges=ranges)

    url = SPREADSHEET_VALUES_BATCH_URL % (self.id)
    r = self.client.request("get", url, params=params)
    return r.json()


Spreadsheet.values_get_batch = values_get_batch
github burnash / gspread / gspread / client.py View on Github external
def open_by_key(self, key):
        """Opens a spreadsheet specified by `key`.

        :param key: A key of a spreadsheet as it appears in a URL in a browser.
        :type key: str

        :returns: a :class:`~gspread.models.Spreadsheet` instance.

        >>> c = gspread.authorize(credentials)
        >>> c.open_by_key('0BmgG6nO_6dprdS1MN3d3MkdPa142WFRrdnRRUWl1UFE')

        """
        return Spreadsheet(self, {'id': key})
github aiguofer / gspread-pandas / gspread_pandas / client.py View on Github external
:raises gspread.SpreadsheetNotFound: if no spreadsheet with
                                             specified `title` is found.

        >>> c = gspread.authorize(credentials)
        >>> c.open('My fancy spreadsheet')
        """
        try:
            properties = finditem(
                lambda x: x["name"] == title, self.list_spreadsheet_files(title)
            )

            # Drive uses different terminology
            properties["title"] = properties["name"]

            return Spreadsheet(self, properties)
        except StopIteration:
            raise SpreadsheetNotFound
github burnash / gspread / gspread / client.py View on Github external
def openall(self, title=None):
        """Opens all available spreadsheets.

        :param title: (optional) If specified can be used to filter
                      spreadsheets by title.
        :type title: str

        :returns: a list of :class:`~gspread.models.Spreadsheet` instances.

        """
        spreadsheet_files = self.list_spreadsheet_files()

        return [
            Spreadsheet(self, dict(title=x['name'], **x))
            for x in spreadsheet_files
        ]