Alvarian / google-apps-script-API

Small API to format google sheet data from google apps script | Project type: Service | Presentable: :heavy_check_mark:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


Introduction

This project is an API catered to google sheet via google apps script. It handles common and repetitive formatting tasks thats usually in demand for demographic type data.

Getting Started

Install python 3+ and pip into your device. After pip is installed in your computer, we need flask to continue, so in your terminal run:

pip install flask
python manage.py

Expose app

In order for google apps script to request to the running application, the local endpoint needs to be forwarded and exposed to the web using ngrok. Follow the intructions until usage and run:

ngrok http 5000

Copy the "Forwarding" url, ex: https://7d0b-173-52-201-90.ngrok.io, to use in the next step.

Usage

Log in to your google account and navigate to google sheets and in a new sheet fill one column with random first names with a column title of "Full Name".

Go to the top tool bar > Extensions > AppSheet > Create an app.

Create a new sheet and put the following algorithms in it:

function callServer(columns, data, job)  {
    let draft = {
        columns,
        data
    };

    const URL = <YOUR_GENERATED_NGROK_URL>+job;

    let options = {
        method: "POST",
        contentType: "application/json",
        headers: {
            "Authorization": "bearer " + ScriptApp.getOAuthToken()
        },
        payload: JSON.stringify(draft),
        muteHttpExceptions: true
    };

    return urlFetchApp.fetch(URL, options);
}

function getGuessedGender() {
    const cs = getCurrentSheet();

    const res = JSON.parse(callServer(["first_name"], cs.rows, "genderize"));

    cs.sheet.get(1, 1, res.length, res[0].length).setValues(res);
}

YOUR_GENERATED_NGROK_URL is where you can paste the ngrok url, then run "getGuessedGender" as the main point of starting the script.

References

:octocat:

About

Small API to format google sheet data from google apps script | Project type: Service | Presentable: :heavy_check_mark:


Languages

Language:Python 100.0%