timdows / MMM-JsonTable

A module for the MagicMirror project which creates a table filled with a list gathered from a json request.
MIT License
25 stars 31 forks source link

Get Json from Google "awating" issue #13

Closed emrahaslan closed 4 years ago

emrahaslan commented 4 years ago

Hello, I'm trying to retrieve my sheet from google spreadsheets , but module says "awaiting"

The data in "entry/feed/gsx.." category, I'm not sure what is wrong with my code, but needs your touches.

I also need create loop for bringing with prefix "gsx " values.

URL

https://spreadsheets.google.com/feeds/list/1dVwsdP3K49XGTaixhTTzuybEz4nFubtQzB_Qa32c4ZM/od6/public/values?alt=json

{ module: 'MMM-JsonTable', position: 'top_left', header: 'Majken', config: { url: 'https://spreadsheets.google.com/feeds/list/1dVwsdP3K49XGTaixhTTzuybEz4nFubtQzB_Qa32c4ZM/od6/public/values?alt=json', // Required arrayName: 'object/feed/entry' // Optional } },

image

timdows commented 4 years ago

Its complicated to make this nested array of objects visible in MMM-JsonTable, but I managed

image

I made 3 code changes:

https://github.com/timdows/MMM-JsonTable/blob/master/MMM-JsonTable.js#L59 Get the nested array outside of the configuration

        var items = this.jsonData.feed.entry;
        // if (this.config.arrayName) {
        //  items = this.jsonData[this.config.arrayName];
        // }
        // else {
        //  items = this.jsonData;
        // }

https://github.com/timdows/MMM-JsonTable/blob/master/MMM-JsonTable.js#L87 Only show if it starts with gsx

            if (!key.startsWith("gsx")) {
                continue;
            }
            var cell = document.createElement("td");

https://github.com/timdows/MMM-JsonTable/blob/master/MMM-JsonTable.js#L98 Force to use the $t

valueToDisplay = jsonObject[key].$t;
emrahaslan commented 4 years ago

Hi timdows,

I tried all your steps carefully, but module always says "Awating Json data ". I think data is not coming, but it looks you succeed it.

Configuration

`{ module: 'MMM-JsonTable', position: 'top_right', header: 'Inhabitant Information', config: { url: 'https://spreadsheets.google.com/feeds/list/1dVwsdP3K49XGTaixhTTzuybEz4nFubtQzB_Qa32c4ZM/od6/public/values?alt=json', // Required arrayName: '' // Get the nested array outside of the configuration Optional } }

.js file Line59

`var items =[]; //for google sheets items = this.jsonData.feed.entry;

    //commented for google sheets
    //var items = [];
    //if (this.config.arrayName) {
        //items = this.jsonData[this.config.arrayName];
    //}
    //else {
        //items = this.jsonData;
    //}

`

Line : 100 `getTableRow: function (jsonObject) { var row = document.createElement("tr"); for (var key in jsonObject) {

        //added for googlesheets

        if (!key.startsWith("gsx")) {
            continue;
        }
        `

Line : 117 else if (this.config.tryFormatDate) { //commented for google sheets //valueToDisplay = this.getFormattedValue(jsonObject[key]); //added for googlesheets valueToDisplay = jsonObject[key].$t; } else { if ( this.config.keepColumns.length == 0 || this.config.keepColumns.indexOf(key) >= 0 ){ //commented for google sheets //valueToDisplay = jsonObject[key]; //added for googlesheets valueToDisplay = jsonObject[key].$t; } }

But the result is same, what did i missed ?

image

emrahaslan commented 4 years ago

I re-installed module and try your steps again, now its works. thanks for your support

image

emrahaslan commented 4 years ago

Great Help