Created
April 3, 2020 06:20
-
-
Save sagarpanda/1023f6c7a6260e0cb2322e27cba0762d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function fetchGoogleSheetFeed({spreadsheetId, sheetNum}) { | |
| const tab = sheetNum || 1; | |
| const fetchUrl = `https://spreadsheets.google.com/feeds/cells/${spreadsheetId}/${tab}/public/full?alt=json`; | |
| const data = await fetch(fetchUrl).then(response => { | |
| if(response.status === 200) { | |
| return response.json(); | |
| } else { | |
| return { feed: { entry: [] }}; | |
| } | |
| }); | |
| let count = 0; | |
| const rowData = data.feed.entry.reduce((prev, curr) => { | |
| const { row, col } = curr['gs$cell']; | |
| const content = curr.content['$t']; | |
| const rowIndex = row - 1; | |
| const colIndex = col - 1; | |
| if(prev[rowIndex]) { | |
| prev[rowIndex][`col${colIndex}`] = content; | |
| } else { | |
| prev[rowIndex] = { [`col${colIndex}`]: content }; | |
| } | |
| return prev; | |
| }, []); | |
| return rowData; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment