FGU remote_annoucement url and files fix

This commit is contained in:
Spen 2013-10-04 10:59:51 +08:00
parent 42decd3ff4
commit 35733da7ba
1 changed files with 40 additions and 0 deletions

View File

@ -5,6 +5,7 @@ require 'date'
@db = Mongo::Connection.new("localhost", 27017).db("fgu_orbit") @db = Mongo::Connection.new("localhost", 27017).db("fgu_orbit")
@coll_bulletin = @db["bulletins"] @coll_bulletin = @db["bulletins"]
@bulletin_links = @db["bulletin_links"]
@coll_cat = @db["bulletin_categories"] @coll_cat = @db["bulletin_categories"]
@categories = @coll_cat.find().to_a.inject({}) do |categories, category| @categories = @coll_cat.find().to_a.inject({}) do |categories, category|
@ -12,6 +13,22 @@ require 'date'
categories categories
end 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) def get_remote_bulletins_json(url)
data = "" data = ""
open(url){|f| f.each_line {|line| data << line} } open(url){|f| f.each_line {|line| data << line} }
@ -57,6 +74,17 @@ def get_remote_bulletins_json(url)
unless this_bulletin unless this_bulletin
@coll_bulletin.save(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] # puts "Inserted "+lang.to_s+" "+bulletin[:title][lang]
# p bulletin # p bulletin
else else
@ -85,6 +113,18 @@ def get_remote_bulletins_json(url)
:is_hot => this_bulletin["is_hot"], :is_hot => this_bulletin["is_hot"],
:is_hidden => this_bulletin["is_hidden"] :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] # puts "Updated "+lang.to_s+" "+bulletin[:title][lang]
# p this_bulletin["_id"] # p this_bulletin["_id"]
end end