Package: loopleSheet
loopleSheetThe purpose of this library is to provide a subroutine wrapper connected to a Google Sheet. It implements the main loop (calling the subroutine in a loop) and interacts with a Google Sheet.This library allows the rapid deployment of a robot and offers a tracking of it. This can be relevant for example in the context of Raspeberry Pi boards.A full documentation is availablehere.Features:sleep time between 2 executions of the subroutine is read from the Google Sheetdisplay the date and time of the last execution of the subroutine in the Google Sheetallow to post messages in the Google Sheet. These messages are automatically time-stampedIn order to use this library, you need to have a Google account and you need to accept the Terms of use of Google Cloud Platform.InstallingYou can install this library using:pipinstallloopleSheetor:python3-mpipinstallloopleSheetUseful InformationIn order to work with a Google Sheet,loopleSheetneed 2 elements:thekeyof the Google Sheet (a.k.aSpreadsheet ID)a.jsonfile withaccess credentialsGetting a Spreadsheet IDYou can get the Spredsheet ID of a Google Sheet from the url used when you edit the Google Sheet online. It is the part betweenhttps://docs.google.com/spreadsheets/d/and/edit#gid=0.For example, in the urlhttps://docs.google.com/spreadsheets/d/1LzDqgfWea1cIafGnXhIc2OEFCHzoFOSdO1qsSlK3rGk/edit#gid=0, the Spreadsheet ID is1LzDqgfWea1cIafGnXhIc2OEFCHzoFOSdO1qsSlK3rGk.Creating access credentialsThis library uses GoogleService accountcredentials. You can follow thisdocumentationfor creating aProjectand aService account. Don't forget to select Google Sheet API when you are asked which API you want to use.At the end of the process, you should have downloaded the.jsonfile.Authorizing the Service account to edit the Google SheetIf you haven't shared your Google Sheet, it can only be edited by you (the Google account that created the Google Sheet). So, in order for the Service account to edit the Google Sheet, you must share it with them.The Service account has an email address. You can find it in your Google Cloud Console or more easily in the.json(tag"client_email"). Just share the Google Sheet with this specific email address or with anyone if you're fine with it. Don't forget to allow modifications.Google Sheet templateYour Google Sheet is not processed byloopleSheet, so don't expect some clever behaviour.
I suggest your Google Sheet to be like this one :By default,loopleSheet:expects in theB1cell the number of seconds to sleep between 2 executionswill write the date and time of the last performed execution in theA4cellwill write the messages you want to post in theCcolumn with the associated date and time in theDcolumnworks on thefirstsheet of the Google SheetYou can edit this behavior.ExamplesimportosimportsysimportloopleSheetaslsdefsubroutine(loopleSht):# Doing some work...ifspecial_result:loopleSht.post('New info found ! [...]')# The .json is next to the scriptls.LoopleSheet(json_path=os.path.dirname(os.path.realpath(sys.argv[0]))+'/credentials.json',spreadsheet_id='1LzDqgfWea1cIafGnXhIc2OEFCHzoFOSdO1qsSlK3rGk',runnable=subroutine,catchingExceptionsFromRunnable=True).start()Note: You may have to kill the script in order to finish it