API reference

This documentation is auto-generated from the source code.
members:

I Sheet You Not

Search Excel data in Alfred 3

This package implements an Alfred workflow that generates other Alfred workflows that pull data from Excel files.

The core program can both search for and in Excel files, and works by making a copy of itself with different settings (and stripped of the workflow-generating elements in Alfred’s UI).

I Sheet You Not. Search Excel data in Alfred 3.

Pass this script the path to an Excel file via the -p option or the DOC_PATH environment variable.

By default, the script reads the rows of the first worksheet in the workbook and generates Alfred JSON results.

It reads the first three columns, treating the first as the result title, the second as its subtitle and the third as its value (arg).

exception isheetyounot.core.ConfigError[source]

Raised if a configuration value is not given or invalid.

Typically, this will be a bad sheet number or name.

If the program can’t read the Excel data for other reasons, there’ll be an exception from the underlying xlrd library.

class isheetyounot.core.Formatter(datemode, formats=None)[source]

Format Excel values according to column-specific format strings.

Format strings should be sprintf- or strftime-style (for date columns) patterns.

datemode

int – Date mode of sheet this formatter is for

formats

dict – Column -> format string mapping

format(col, cell)[source]

Format a value with the pattern set for column.

If no format pattern is set for column, value is returned unchanged.

Parameters:
  • col (int) – Column number
  • cell (xlrd.sheet.Cell) – Excel cell
Returns:

Formatted value

Return type:

str

get(col)[source]

Get format pattern (or None) for a specific column.

Parameters:col (int) – Column index (1-indexed)
Returns:Format pattern or None
Return type:str
set(col, pat)[source]

Set format pattern for column.

Parameters:
  • col (int) – Column index (1-indexed)
  • pat (str) – Format pattern
isheetyounot.core.cache_data(key, data)[source]

Store data in cache under name key.

Parameters:
  • key (str) – Cache key from cache_key().
  • data (str) – Data to write to file.
isheetyounot.core.cache_key(o)[source]

Generate unique, deterministic key based on program options.

Parameters:o (argparse.Namespace) – Program’s configuration object.
Returns:MD5 hex digest of options.
Return type:str
isheetyounot.core.cached_data(key, max_age=0)[source]

Returned data cached for key or None.

Returns None if no data are cached for key or the age of the cached data exceeds max_age (if max_age is non-zero).

Parameters:
  • key (str) – Cache key from cache_key().
  • max_age (int, optional) – Maximum permissible age of cached data in seconds.
Returns:

The contents of the cache file, or None.

Return type:

str

isheetyounot.core.cell_type(cell)[source]

Return type of cell.

Parameters:cell (xlrd.sheet.Cell) – Excel cell
Returns:Type of cell as text
Return type:str
isheetyounot.core.read_data(path, sheet, cols, start_row=1, variables=None, formats=None, match=None)[source]

Read the specified cells from an Excel file.

Parameters:
  • path (unicode) – Path of XLSX file to read data from.
  • sheet (unicode) – Number or name of sheet to read data from.
  • cols (list) – The three columns to read title, subtitle and value from respectively.
  • start_row (int, optional) – The row on which to start reading data.
  • variables (dict, optional) – name->col mapping of columns to read into result variables with the corresponding names.
  • formats (dict, optional) – index->format mapping of sprintf-style format strings for columns.
  • match (str, optional) – sprintf-style format string for match field.
Returns:

Sequence of Alfred 3 result dictionaries.

Return type:

list

Raises:

ConfigError – Raised if an argument is invalid, e.g. non-existent sheet name.

isheetyounot.core.tilde(path)[source]

Replace user’s home directory in path with ~.

Parameters:path (unicode) – A filepath.
Returns:Shortened filepath.
Return type:unicode

cli

Command-line interface for the Alfred workflow.

Will probably die in flames if not run from Alfred or an Alfred-like environment.

isheetyounot.cli.main()[source]

Run workflow script.

isheetyounot.cli.parse_args()[source]

Read program options from the environment and command line.

Returns:Program configuration.
Return type:argparse.Namespace

Lightweight Alfred 3+ workflow library.

class isheetyounot.aw3.AttrDict(*args, **kwargs)[source]

Dictionary whose keys are also accessible as attributes.

class isheetyounot.aw3.Feedback(items=None)[source]

Alfred 3 JSON results.

items

list – Sequence of dicts as generated by make_item().

send()[source]

Send self as results to Alfred 3.

isheetyounot.aw3.alfred_vars()[source]

Dict of Alfred’s environment variables w/out alfred_ prefix.

isheetyounot.aw3.change_bundle_id(newid)[source]

Change the bundle ID of the current workflow.

WARNING: The change will not apply for the current run of the workflow.

Parameters:newid (unicode) – New bundle ID.
isheetyounot.aw3.human_time(seconds)[source]

Human-readable duration, e.g. 5m2s or 1h2m.

Parameters:seconds (float) – Number of seconds.
Returns:Human-readable duration.
Return type:unicode
isheetyounot.aw3.log(s, *args)[source]

Print message s to STDERR. Run s % args with any args.

Parameters:
  • s (unicode) – Message to print/format string.
  • *args (object) – If given, used in format string s % args.
isheetyounot.aw3.make_item(title, subtitle=u'', arg=None, icon=None, match=None, **wfvars)[source]

Create new Alfred 3 result.

Parameters:
  • title (unicode) – Title of the result.
  • subtitle (unicode, optional) – Subtitle of the result.
  • arg (unicode, optional) – Arg (value) of the result.
  • icon (unicode, optional) – Path to icon for result.
  • match (str, optional) – Match field.
  • **wfvars (dict) – Unicode values to set as Alfred workflow variables with this result.
Returns:

Alfred result.

Return type:

dict

isheetyounot.aw3.random_bundle_id(prefix=None)[source]

Generate random bundle ID based on UUID4.

Parameters:prefix (unicode, optional) – Prefix for the new bundle ID.
Returns:Random bundle ID of form prefix + UUID4.
Return type:unicode
isheetyounot.aw3.rescue(fn, help_url=None)[source]

Wrap callable fn, and catch and log any exceptions it raises.

Any captured exception is logged to STDERR and also sent to Alfred as a result.

Parameters:
  • fn (callable) – Function/method to call in try ... except block.
  • help_url (unicode, optional) – URL to show when an exception is caught.
isheetyounot.aw3.run_command(cmd)[source]

Run command and return output.

Parameters:cmd (sequence) – Sequence or arguments to pass to Popen
Returns:(stdout, stderr)
Return type:tuple
Raises:CalledProcessError – Raised if command exits with non-zero status