From 35733da7badfea0bf75090e6bd87b2da29c2b1ff Mon Sep 17 00:00:00 2001 From: Spen Date: Fri, 4 Oct 2013 10:59:51 +0800 Subject: [PATCH] FGU remote_annoucement url and files fix --- lib/remote_announcement.rb | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/lib/remote_announcement.rb b/lib/remote_announcement.rb index ad90b526f..75fd43d20 100644 --- a/lib/remote_announcement.rb +++ b/lib/remote_announcement.rb @@ -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