作者:漆黑中的萤火虫 | 来源:互联网 | 2023-10-12 19:58
Iperiodicallyfetchthelatesttweetswithacertainhashtagandsavethemlocally.Inordertopre
I periodically fetch the latest tweets with a certain hashtag and save them locally. In order to prevent saving duplicates, I use the method below. Unfortunately, it does not seem to be working... so what's wrong with this code:
我会定期使用特定的标签获取最新的推文并将其保存在本地。为了防止保存重复,我使用下面的方法。不幸的是,它似乎没有工作......所以这段代码有什么问题:
def remove_duplicates
before = @tweets.size
@tweets.delete_if {|tweet| !((Tweet.all :cOnditions=> { :twitter_id => tweet.twitter_id}).empty?) }
duplicates = before - @tweets.size
puts "#{duplicates} duplicates found"
end
Where @tweets is an array of Tweet objects fetched from twitter. I'd appreciate any solution that works and especially one that might be more elegant...
其中@tweets是从twitter获取的Tweet对象数组。我很感激任何有效的解决方案,特别是可能更优雅的解决方案......
4 个解决方案