Created
May 4, 2012 20:27
-
-
Save 7even/2597518 to your computer and use it in GitHub Desktop.
репликация новостей с вконтакта
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'vkontakte_api' | |
# id группы с минусом | |
GROUP_ID = -1 | |
# id последней новости, сохраненной в БД | |
last_news_id = News.maximum(:vk_id) | |
vk = VK::Client.new | |
all_news = vk.wall.get(owner_id: GROUP_ID).tap(&:shift).reverse | |
all_news.each do |news_attributes| | |
next unless news_attributes[:id] > last_news_id | |
News.create! do |n| | |
n.vk_id = news_attributes[:id] | |
n.text = news_attributes[:text] | |
n.vk_date = Time.at(news_attributes[:date]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment