loopleSheet package#

Submodules#

loopleSheet.loopleSheet module#

exception loopleSheet.loopleSheet.GoogleSheetAPIError(message)#

Bases: Exception

Wrap all exceptions raised by gspread

class loopleSheet.loopleSheet.LoopleSheet(json_path, spreadsheet_id, runnable, catchingExceptionsFromRunnable=False, verbose=False, errorStream='stderr', datetimeFormat='%d/%m %H:%M:%S')#

Bases: object

Initialise a LoopleSheet and try to connect to the Google Sheet.

Parameters:
json_pathstr

The path to the Service account credentials .json file

spreadsheet_idstr

The spreadsheet id of the Google Sheet

runnablefunc(LoopleSheet)

The subroutine executed in a loop. Note the signature of runnable !

catchingExceptionsFromRunnablebool, optional, default False

If True, the exceptions raised by runnable will be caught in the start function and won’t stop the loop. If False, start will finish and transmit the exception

verbosebool, optional, default False

If True, start will print some informations

errorStreamstr, optional, default ‘stderr’

The stream to write errors to. Accepted values are : ‘google sheet’, ‘stderr’, ‘both’ or None

datetimeFormatstr, optional, default ‘%d/%m %H:%M:%S’

The format used for the date and time. See datetime.strftime() for more details

Methods

post(msg[, processColumns])

Post a message in the Google Sheet with the date and time associated.

setGoogleSheetStructure(**kwargs)

Edit the default behaviour of LoopleSheet regarding the Google Sheet structure.

start()

Launch the main loop.

post(msg, processColumns=False)#

Post a message in the Google Sheet with the date and time associated. The columns used are messageColumn for the message and msgDateColumn for the date and time. The messages and date and time are appended at the bottom of the columns (the maximum of the two so that message and date and time are in the same row).

Parameters:
msgstr

The message to post

processColumnsbool, optional, default False

If False, LoopleSheet assumes that msgColumn and msgDateColumn are not modified by a third party and doesn’t process these columns. If True, LoopleSheet fetches msgColumn and msgDateColumn, thus increasing memory and gspread api usage with the number of posts.

setGoogleSheetStructure(**kwargs)#

Edit the default behaviour of LoopleSheet regarding the Google Sheet structure.

Parameters:
sleepTimeCellstr, optional, default ‘B1’

The cell in which the number of seconds to sleep between 2 executions is written

lastExecDateTimeCellstr, optional, default ‘A4’

The cell in which the date and time of the last performed execution are written

messageColumnstr, optional, default ‘C’

The column in which the messages posted are written

msgDateColumnstr, optional, default ‘D’

The column in which the date and time of the messages posted are written

worksheetint, optional, default 0

The worksheet LoopleSheet works on (starts at 0)

start()#

Launch the main loop. In an infinite loop :

  • the date and time are written in the right cell (lastExecDateTimeCell) of the Google Sheet

  • runnable is called with as parameter the current instance of LoopleSheet (in order to be able to post some messages)

  • the script sleeps for the number of seconds written in the sleepTimeCell of the Google Sheet

The exceptions raised by runnable are caught or not according to catchingExceptionsFromRunnable. The exceptions from the Google Sheet API are caught and won’t break the loop.

Module contents#