gree-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/Gemfile +1 -0
- data/gree-community.gemspec +13 -0
- data/lib/gree-community.rb +108 -0
- metadata +48 -0
data/Gemfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
gemspec
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Gem::Specification.new do |gem|
|
2
|
+
gem.name = "gree-community"
|
3
|
+
gem.version = "0.0.1"
|
4
|
+
gem.authors = ["todesking"]
|
5
|
+
gem.email = ["discommunicative@gmail.com"]
|
6
|
+
gem.summary = %q{Access to GREE community.}
|
7
|
+
gem.homepage = "https://github.com/todesking/gree-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
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# -*- coding:utf-8 -*-
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'mechanize'
|
5
|
+
|
6
|
+
module GREE
|
7
|
+
class Community
|
8
|
+
def initialize id
|
9
|
+
@id=id
|
10
|
+
end
|
11
|
+
attr_reader :id
|
12
|
+
attr_reader :recent_threads
|
13
|
+
def recent_threads_uri
|
14
|
+
URI.parse(
|
15
|
+
"http://gree.jp/?mode=community&act=bbs_list&community_id=#{id}"
|
16
|
+
)
|
17
|
+
end
|
18
|
+
def fetch(fetcher)
|
19
|
+
page=fetcher.get(recent_threads_uri)
|
20
|
+
@recent_threads=page.search('.feed .item').map{|item|
|
21
|
+
thread_uri = item.at('.head a').attr(:href)
|
22
|
+
thread_uri =~ /&thread_id=(\d+)/
|
23
|
+
thread_id = Integer($1)
|
24
|
+
thread_title = item.at('.head a strong').text
|
25
|
+
Thread.new(
|
26
|
+
thread_id,
|
27
|
+
title: thread_title,
|
28
|
+
)
|
29
|
+
}
|
30
|
+
end
|
31
|
+
class Thread
|
32
|
+
def initialize(id,values={})
|
33
|
+
@id=id
|
34
|
+
@recent_comments=values[:recent_comments]
|
35
|
+
@title=values[:title]
|
36
|
+
end
|
37
|
+
attr_reader :id
|
38
|
+
attr_reader :recent_comments
|
39
|
+
attr_reader :title
|
40
|
+
def uri
|
41
|
+
URI.parse(
|
42
|
+
"http://gree.jp/?mode=community&act=bbs_view&thread_id=#{self.id}"
|
43
|
+
)
|
44
|
+
end
|
45
|
+
def fetch(fetcher)
|
46
|
+
page=fetcher.get(self.uri)
|
47
|
+
@title = page.at('.title').text
|
48
|
+
@recent_comments = page.search('.comment-list li').map{|comment|
|
49
|
+
id = Integer(comment.attr(:id))
|
50
|
+
body = comment.
|
51
|
+
at('.item').
|
52
|
+
children[3..-1]
|
53
|
+
Comment.new(
|
54
|
+
id,
|
55
|
+
user_name: comment.at('.item strong').text,
|
56
|
+
body_text: body.map{|elm| elm.name == 'br' ? "\n" : elm.text }.join('').gsub(//,''),
|
57
|
+
time: Time.strptime(comment.at('.shoulder .timestamp').text, '%m/%d %H:%M'),
|
58
|
+
)
|
59
|
+
}
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
class Comment
|
63
|
+
def initialize(id, values={})
|
64
|
+
@id=id
|
65
|
+
@body_text = values[:body_text]
|
66
|
+
@user_name = values[:user_name]
|
67
|
+
@time = values[:time]
|
68
|
+
end
|
69
|
+
attr_reader :id
|
70
|
+
attr_reader :user_name
|
71
|
+
attr_reader :body_text
|
72
|
+
attr_reader :time
|
73
|
+
end
|
74
|
+
end
|
75
|
+
class Fetcher
|
76
|
+
USER_AGENT = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1'
|
77
|
+
def initialize user_id, password
|
78
|
+
@user_id = user_id
|
79
|
+
@password = password
|
80
|
+
@agent = Mechanize.new
|
81
|
+
@agent.user_agent = USER_AGENT
|
82
|
+
end
|
83
|
+
def get(uri)
|
84
|
+
raise "invalid arg" unless uri.host == 'gree.jp'
|
85
|
+
page_encoding = 'EUC-JP-MS'
|
86
|
+
|
87
|
+
page = @agent.get(uri)
|
88
|
+
page.encoding = page_encoding
|
89
|
+
unless page.uri == uri
|
90
|
+
login_form = page.form_with(name: 'login')
|
91
|
+
raise "Login form not found: uri=#{uri} redirected=#{page.uri}" unless login_form
|
92
|
+
|
93
|
+
login_uri = page.uri
|
94
|
+
|
95
|
+
login_form.user_mail = @user_id
|
96
|
+
login_form.user_password = @password
|
97
|
+
login_form.submit
|
98
|
+
|
99
|
+
page = @agent.page
|
100
|
+
page.encoding = page_encoding
|
101
|
+
|
102
|
+
raise "Login failed or something: uri=#{uri} login=#{login_uri} last=#{page.uri}" unless page.uri == uri
|
103
|
+
end
|
104
|
+
page
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gree-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-12 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description:
|
15
|
+
email:
|
16
|
+
- discommunicative@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- Gemfile
|
22
|
+
- gree-community.gemspec
|
23
|
+
- lib/gree-community.rb
|
24
|
+
homepage: https://github.com/todesking/gree-community
|
25
|
+
licenses: []
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 1.8.24
|
45
|
+
signing_key:
|
46
|
+
specification_version: 3
|
47
|
+
summary: Access to GREE community.
|
48
|
+
test_files: []
|