FGU remote_annoucement url and files fix
This commit is contained in:
parent
42decd3ff4
commit
35733da7ba
|
@ -5,6 +5,7 @@ require 'date'
|
|||
|
||||
@db = Mongo::Connection.new("localhost", 27017).db("fgu_orbit")
|
||||
@coll_bulletin = @db["bulletins"]
|
||||
@bulletin_links = @db["bulletin_links"]
|
||||
@coll_cat = @db["bulletin_categories"]
|
||||
|
||||
@categories = @coll_cat.find().to_a.inject({}) do |categories, category|
|
||||
|
@ -12,6 +13,22 @@ require 'date'
|
|||
categories
|
||||
end
|
||||
|
||||
|
||||
def save_bulletin_links bulletin_id, title, url, c_time
|
||||
|
||||
title = "Link" if title == ''
|
||||
|
||||
bulletin_link = {
|
||||
title: {"zh_tw" => title, "en" => title },
|
||||
url: url,
|
||||
bulletin_id: bulletin_id,
|
||||
created_at: c_time,
|
||||
updated_at: c_time
|
||||
}
|
||||
@bulletin_links.save(bulletin_link)
|
||||
|
||||
end
|
||||
|
||||
def get_remote_bulletins_json(url)
|
||||
data = ""
|
||||
open(url){|f| f.each_line {|line| data << line} }
|
||||
|
@ -57,6 +74,17 @@ def get_remote_bulletins_json(url)
|
|||
|
||||
unless this_bulletin
|
||||
@coll_bulletin.save(bulletin)
|
||||
|
||||
|
||||
#files
|
||||
(10..14).each do |i|
|
||||
ta = i + 5
|
||||
save_bulletin_links( bulletin[:_id], b[ta], b[i], bulletin[:created_at] ) if b[i] != ''
|
||||
end
|
||||
|
||||
#url
|
||||
save_bulletin_links( bulletin[:_id], '', b[20], bulletin[:created_at] ) if b[20] != ''
|
||||
|
||||
# puts "Inserted "+lang.to_s+" "+bulletin[:title][lang]
|
||||
# p bulletin
|
||||
else
|
||||
|
@ -85,6 +113,18 @@ def get_remote_bulletins_json(url)
|
|||
:is_hot => this_bulletin["is_hot"],
|
||||
:is_hidden => this_bulletin["is_hidden"]
|
||||
})
|
||||
|
||||
@bulletin_links.remove(bulletin_id: BSON::ObjectId(this_bulletin["_id"].to_s) )
|
||||
|
||||
#files
|
||||
(10..14).each do |i|
|
||||
ta = i + 5
|
||||
save_bulletin_links( this_bulletin["_id"], b[ta], b[i], this_bulletin["created_at"] ) if b[i] != ''
|
||||
end
|
||||
|
||||
#url
|
||||
save_bulletin_links( this_bulletin["_id"], '', b[20], bulletin[:created_at] ) if b[20] != ''
|
||||
|
||||
# puts "Updated "+lang.to_s+" "+bulletin[:title][lang]
|
||||
# p this_bulletin["_id"]
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue