Fix bugs for FGU remote_annoucement

Added english support
Skip data with blank title
This commit is contained in:
Manson Wang 2013-10-02 09:33:24 +08:00
parent e2d09c7379
commit f851ad0e27
1 changed files with 54 additions and 20 deletions

View File

@ -20,34 +20,68 @@ def get_remote_bulletins_json(url)
bulletins.each do |b|
lang = b[1]=='zh-tw' ? "zh_tw".to_sym : "en".to_sym
next if b[2]==""
bulletin = { _type: "Bulletin",
postdate: Time.now,
created_at: Time.now,
updated_at: Time.now,
postdate: Time.parse(b[8]),
created_at: Time.parse(b[8]),
updated_at: Time.parse(b[8]),
is_checked: true,
is_pending: false,
is_rejected: false,
bulletin_category_id: @categories["#{b[7]}"],
title: {:zh_tw => b[2]},
text: {:zh_tw => b[5]},
title: {lang => b[2]},
text: {lang => b[5]},
available_for_zh_tw: true,
available_for_en: false,
available_for_en: true,
create_user_id: "",
public: true,
sn: b[0],
site: b[9],
site_id: b[10],
is_top: false,
is_hot: false,
is_hidden: false }
unless @coll_bulletin.find_one(:$and => [{ :sn => bulletin[:sn]},{ :site => bulletin[:site]}])
this_bulletin = @coll_bulletin.find_one(:$and => [{ :sn => bulletin[:sn]},{ :site => bulletin[:site]}])
# p bulletin
unless this_bulletin
@coll_bulletin.save(bulletin)
# puts "Inserted"
# puts "Inserted "+lang.to_s+" "+bulletin[:title][lang]
# p bulletin
else
# puts "Exist"
@coll_bulletin.update(
{"_id"=>this_bulletin["_id"]},
{
:_type => "Bulletin",
:postdate => bulletin[:postdate],
:created_at => bulletin[:created_at],
:updated_at => bulletin[:updated_at],
:is_checked => this_bulletin["is_checked"],
:is_pending => this_bulletin["is_pending"],
:is_rejected => this_bulletin["is_rejected"],
:bulletin_category_id => bulletin[:bulletin_category_id],
:title => bulletin[:title],
:text => bulletin[:text],
:available_for_zh_tw => this_bulletin["available_for_zh_tw"],
:available_for_en => this_bulletin["available_for_en"],
:create_user_id => "",
:public => this_bulletin["public"],
:sn => bulletin[:sn],
:site => bulletin[:site],
:site_id => bulletin[:site_id],
:is_top => this_bulletin["is_top"],
:is_hot => this_bulletin["is_hot"],
:is_hidden => this_bulletin["is_hidden"]
})
# puts "Updated "+lang.to_s+" "+bulletin[:title][lang]
# p this_bulletin["_id"]
end
end
end
get_remote_bulletins_json("http://president.fgu.edu.tw/remote_annoucement/get_news.php")
get_remote_bulletins_json("http://car.fgu.edu.tw/remote_annoucement/get_news.php")
get_remote_bulletins_json("http://president.fgu.edu.tw/remote_annoucement/get_news2.php")
get_remote_bulletins_json("http://car.fgu.edu.tw/remote_annoucement/get_news2.php")