Advertisement
Guest User

Untitled

a guest
May 27th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. import gs from 'fast-gs';
  2. import axios from 'axios';
  3.  
  4. // Needed to throttle data coming in from Google spreadsheets
  5. const RateLimiter = require('limiter').RateLimiter;
  6. const limiter = new RateLimiter(50, 'second');
  7.  
  8. // Access details for worksheet
  9. const googleKey = '';
  10. const googleSheetId = ;
  11.  
  12. // Gets data from Google spreadsheets in JSON format
  13. function getDataFromGoogleSpreadsheet(cb) {
  14. gs.toObject(googleKey, googleSheetId, (err, data) => {
  15. if (err) { cb(err); return; }
  16. cb(null, data);
  17. });
  18. }
  19.  
  20. function importData(data) {
  21. axios({
  22. url: '', // endpoint for posting data
  23. method: 'post',
  24. data: { testA: data.key, testB: data.key }, // Example post data
  25. })
  26. .then((res) => {
  27. // Validate if successful
  28. })
  29. .catch((er) => {
  30. // Check for error
  31. });
  32. }
  33.  
  34. // Running script
  35. getDataFromGoogleSpreadsheet((err, result) => {
  36. if (err) { console.error('Unable to retrieve data from google spreadsheet: ' + err)); return; }
  37. result.forEach((data) => {
  38. limiter.removeTokens(1, (errd, throttling) => {
  39. importData(data);
  40. })
  41. .catch((er) => {
  42. // Error logs
  43. });
  44. });
  45. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement