Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import gs from 'fast-gs';
- import axios from 'axios';
- // Needed to throttle data coming in from Google spreadsheets
- const RateLimiter = require('limiter').RateLimiter;
- const limiter = new RateLimiter(50, 'second');
- // Access details for worksheet
- const googleKey = '';
- const googleSheetId = ;
- // Gets data from Google spreadsheets in JSON format
- function getDataFromGoogleSpreadsheet(cb) {
- gs.toObject(googleKey, googleSheetId, (err, data) => {
- if (err) { cb(err); return; }
- cb(null, data);
- });
- }
- function importData(data) {
- axios({
- url: '', // endpoint for posting data
- method: 'post',
- data: { testA: data.key, testB: data.key }, // Example post data
- })
- .then((res) => {
- // Validate if successful
- })
- .catch((er) => {
- // Check for error
- });
- }
- // Running script
- getDataFromGoogleSpreadsheet((err, result) => {
- if (err) { console.error('Unable to retrieve data from google spreadsheet: ' + err)); return; }
- result.forEach((data) => {
- limiter.removeTokens(1, (errd, throttling) => {
- importData(data);
- })
- .catch((er) => {
- // Error logs
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement