Added read rss2 annoucement feature

This commit is contained in:
Manson Wang 2013-09-26 13:38:27 +08:00
parent 926102bf72
commit 25c1f191b2
3 changed files with 70 additions and 2 deletions

View File

@ -0,0 +1,7 @@
class GetRemoteAnnouncement
@queue = :high
def self.perform()
%x(ruby "#{Rails.root}/lib/remote_announcement.rb")
end
end

View File

@ -11,7 +11,8 @@ backup_server:
description: BackupServer and remove old backups description: BackupServer and remove old backups
update_tag_cloud: update_tag_cloud:
cron: 0 0 [0,12] * * * # cron: 0 0 [0,12] * * *
cron: 0 0 0 * * *
class: UpdateTagCloud class: UpdateTagCloud
args: args:
description: UpdateTagCloud description: UpdateTagCloud
@ -23,7 +24,14 @@ generate_system_summary:
description: Generate the system status such as disk free space,package version list for showing at site tab description: Generate the system status such as disk free space,package version list for showing at site tab
email_cron: email_cron:
cron: 0 0 [10,16,22] * * * # cron: 0 0 [10,16,22] * * *
cron: 0 0 10 * * *
class: EmailCron class: EmailCron
args: args:
description: EmailCron description: EmailCron
get_remote_announcement:
cron: */5 * * * * *
class: GetRemoteAnnouncement
args:
description: GetRemoteAnnouncement

View File

@ -0,0 +1,53 @@
require 'mongo'
require 'open-uri'
require 'json'
require 'date'
@db = Mongo::Connection.new("localhost", 27017).db("fgu_orbit")
@coll_bulletin = @db["bulletins"]
@coll_cat = @db["bulletin_categories"]
@categories = @coll_cat.find().to_a.inject({}) do |categories, category|
categories[category['key']] = category['_id']
categories
end
def get_remote_bulletins_json(url)
data = ""
open(url){|f| f.each_line {|line| data << line} }
bulletins = JSON.parse data
bulletins.each do |b|
bulletin = { _type: "Bulletin",
postdate: Time.now,
created_at: Time.now,
updated_at: Time.now,
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]},
available_for_zh_tw: true,
available_for_en: false,
create_user_id: "",
public: true,
sn: b[0],
site: b[9],
is_top: false,
is_hot: false,
is_hidden: false }
unless @coll_bulletin.find_one(:$and => [{ :sn => bulletin[:sn]},{ :site => bulletin[:site]}])
@coll_bulletin.save(bulletin)
# puts "Inserted"
else
# puts "Exist"
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")