小编pr0*_*0t0的帖子

使用Google Apps脚本解析XML

我在从boardgamegeek查询中解析XML时遇到困难,以便我可以用数据填充谷歌表.这是bgg xml的一个例子:

<boardgames termsofuse="http://boardgamegeek.com/xmlapi/termsofuse">
  <boardgame objectid="423">
    <yearpublished>1995</yearpublished>
    <minplayers>3</minplayers>
    <maxplayers>6</maxplayers>
    <playingtime>300</playingtime>
    <name primary="true" sortindex="1">1856</name>
  </boardgame>
</boardgames>
Run Code Online (Sandbox Code Playgroud)

这是我编写的Google Apps脚本来解析它:

//get the data from boardgamegeek
  var url = 'http://www.boardgamegeek.com/xmlapi/boardgame/' + bggCode;
  var bggXml = UrlFetchApp.fetch(url).getContentText();

  var document = XmlService.parse(bggXml);
  var root = document.getRootElement();     
  var entries = new Array();
  entries = root.getChildren('boardgame');

  for (var x = 0; x < entries.length; i++) {
    var name = entries[x].getAttribute('name').getValue();
    var yearpublished = entries[x].getAttribute('yearpublished').getValue();
    var minplayers = entries[x].getAttribute('minplayers').getValue();
    var maxplayers = entries[x].getAttribute('maxplayers').getValue();
  }
  //SpreadsheetApp.getActiveSheet().getRange(i+1,7).setValue(yearpublished);
  Logger.log(entries);
Run Code Online (Sandbox Code Playgroud)

我目前在条目为NULL导致for循环中出错.如果我评论循环并记录bggXml的样子,它看起来就像上面的例子.但是,记录变量进一步下降我得到以下内容:

document => …
Run Code Online (Sandbox Code Playgroud)

xml-parsing google-apps-script

6
推荐指数
1
解决办法
1万
查看次数

Firebase Cloud功能不会触发onCreate

尝试使用Cloud Functions处理联系表单提交以发送电子邮件."Hello World"函数启动正常,所以我认为设置很好.表单填充了'messages'集合,但我没有获得以下触发器的日志条目(或错误):

const functions = require('firebase-functions');
const admin = require('firebase-admin')
admin.initializeApp(functions.config().firebase);

const ref = admin.database().ref();

//if user contacts us
exports.sendContactEmail = functions.database
.ref('messages/{msgId}')
.onCreate(event => {

   console.log('Made it to the trigger!');
   const formData = event.data.data(); // the contact form data

   return sendContactEmail(formData);
})

// Sends an email to someone at the company
function sendContactEmail(formInfo) {
   console.log('Made it to the send function!');
   ...
Run Code Online (Sandbox Code Playgroud)

package.json看起来像:

"dependencies": {
   "firebase-admin": "~5.8.1",
   "firebase-functions": "^0.8.1",
Run Code Online (Sandbox Code Playgroud)

firebase google-cloud-functions

2
推荐指数
1
解决办法
2960
查看次数