Class: Meiriyigua::PostClientTwo

Inherits:
Object
  • Object
show all
Includes:
Models
Defined in:
lib/meiriyigua/post_client_two.rb

Constant Summary collapse

ZHS =
0x4e00..0x9fff

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePostClientTwo

Returns a new instance of PostClientTwo.



14
15
16
# File 'lib/meiriyigua/post_client_two.rb', line 14

def initialize
  @agent = CrawlClient.create_agent
end

Instance Attribute Details

#category_idsObject (readonly)

Returns the value of attribute category_ids.



12
13
14
# File 'lib/meiriyigua/post_client_two.rb', line 12

def category_ids
  @category_ids
end

Instance Method Details

#post_news(page_record) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/meiriyigua/post_client_two.rb', line 41

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

#runObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/meiriyigua/post_client_two.rb', line 18

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