【发布时间】:2016-06-24 03:37:31
【问题描述】:
我正在从 RSS 提要中检索数据,并将其作为结构化日期添加到 Firebase 的数据库中。每次刷新 RSS 提要时,都会添加一个新的 UID,但问题是它添加了相同的值。换句话说:
有没有办法检查一个值,例如更新:“Fish shows on all..”已经存在并跳过添加一个全新的 UID?
我使用feedparser (node.js) 进行 rss 解析,这是导致每次刷新时重复的代码:
feedparser.on('readable', function() {
// This is where the action is!
var stream = this
, meta = this.meta // **NOTE** the "meta" is always available in the context of the feedparser instance
, item;
while (item = stream.read()) {
console.log(item);
var pubDate = item.pubDate;
var date = new Date(pubDate);
var description = item.description;
var parts = description.split(' - ', 2);
var time = parts[0];
var update = parts[1];
// date.setTimezone
// var time = date.getHours()+":"+date.getMinutes();
var monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];
var month = monthNames[date.getMonth()]+" "+date.getDate();
var postData = {
time: time,
date: month,
update: update,
description: description,
day: pubDate
};
var newPostKey = firebase.database().ref().child('feed').push().key;
var updates = {};
updates['/feed/' + month + '/' + newPostKey] = postData;
return firebase.database().ref().update(updates);
【问题讨论】:
-
好像要保证某个值是唯一的:stackoverflow.com/questions/25294478/…
标签: node.js firebase firebase-realtime-database