Coder Social home page Coder Social logo

deflinhec / gsx2jsonpp Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 480 KB

Connects to your spreadsheet and santizes the data, providing simple, readable JSON for you to use in your app.

License: MIT License

CMake 14.60% Dockerfile 0.88% PowerShell 1.90% Shell 3.14% C++ 79.49%
json gsx service cpp docker

gsx2jsonpp's Introduction

Build CMake GitHub license GitHub release Maintenance

GSX2JSONPP - Google Spreadsheet to JSON API C/C++ service.

Inspired by 55sketch/gsx2Json, preserve all functinality of origin and implement additional features.

๐Ÿ’ฌ About

One useful feature of Google Spreadsheets is the ability to access the data as JSON by using a particular feed URL. However, this is a bit fiddly to do, and the resulting JSON is pretty unreadable, with usable data buried deep inside objects.

This API connects to your spreadsheet and santizes the data, providing simple, readable JSON for you to use in your app.

๐Ÿณ Using docker image

Make sure docker engine has already install in your operating-system.

In this example below I'm going to use 5000 as port, and output log file under bin/volume directory.

  • Launch with a remote image

    docker pull deflinhec/gsx2jsonpp:latest
    
    docker run -it -d --expose 5000 \
    -v ${PWD}/bin/volume:/workspace \
    -e ARGUMENTS="--host 0.0.0.0 --port 5000" \
    --name gsx2jsonpp-latest deflinhec/gsx2jsonpp
    
    Command line for Windows platform
     docker run -it -d --expose 5000 `
     -v ${PWD}\bin\volume:/workspace `
     -e ARGUMENTS="--host 0.0.0.0 --port 5000" `
     --name gsx2jsonpp-latest deflinhec/gsx2jsonpp
    
  • Launch with a local image

    Follow instructions below, ๐Ÿงฐ Build from source.

    docker build --rm -t gsx2jsonpp .
    
    docker run -it -d --expose 5000 \ 
    -v ${PWD}/bin/volume:/workspace \
    -e ARGUMENTS="--host 0.0.0.0 --port 5000" \
    --name gsx2jsonpp gsx2jsonpp
    
    Command line for Windows platform
    docker run -it -d --expose 5000 `
    -v ${PWD}\bin\volume:/workspace `
    -e ARGUMENTS="--host 0.0.0.0 --port 5000" `
    --name gsx2jsonpp gsx2jsonpp
    

After launched, Gsx2Jsonpp should be accessable in your browser localhost:5000.

Supervisor have been setup within the container to guarantee an auto restart after accidentially crashed(hopefully not).

๐Ÿงฐ Build from source

CMake version must greater than 3.14.0, requires openssl, zlib, brotli installed.

Comparing to docker image, executable size will be way more smaller than using an docker image.

  • Using build script

    git submodule update --init
    

    Avaliable argument: Release|Debug|Project (Default: Release)

    bash scripts/build.sh Release
    
    Command line for Windows platform
    Push-Location scripts; .\build.ps1; Pop-Location
    
    • Launch with executable

      bin/Gsx2Jsonpp --host 0.0.0.0 -p 5000
      
      Command line for Windows platform
      Push-Location bin; .\Gsx2Jsonpp.exe --host 0.0.0.0 -p 5000; Pop-Location
      

๐Ÿท๏ธ Spreadsheet configuration

First, you must publish your spreadsheet to the web, using File -> Publish To Web in your Google Spreadsheet.

Second, locate to your spreadsheet id and sheet number.

https://docs.google.com/spreadsheets/d/[SPREADSHEET_ID]/edit#gid=[SHEET_NUMBER]

You can then access your readable JSON API using the /api endpoint.

http://example.com/api?id=SPREADSHEET_ID&sheet=SHEET_NUMBER

๐ŸŽฏ Spreadsheet rule

  • Column name begin with NOEX_ will not export to the final result.

  • Make sure to add a left most column represents as an unique integer key.

๐Ÿš€ Avaliable launch arguments:

-p, --port (default: 8080): Depends on your network environment.

--host (default: localhost): Depends on your network environment.

--cache ( file | memory | none - default: none): This feature allows client to query on specific data version. When cache is configure with file, cache file will be preserve under cache/ folder. In order to trigger an update, you will have to removes files under cache/ folder manaually or restarts your container if configured with memory.

--ssl ( true | false - default: false): Copy your certification and key into ${PWD}/bin/volume and rename as cert.pem, key.pem. Self-signed certification will be auto generates if absent.

๐Ÿ“ Parameters

id (required): The ID of your document. This is the big long aplha-numeric code in the middle of your document URL.

sheet (optional): The number of the individual sheet you want to get data from. Your first sheet is 1, your second sheet is 2, etc. If no sheet is entered then 1 is the default.

q (optional): A simple query string. This is case insensitive and will add any row containing the string in any cell to the filtered result.

integers (optional - default: true): Setting 'integers' to false will return numbers as a string.

dict (optional - default: true): Setting 'dict' to false will return rows and columns view.

rows (optional - default: true): Setting 'rows' to false will return dictionary and columns view.

columns (optional - default: true): Setting 'columns' to false will return dictionary and rows view.

meta (optional - default: false): Setting 'meta' to true will return only meta data.

pretty (optional - default: false): Pretty print the result if sets to true.

๐Ÿ”– Example Response

Test localhost:5000 with example spreadsheet

Example spreadsheet

There are four sections to the returned data.

  • Columns (containing the names of each column)
  • Dictionary (used left most column as primary key)
  • Rows (containing each row of data as an object)
  • Meta (contains short brief of target data)
Returned data
  {
   "columns": {
    "key": [
     1,
     2,
     3,
     4
    ],
    "column1": [
     "1b",
     "2b",
     "3b",
     "4b"
    ],
    "column2": [
     11,
     22,
     33,
     44
    ]
   },
   "rows": [
    {
     "key": 1,
     "column1": "1b",
     "column2": 11
    },
    {
     "key": 2,
     "column1": "2b",
     "column2": 22
    },
    {
     "key": 3,
     "column1": "3b",
     "column2": 33
    },
    {
     "key": 4,
     "column1": "4b",
     "column2": 44
    }
   ],
   "dict": {
    "1": {
     "key": 1,
     "column1": "1b",
     "column2": 11
    },
    "2": {
     "key": 2,
     "column1": "2b",
     "column2": 22
    },
    "3": {
     "key": 3,
     "column1": "3b",
     "column2": 33
    },
    "4": {
     "key": 4,
     "column1": "4b",
     "column2": 44
    }
   },
   "meta": {
    "columns": {
     "md5": "EAC2F0EF3EA62CEEDD3B65B627B06CBA",
     "bytes": 73
    },
    "rows": {
     "md5": "7767981744A818A7574B4A0B8EBE1C25",
     "bytes": 153
    },
    "dict": {
     "md5": "76C73EAEAFC8BA2ACD890C50E20C1613",
     "bytes": 169
    },
    "time": "2021-02-07T20:00:04.552Z"
   }
  }
  

๐Ÿ“‹ TODO-List

  • โœ… docker image

  • โœ… md5 checksum

  • โœ… cache

gsx2jsonpp's People

Contributors

deflinhec avatar

Stargazers

 avatar  avatar

Watchers

 avatar

gsx2jsonpp's Issues

Supporting Raspberry Pi 4

Greetings all, since Raspberry pi 4 are not capable of source building due to it's cmake version, which is under 3.14.0. I have manager to launch Gsx2jsonpp with docker container under Raspberry Pi 4, but Gsx2jsonpp did not response as expected.

Connection did established in between, but received content length display as 0 within info.log. Still investigate of the cause, It would be grateful if anyone can help on this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.