mixi-community 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/Gemfile +1 -0
- data/lib/mixi-community.rb +119 -0
- data/mixi-community.gemspec +15 -0
- metadata +66 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Gemfile.lock
|
data/Gemfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
gemspec
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# -*- coding:utf-8 -*-
|
2
|
+
require 'mechanize'
|
3
|
+
|
4
|
+
module Mixi
|
5
|
+
class Community
|
6
|
+
def initialize(id)
|
7
|
+
@id = id
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :id
|
11
|
+
attr_reader :title
|
12
|
+
|
13
|
+
def uri
|
14
|
+
URI.parse("http://mixi.jp/view_community.pl?id=#{id}")
|
15
|
+
end
|
16
|
+
|
17
|
+
def fetch(fetcher)
|
18
|
+
page = fetcher.get(uri)
|
19
|
+
@recent_bbses = page.search('#newCommunityTopic .contents dl dd a').map {|a|
|
20
|
+
bbs_uri = URI.parse(a.attr(:href))
|
21
|
+
bbs_title = a.text
|
22
|
+
bbs_id = Hash[bbs_uri.query.split('&').map{|kv|kv.split('=')}]['id']
|
23
|
+
|
24
|
+
BBS.new(self.id, bbs_id, title: bbs_title)
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def recent_bbses
|
29
|
+
@recent_bbses
|
30
|
+
end
|
31
|
+
|
32
|
+
class BBS
|
33
|
+
def initialize(community_id, id, params)
|
34
|
+
@community_id = community_id
|
35
|
+
@id = id
|
36
|
+
@title = params[:title]
|
37
|
+
end
|
38
|
+
|
39
|
+
attr_reader :community_id
|
40
|
+
attr_reader :id
|
41
|
+
attr_reader :title
|
42
|
+
|
43
|
+
attr_reader :recent_comments
|
44
|
+
|
45
|
+
def uri
|
46
|
+
URI.parse("http://mixi.jp/view_bbs.pl?id=#{id}&comm_id=#{community_id}")
|
47
|
+
end
|
48
|
+
|
49
|
+
def fetch(fetcher)
|
50
|
+
page = fetcher.get(uri)
|
51
|
+
@title = page.at('.bbsTitle .title').text
|
52
|
+
@recent_comments = page.at('#bbsComment').at('dl.commentList01').children.select{|e|%w(dt dd).include? e.name}.each_slice(2).map {|dt,dd|
|
53
|
+
puts dt.at('a').attr(:href)
|
54
|
+
user_uri = URI.parse(dd.at('dl.commentContent01 dt a').attr(:href))
|
55
|
+
user_id = Hash[user_uri.query.split('&').map{|kv|kv.split('=')}]['content_id']
|
56
|
+
user_name = dd.at('dl.commentContent01 dt a').text
|
57
|
+
body_text = dd.at('dl.commentContent01 dd').text.strip.gsub(/\n\n返信$/, '').gsub(/\r/,"\n")
|
58
|
+
comment_id = dt.at('.senderId a').attr(:name).gsub(/^comment_id_(\d+)$/, '\1')
|
59
|
+
comment_num = dt.at('.senderId a').text.gsub(/^\[(\d+)\]$/, '\1')
|
60
|
+
time = Time.strptime(dt.at('.date').text, '%Y年%m月%d日 %H:%M')
|
61
|
+
|
62
|
+
Comment.new(
|
63
|
+
comment_id,
|
64
|
+
user_id: user_id,
|
65
|
+
user_name: user_name,
|
66
|
+
body_text: body_text,
|
67
|
+
num: comment_num,
|
68
|
+
time: time,
|
69
|
+
)
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
class Comment
|
74
|
+
def initialize(id, params)
|
75
|
+
@id = id
|
76
|
+
@user_id = params[:user_id]
|
77
|
+
@user_name = params[:user_name]
|
78
|
+
@body_text = params[:body_text]
|
79
|
+
@num = params[:num]
|
80
|
+
@time = params[:time]
|
81
|
+
end
|
82
|
+
attr_reader :id
|
83
|
+
attr_reader :user_id
|
84
|
+
attr_reader :user_name
|
85
|
+
attr_reader :body_text
|
86
|
+
attr_reader :time
|
87
|
+
attr_reader :num
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
class Fetcher
|
92
|
+
DEFAULT_USER_AGENT = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1'
|
93
|
+
def initialize user_id, password, user_agent = DEFAULT_USER_AGENT
|
94
|
+
@user_id = user_id
|
95
|
+
@password = password
|
96
|
+
@agent = Mechanize.new
|
97
|
+
@agent.user_agent = user_agent
|
98
|
+
@agent.follow_meta_refresh = true
|
99
|
+
end
|
100
|
+
def get(uri)
|
101
|
+
raise "invalid arg" unless uri.host == 'mixi.jp'
|
102
|
+
page_encoding = 'euc-jp'
|
103
|
+
|
104
|
+
page = @agent.get(uri)
|
105
|
+
page.encoding = page_encoding
|
106
|
+
login_form = page.form_with(name: 'login_form')
|
107
|
+
if login_form
|
108
|
+
login_form.email = @user_id
|
109
|
+
login_form.password = @password
|
110
|
+
login_form.submit
|
111
|
+
|
112
|
+
page = @agent.page
|
113
|
+
page.encoding = page_encoding
|
114
|
+
end
|
115
|
+
page
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Gem::Specification.new do |gem|
|
2
|
+
gem.name = "mixi-community"
|
3
|
+
gem.version = "0.0.1"
|
4
|
+
gem.authors = ["todesking"]
|
5
|
+
gem.email = ["discommunicative@gmail.com"]
|
6
|
+
gem.summary = %q{Access to Mixi community.}
|
7
|
+
gem.homepage = "https://github.com/todesking/mixi-community"
|
8
|
+
|
9
|
+
gem.files = `git ls-files`.split($\)
|
10
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
11
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
12
|
+
gem.require_paths = ["lib"]
|
13
|
+
|
14
|
+
gem.add_runtime_dependency 'mechanize'
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mixi-community
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- todesking
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: mechanize
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description:
|
31
|
+
email:
|
32
|
+
- discommunicative@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- lib/mixi-community.rb
|
40
|
+
- mixi-community.gemspec
|
41
|
+
homepage: https://github.com/todesking/mixi-community
|
42
|
+
licenses: []
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.8.24
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: Access to Mixi community.
|
65
|
+
test_files: []
|
66
|
+
has_rdoc:
|