mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 09:53:43 +08:00
1574485443
This refactoring was automated using the command: bundle exec "ruby refactorings/where_dot_first_to_find_by/app.rb"
45 lines
1.1 KiB
Ruby
45 lines
1.1 KiB
Ruby
#
|
|
# Creates and Updates Topics based on an RSS or ATOM feed.
|
|
#
|
|
require 'digest/sha1'
|
|
require_dependency 'post_creator'
|
|
require_dependency 'post_revisor'
|
|
require 'open-uri'
|
|
|
|
module Jobs
|
|
class PollFeed < Jobs::Scheduled
|
|
every 1.hour
|
|
|
|
sidekiq_options retry: false
|
|
|
|
def execute(args)
|
|
poll_feed if SiteSetting.feed_polling_enabled? &&
|
|
SiteSetting.feed_polling_url.present? &&
|
|
SiteSetting.embed_by_username.present?
|
|
end
|
|
|
|
def feed_key
|
|
@feed_key ||= "feed-modified:#{Digest::SHA1.hexdigest(SiteSetting.feed_polling_url)}"
|
|
end
|
|
|
|
def poll_feed
|
|
user = User.find_by(username_lower: SiteSetting.embed_by_username.downcase)
|
|
return if user.blank?
|
|
|
|
require 'simple-rss'
|
|
rss = SimpleRSS.parse open(SiteSetting.feed_polling_url)
|
|
|
|
rss.items.each do |i|
|
|
url = i.link
|
|
url = i.id if url.blank? || url !~ /^https?\:\/\//
|
|
|
|
content = i.content || i.description
|
|
if content
|
|
TopicEmbed.import(user, url, i.title, CGI.unescapeHTML(content.scrub))
|
|
end
|
|
end
|
|
end
|
|
|
|
end
|
|
end
|