Update import new from Rss2
This commit is contained in:
parent
d853cb9f63
commit
befaae9b13
|
@ -5,8 +5,9 @@ require 'json'
|
|||
class Admin::ImportController < ApplicationController
|
||||
|
||||
def rss2_news
|
||||
@url = "http://192.168.1.10/alreadly_removed/NKUT/NKUT_01/remote_annoucement/get_news.php"
|
||||
@url = params['url']
|
||||
uri = URI.parse(@url)
|
||||
@host = uri.host
|
||||
http = Net::HTTP.new(uri.host, uri.port)
|
||||
request = Net::HTTP::Get.new(uri.request_uri)
|
||||
response = http.request(request)
|
||||
|
@ -38,7 +39,6 @@ class Admin::ImportController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
@regexp = /(https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\/_\.]*(\?\S+)?)?)?)/
|
||||
@user = User.where(:user_id => "rulingcom").first
|
||||
|
||||
@data.each do |row|
|
||||
|
@ -46,19 +46,23 @@ class Admin::ImportController < ApplicationController
|
|||
bulletin.title_translations = row['Title']
|
||||
bulletin.subtitle_translations = row['Summary']
|
||||
|
||||
|
||||
@site_valid_locales.each do |locale|
|
||||
temp = row['Content'][locale]
|
||||
urls = temp.scan(@regexp)
|
||||
|
||||
urls = Nokogiri::HTML(temp).css("img").map do |link|
|
||||
if URI.parse(link.attr("src")).host == @host
|
||||
link.attr("src")
|
||||
end
|
||||
end
|
||||
|
||||
urls.each do |url|
|
||||
u = url[0]
|
||||
a = Asset.new
|
||||
a.remote_data_url = u
|
||||
a.remote_data_url = url
|
||||
a.assetable_type = "User"
|
||||
a.assetable_id = @user.id
|
||||
a.title = {"en" => a["data"], "zh_tw" => a["data"]}
|
||||
a.save!
|
||||
temp.sub!(u,a.data.to_s)
|
||||
temp.sub!(url,a.data.to_s)
|
||||
end
|
||||
row['Content'][locale] = temp
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue