Interaction through Python

I’ve made a project where using it sends the battery details ( ‘remaining battery’, ‘time for the battery to empty’ and ‘whether is the computer is charging’ ) through python as post request to the web. On the other side, we get the values and show them in the app :iphone:


I’ve uploaded the Python script as well as the Google script to GitHub, you can fork or download it.

https://github.com/XomaDev/batteryx-interaction

In the repository, open the script.gs and upload it to the Google scripts.
Then you’ve to copy the script’s ID and change it in the main.py file. The current script ID won’t work. It’s just for testing. Scroll below to understand the script.gs

98688f0f3c27dc1f8dc1de0abe9be08330b919b0 (1)

You could also change the interval or pause between post requests. The current value is set to 700 milliseconds.


The below is the Google script’s code. Both the post and get request code is in the same script. Make sure to change the spreadsheet’s ID here.

f061e37e7550e6f4f64a64258b88091cd85fe9e3_2_1035x384 (1)


The three values will be stored in a single cell in the spreadsheet as in the form of JSON. We’ll get the values, decode the JSON and show it.

82378d370c8d97d5f72d7bf97c1b5bb05f12a3c6_2_1033x529

Blocks are the same for Appzard.

The three JSON keys here for the values are (‘remainingBattery’, ‘pluggedIn’ and ‘timeLeft’). We use dictionary blocks to parse them.


Say me if anything is wrong, I’ll correct it.

Thanks! :smiley:

6 Likes

Very helpful. Thank you for your contribution

3 Likes