class Meiriyigua::PostClientTwo

Constants

ZHS

Attributes

category_ids[R]

Public Class Methods

new() click to toggle source
# File lib/meiriyigua/post_client_two.rb, line 13
def initialize
  @agent = CrawlClient.create_agent
end

Public Instance Methods

post_news(page_record) click to toggle source
# File lib/meiriyigua/post_client_two.rb, line 40
def post_news(page_record)
  post_params = {}
  post_params['A'] = page_record.title
  downloads = page_record.downloads.split('#!#')
  post_params['xiadizhi'] = downloads[0]
  post_params['xiadizhi2'] = downloads[1]
  post_params['tjiao'] = 'opop'
  post_params['editorValue'] = "<pre>#{page_record.content} \r\n\r\n #{page_record.baidu_intro}</pre>"
  @agent.post("http://#{Meiriyigua::Config.site_host}/ti.php", post_params)
end
run() click to toggle source
# File lib/meiriyigua/post_client_two.rb, line 17
def run
  today_count = UrlRecord.count(:publish_at.gte => Date.today)

  if today_count >= Meiriyigua::Config.day_num
    return
  end

  UrlRecord.all(:baidu_at.not => nil, :publish_at => nil).each do |url_record|
    today_count += 1
    if today_count >= Meiriyigua::Config.day_num
      return
    end

    page_record = url_record.page_record
    post_news(page_record)
    url_record.publish_at = Time.now
    url_record.save
    print "发布 #{url_record.url} "
    puts "成功"
    sleep Meiriyigua::Config.post_time.to_i
  end
end