Skip to content

Instantly share code, notes, and snippets.

@7even
Created May 4, 2012 20:27
Show Gist options
  • Save 7even/2597518 to your computer and use it in GitHub Desktop.
Save 7even/2597518 to your computer and use it in GitHub Desktop.
репликация новостей с вконтакта
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