I am having three functions to fetch screenshots, yelp and google data of a website.The result of these three functions are pushed to an array of subdocuments which will get inserted to database.I need to increase the performance of this api.Is it possible to call these functions using parallel async in meteor without using npm module?
The line of code I used is shown below
Meteor.methods({
insertApart : function(apart){
var google_data = setGoogleData(apart);
var screen_captures_data = setScreenShots(apart);
var yelp_data = setYelpData(apart);
function setGoogleData(apart) {
// code to fetch google data
}
function setScreenShots(apart) {
// code to fetch screen shots
}
function setYelpData(apart) {
// code to fetch yelp data
}
var data=[];
data.google = google_data;// setting google data
data.screen_captures = screen_captures_data;// setting screen captures
data.yelp = yelp_data;// setting yelp data
var id = Apartments.insert(data);
return id;
}
});
Related
I get this exception since I started integrating Google Sheets and Firebase and Firestore. Despite all the tutorials and articles, non of the solutions worked with me.
my issue is when using getDocuments method for retrieving all the docs, the program throws an exception saying Error: Missing or insufficient permissions.
I already project created in Google Cloud, and I have created all the services needed and added all the APIs as instructed from Google Cloud website. Also, I have added oauthscopes needed. unfortunately, it did not work also.
My code:
function getRatingData() {
// Initialize firestore
const firestore = initFirestore();
// Initialize spread sheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
var activeSpreadSheet = ss.getSheetByName("Sheet1");
// Get all docs
const docs = firestore.getDocuments("rating_debug");
for(var i = 0; i < docs.length; i++){
var array = [];
const lastRow = activeSpreadSheet.getLastRow();
// Get data field of each doc
var date = docs[i].fields["date"];
array.push(date);
var customerID = docs[i].fields["customerID"];
array.push(customerID.stringValue);
var mandoobID = docs[i].fields["mandoobID"];
array.push(mandoobID.stringValue);
var offerUniqueID = docs[i].fields["offerUniqueID"];
array.push(offerUniqueID.stringValue);
var message = docs[i].fields["message"];
array.push(message.stringValue);
var rating = docs[i].fields["rating"];
array.push(rating);
activeSpreadSheet.appendRow(array)[lastRow + 1];
}
}
function initFirestore(){
var config = {
"project_id" : "PROJECT-ID",
"private_key" : "PRIVATE-KEY",
"client_email" : "CLIENT-EMAIL",
};
return FirestoreApp.getFirestore(config.client_email, config.private_key, config.project_id);
}
My oauthScopes
"https://www.googleapis.com/auth/spreadsheets.readonly",
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/script.container.ui",
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/compute",
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/cloud-platform.read-only",
"https://www.googleapis.com/auth/datastore",
"https://www.googleapis.com/auth/firebase",
"https://www.googleapis.com/auth/firebase.readonly",
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/script.deployments",
"https://www.googleapis.com/auth/script.projects",
"https://www.googleapis.com/auth/drive.readonly",
"https://www.googleapis.com/auth/gmail.addons.current.message.metadata",
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/drive.file",
"https://www.googleapis.com/auth/script.scriptapp",
"https://www.googleapis.com/auth/script.locale",
"https://www.googleapis.com/auth/documents.currentonly",
"https://www.googleapis.com/auth/spreadsheets.currentonly",
"https://www.googleapis.com/auth/presentations.currentonly",
"https://www.googleapis.com/auth/drive.addons.metadata.readonly",
"https://www.googleapis.com/auth/gmail.addons.current.action.compose",
"https://www.googleapis.com/auth/firebase.database"
This is my output for more clarification
photo of the output
I must admit that I donĀ“t have much experience so I tried my best so far-
I made a webhook on my woocommerce store and made a script on google apps to export new order data directly to spreadsheet.
The script partly works but the problem is that when there are more products in order it only exports one row and ignores the rest - so the order ID is correct the name of customer is exported but just 1 of his products from his order is exported to spreadsheet, second problem is that product ID is wrong.
The script is below:
//this is a function that fires when the webapp receives a GET request
function doGet(e) {
return HtmlService.createHtmlOutput("request received");
}
//this is a function that fires when the webapp receives a POST request
function doPost(e) {
var myData = JSON.parse([e.postData.contents]);
var order_number = myData.number;
var shipping_company = myData.shipping.company;
var shipping_method = myData.shipping_lines[0].method_title;
var customer_note = myData.customer_note;
var shipping_lastname = myData.shipping.last_name;
var lineitems=""
for (i in myData.line_items)
{
var product_id = myData.line_items[i].product_id;
var quantity = myData.line_items[i].quantity;
}
var sheet = SpreadsheetApp.getActive().getSheetByName("export");
sheet.appendRow([order_number,product_id,customer_note,shipping_method,shipping_lastname,shipping_company,quantity,lineitems]);
}
on the sheet there is one order - which actually has 3 products in the order but only one was exported, also product ID is 4135 and correct should be 4137.
If anyone has any feedback for me I would be very happy for any help, thanks.
Guys thanks for the helpful tips - I changed the looping and I also realized that I was exporting product_id but in fact what I was looking for variation_id.
Here is the finished code I hope it will help someone:
//this is a function that fires when the webapp receives a GET request
function doGet(e) {
return HtmlService.createHtmlOutput("request received");
}
//this is a function that fires when the webapp receives a POST request
function doPost(e) {
var myData = JSON.parse([e.postData.contents]);
var order_number = myData.number;
var shipping_company = myData.shipping.company;
var shipping_method = myData.shipping_lines[0].method_title;
var customer_note = myData.customer_note;
var shipping_lastname = myData.shipping.last_name;
var lineitems=""
for (i in myData.line_items)
{
var variation_id = myData.line_items[i].variation_id;
var quantity = myData.line_items[i].quantity;
var product_items = variation_id;
var lineitems =lineitems+product_items;
var sheet = SpreadsheetApp.getActive().getSheetByName("export");
sheet.appendRow([order_number,variation_id,customer_note,shipping_method,shipping_lastname,shipping_company,quantity]);
}
}
As I would like to create documents by merging the entries in a list into a Google Docs template. I have therefore integrated the DocumentMerge method from my previous question into a printButton in a list widget.
Clicking on the printButton should produce a document that merges the contents of the current row into the document template. But when I click on the printButton the method fails due to a circular reference. How can I fix that? The print method goes like this ...
function printReview(widget) {
var review = app.models.Review.getRecord(widget.datasource.item._key);
var templateId = 'templateId';
var filename = 'Review for ...' + new Date();
var copyFile = DriveApp.getFileById(templateId).makeCopy(filename);
var copyDoc = DocumentApp.openById(copyFile.getId());
var copyBody = copyDoc.getBody();
var fields = app.metadata.models.Review.fields;
for (var i in fields) {
var text = '$$' + fields[i].name + '$$';
var data = review[fields[i].name];
copyBody.replaceText(text, data);
}
copyDoc.saveAndClose();
}
As Morfinismo noticed you are getting the error because you are trying to pass complex object from client to server and serializer fails to handle it. In order to fix that you need to adjust your code:
// onClick button's event handler (client script)
function onPrintClick(button) {
var reviewKey = button.datasource.item._key;
google.script.run
.withSuccessHandler(function() { /* TODO */ })
.withFailureHandler(function() { /* TODO */ })
.printReview(reviewKey);
}
// server script
function printReview(reviewKey) {
var review = app.models.Review.getRecord(reviewKey);
...
}
I'm trying to add to my ionic 1.x app offline capabilities by storing some data to localStorage while offline, and then once online again (networking issues for example) sync the data to the cloud. I came up with this service, however I dont know if this is the correct way to go. Is there a more correct way of pushing several objects to firebase at once\one after another?
.service("syncOFFLINE_Service", function (fireBaseService) {
var dataArray= JSON.parse(localStorage.getItem("offline_data"));
this.syncExpenses = function(){
for(var i = 0; i < dataArray.length; i++){
fireBaseService.addDataToDB(dataArray[i],firebase.auth().currentUser.uid);
}
localStorage.removeItem('offline_expenses');//clear offline data once the loop is over
}
})
And this is the service that adds data (one object at a time) to firebase:
this.addDataToDB = function (expense, uid) {
var newExpenseKey = firebase.database().ref().child('expenses').push().key;
var updates = {};
var keyByDate = "somekey";
updates['/user-expenses/' + uid + '/' + keyByDate + '/'+ newExpenseKey] = expense;
return firebase.database().ref().update(updates);
};
I would like to have a template value {{abc}} that is reactive to changes triggered by other code in my application, but it is not a database field. I have seen the Session variable being used for this but is this the only way?
Please have a look at meteor documentation with examples.
From there:
var weather = "sunny";
var weatherDep = new Deps.Dependency;
var getWeather = function () {
weatherDep.depend()
return weather;
};
var setWeather = function (w) {
weather = w;
// (could add logic here to only call changed()
// if the new value is different from the old)
weatherDep.changed();
};
So everytime you call setWeather() the dependency in getWeather() will be flagged as changed and call any reactive functions to run again with the new value.