subroutine wrapper connected to a Google Sheet
Project description
loopleSheet
The 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.
Features:
- sleep time between 2 executions of the subroutine is read from the Google Sheet
- display the date and time of the last execution of the subroutine in the Google Sheet
- allow to post messages in the Google Sheet. These messages are automatically time-stamped
In 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.
Installing
You can install this library using:
pip install loopleSheet
or:
python3 -m pip install loopleSheet
Useful Information
In order to work with a Google Sheet, loopleSheet
need 2 elements:
- the
key
of the Google Sheet (a.k.a Spreadsheet ID) - a
.json
file with access credentials
Getting a Spreadsheet ID
You can get the Spredsheet ID of a Google Sheet from the url used when you edit the Google Sheet online. It is the part between https://docs.google.com/spreadsheets/d/
and /edit#gid=0
.
For example, in the url https://docs.google.com/spreadsheets/d/1LzDqgfWea1cIafGnXhIc2OEFCHzoFOSdO1qsSlK3rGk/edit#gid=0
, the Spreadsheet ID is 1LzDqgfWea1cIafGnXhIc2OEFCHzoFOSdO1qsSlK3rGk.
Creating access credentials
This library uses Google Service account
credentials. You can follow this documentation for creating a Project and a Service 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 .json
file.
Authorizing the Service account to edit the Google Sheet
If 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 template
Your Google Sheet is not processed by loopleSheet
, so don't expect some clever behaviour.
I suggest your Google Sheet to be like this one :
By default, loopleSheet
:
- expects in the
B1
cell the number of seconds to sleep between 2 executions - will write the date and time of the last performed execution in the
A4
cell - will write the messages you want to post in the
C
column with the associated date and time in theD
column - works on the
first
sheet of the Google Sheet
You can edit this behavior.
Examples
import os
import sys
import loopleSheet
def subroutine(loopleSht):
# Doing some work...
if special_result:
loopleSht.post('New info found ! [...]')
# The .json is next to the script
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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file loopleSheet-1.0.0.tar.gz
.
File metadata
- Download URL: loopleSheet-1.0.0.tar.gz
- Upload date:
- Size: 17.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bed3ff0af1ed0e1732586e6b9d3aa29ec8fd2a366cbc703bae0674b6b46af47b |
|
MD5 | a006205679737dced3f4e842001b02e6 |
|
BLAKE2b-256 | 5b0ced865a8a02c114ed7255bfe7d1afb3518d082d52e601e258722e069c3d42 |
File details
Details for the file loopleSheet-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: loopleSheet-1.0.0-py3-none-any.whl
- Upload date:
- Size: 17.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 987a9c2e01e54ed4677e03dab4d9dd056046be0cb612e2689d93c567e98b5fe1 |
|
MD5 | f3b525a82af09364df8b9b4a0eb5c882 |
|
BLAKE2b-256 | b13b46f519568251107fde36f1e59df3ff833fc8288fd7f1d9a6f416ee4aa542 |