wx_ext 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/wx_ext/sougou_weixin.rb +68 -0
- data/lib/wx_ext/version.rb +1 -1
- data/lib/wx_ext.rb +2 -0
- data/spec/wx_ext/sougou_weixin_spec.rb +11 -0
- data/spec/wx_ext/weixin_spec.rb +5 -3
- data/wx_ext.gemspec +0 -4
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d4dc7c81727a8fe95cec098764ca3b6ae5a6cb1
|
4
|
+
data.tar.gz: 455e5391ca5abb4c9d687b3d48d3881cea885157
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc430085462ce84e094c10a7c1e713e45d0e3fa57be0b28467e757a4a3965ddb9cdae7e4d9cc97baf8c53cb95641b6ae91ba66d241ea4026a41a5ec8e1282b62
|
7
|
+
data.tar.gz: 4969fa8eaa4cbdabf692838c9ba35a8dc09a016197ebf4c3f11039312ee79577cdddf94aff52807b7d30d6aa08541dc2d08481060cd47e23c095206cee5fd455
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem 'wx_ext', '~> 0.1.
|
10
|
+
gem 'wx_ext', '~> 0.1.1'
|
11
11
|
```
|
12
12
|
|
13
13
|
And then execute:
|
@@ -22,6 +22,7 @@ And then execute:
|
|
22
22
|
|
23
23
|
1. 修改 spec/wx_ext/weixin_spec.rb 文件中的账户密码
|
24
24
|
2. rspec spec/wx_ext/weixin_spec.rb
|
25
|
+
3. rspec spec/wx_ext/sougou_weixin_spec.rb
|
25
26
|
|
26
27
|
## Contributing
|
27
28
|
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'rest_client'
|
4
|
+
require 'json'
|
5
|
+
require 'open-uri'
|
6
|
+
module WxExt
|
7
|
+
class SougouWeixin
|
8
|
+
def self.spider_posts_from_sougou(openid, page_index = 1, date_last = '2000-01-01')
|
9
|
+
url = "http://weixin.sogou.com/gzhjs?openid=#{openid}&page=#{page_index}"
|
10
|
+
res = RestClient.get url, {:accept => :json}
|
11
|
+
|
12
|
+
date_last_arr = date_last.to_s.split('-')
|
13
|
+
date_last_to_com = Time.new(date_last_arr[0], date_last_arr[1], date_last_arr[2])
|
14
|
+
|
15
|
+
xml_articles = nil
|
16
|
+
response_time = nil
|
17
|
+
total_items = nil
|
18
|
+
total_pages = nil
|
19
|
+
page = nil
|
20
|
+
|
21
|
+
reg = /gzh\((.*)\).*\/\/<\!--.*--><\!--(\d+)-->/m
|
22
|
+
if reg =~ res.to_s
|
23
|
+
xml_articles = JSON.parse($1)['items']
|
24
|
+
total_items = JSON.parse($1)['totalItems']
|
25
|
+
total_pages = JSON.parse($1)['totalPages']
|
26
|
+
page = JSON.parse($1)['page']
|
27
|
+
response_time = $2.to_i
|
28
|
+
else
|
29
|
+
return {}
|
30
|
+
end
|
31
|
+
spider_posts = []
|
32
|
+
xml_articles.each do |xml|
|
33
|
+
doc = Nokogiri::XML(xml.to_s, nil, "UTF-8")
|
34
|
+
date = doc.at_xpath('//DOCUMENT/item/display/date').text
|
35
|
+
|
36
|
+
spider_post = {}
|
37
|
+
|
38
|
+
date_arr = date.to_s.split('-')
|
39
|
+
date_to_com = Time.new(date_arr[0], date_arr[1], date_arr[2])
|
40
|
+
if date_last_to_com < date_to_com
|
41
|
+
spider_post[:title] = doc.at_xpath('//DOCUMENT/item/display/title1').text
|
42
|
+
spider_post[:url] = doc.at_xpath('//DOCUMENT/item/display/url').text
|
43
|
+
spider_post[:img] = doc.at_xpath('//DOCUMENT/item/display/imglink').text
|
44
|
+
# logo = doc.at_xpath('//DOCUMENT/item/display/headimage').text
|
45
|
+
# sourcename = doc.at_xpath('//DOCUMENT/item/display/sourcename').text
|
46
|
+
spider_post[:content_short] = doc.at_xpath('//DOCUMENT/item/display/content168').text
|
47
|
+
|
48
|
+
doc_post = Nokogiri::HTML(open(url), nil, "UTF-8")
|
49
|
+
node_author = doc_post.css('div.rich_media_meta_list > em.rich_media_meta.rich_media_meta_text')[1]
|
50
|
+
spider_post[:author] = node_author ? node_author.content : '无'
|
51
|
+
spider_post[:content] = doc_post.css('div.rich_media_content').first.to_s
|
52
|
+
spider_posts.push spider_post
|
53
|
+
else
|
54
|
+
break
|
55
|
+
end
|
56
|
+
end
|
57
|
+
{
|
58
|
+
total_items: total_items,
|
59
|
+
total_pages: total_pages,
|
60
|
+
page: page,
|
61
|
+
response_time: response_time,
|
62
|
+
spider_posts: spider_posts,
|
63
|
+
original_count: xml_articles.count,
|
64
|
+
count: spider_posts.count
|
65
|
+
}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/wx_ext/version.rb
CHANGED
data/lib/wx_ext.rb
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe WxExt::SougouWeixin do
|
5
|
+
|
6
|
+
it 'should spider some posts from weixin.sougou.com' do
|
7
|
+
spider_posts = WxExt::SougouWeixin.spider_posts_from_sougou('oIWsFt-tphuh--mRkYQI-TePFFBo', 1)
|
8
|
+
puts spider_posts
|
9
|
+
expect(spider_posts[:original_count]).to eql(10)
|
10
|
+
end
|
11
|
+
end
|
data/spec/wx_ext/weixin_spec.rb
CHANGED
@@ -3,8 +3,9 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe WxExt::WeiXin do
|
5
5
|
before(:all) do
|
6
|
-
@weixin = WxExt::WeiXin.new '
|
6
|
+
@weixin = WxExt::WeiXin.new 'username', 'pass'
|
7
7
|
end
|
8
|
+
|
8
9
|
=begin
|
9
10
|
it 'should login to the mp' do
|
10
11
|
res_hash = @weixin.login
|
@@ -86,7 +87,7 @@ describe WxExt::WeiXin do
|
|
86
87
|
expect(star_res_hash['ret'].to_s).to eql('0')
|
87
88
|
end
|
88
89
|
end
|
89
|
-
|
90
|
+
|
90
91
|
|
91
92
|
it 'should get fans count' do
|
92
93
|
res_hash = @weixin.login
|
@@ -112,7 +113,8 @@ describe WxExt::WeiXin do
|
|
112
113
|
puts 'init failed'
|
113
114
|
end
|
114
115
|
end
|
115
|
-
|
116
|
+
|
117
|
+
|
116
118
|
it "should get new msg num" do
|
117
119
|
res_hash = @weixin.login
|
118
120
|
flag = @weixin.init
|
data/wx_ext.gemspec
CHANGED
@@ -24,8 +24,4 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency 'rspec'
|
25
25
|
spec.add_dependency 'rest_client'
|
26
26
|
spec.add_dependency 'nokogiri'
|
27
|
-
# spec.add_dependency 'mechanize'
|
28
|
-
# spec.add_dependency 'phantomjs', '~> 1.9.7.1'
|
29
|
-
# spec.add_dependency 'capybara'
|
30
|
-
# spec.add_dependency 'poltergeist'
|
31
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wx_ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- flowerwrong
|
@@ -93,9 +93,11 @@ files:
|
|
93
93
|
- README.md
|
94
94
|
- Rakefile
|
95
95
|
- lib/wx_ext.rb
|
96
|
+
- lib/wx_ext/sougou_weixin.rb
|
96
97
|
- lib/wx_ext/version.rb
|
97
98
|
- spec/spec_helper.rb
|
98
99
|
- spec/test.png
|
100
|
+
- spec/wx_ext/sougou_weixin_spec.rb
|
99
101
|
- spec/wx_ext/weixin_spec.rb
|
100
102
|
- wx_ext.gemspec
|
101
103
|
homepage: http://thecampus.cc
|
@@ -125,4 +127,5 @@ summary: a gem to hack mp.weixin.qq.com
|
|
125
127
|
test_files:
|
126
128
|
- spec/spec_helper.rb
|
127
129
|
- spec/test.png
|
130
|
+
- spec/wx_ext/sougou_weixin_spec.rb
|
128
131
|
- spec/wx_ext/weixin_spec.rb
|