secondHandler 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +9 -0
- data/LICENSE +21 -0
- data/README.md +9 -0
- data/Rakefile +10 -0
- data/bin/second_handler +83 -0
- data/lib/second_handler.rb +51 -0
- data/lib/second_handler/version.rb +4 -0
- data/secondhandler.gemspec +20 -0
- data/spec/second_handler_spec.rb +6 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: aa557d8ac82cab551490e67dce3783c3b06c61c2
|
4
|
+
data.tar.gz: e99a38ee0883b0c79801966b70fe72f58b0de951
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f2f46d0c7a0295d5086cca62927045ec3e93582d0d2aca0ad8b71073252026b56a07db18e279097f47327cdd08e38000e63b598dc252230b2f1d80ae1e60f00d
|
7
|
+
data.tar.gz: fd3abf3fb98bcd071f78a6692d1ebfe10dcab1d5d2853e1deaf05c2d917b407c6e3ed5d3e9ae6705c49a2d76a8129693a0cb9561dfc74771698cdc320a0b3dbe
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Smartibuy
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
data/bin/second_handler
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'commander'
|
4
|
+
require_relative '../lib/second_handler'
|
5
|
+
|
6
|
+
def read_char
|
7
|
+
STDIN.echo = false
|
8
|
+
STDIN.raw!
|
9
|
+
|
10
|
+
input = STDIN.getc.chr
|
11
|
+
if input == "\e" then
|
12
|
+
input << STDIN.read_nonblock(3) rescue nil
|
13
|
+
input << STDIN.read_nonblock(2) rescue nil
|
14
|
+
end
|
15
|
+
ensure
|
16
|
+
STDIN.echo = true
|
17
|
+
STDIN.cooked!
|
18
|
+
|
19
|
+
return input
|
20
|
+
end
|
21
|
+
|
22
|
+
def print_page(page)
|
23
|
+
page.each do |e|
|
24
|
+
returns = ''
|
25
|
+
if e['id']
|
26
|
+
returns << "<ID>\n" << e['id']
|
27
|
+
end
|
28
|
+
|
29
|
+
if e['message']
|
30
|
+
returns << "<Informations>\n" << e['message']
|
31
|
+
end
|
32
|
+
|
33
|
+
if e['updated_time']
|
34
|
+
returns << "<Update Time>\n" << e['updated_time']
|
35
|
+
end
|
36
|
+
|
37
|
+
if e['attachments']
|
38
|
+
returns << "\n\n<Attachments>\n"
|
39
|
+
puts e['attachments']
|
40
|
+
end
|
41
|
+
|
42
|
+
puts returns
|
43
|
+
puts "\n\n===================================="
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
Commander.configure do
|
48
|
+
program :name, 'SecondHandler'
|
49
|
+
program :version, '0.0.1'
|
50
|
+
program :description, 'A retriever of second hand information of Facebook or Twitter.'
|
51
|
+
|
52
|
+
command :fb do |c|
|
53
|
+
c.syntax = 'second_handler fb --token access_token --id group_id'
|
54
|
+
c.description = 'Show selling information of a Facebook group'
|
55
|
+
c.option '--token access_token', String, 'Access token'
|
56
|
+
c.option '--id group_id', String, 'Group ID'
|
57
|
+
c.action do |args, options|
|
58
|
+
if options.token && options.id
|
59
|
+
fb = SecondHandler::FbGroupPost.new(options.token, options.id)
|
60
|
+
page = fb.first_page
|
61
|
+
print_page(page)
|
62
|
+
cmd = read_char
|
63
|
+
while cmd != "\u0003" do
|
64
|
+
case cmd
|
65
|
+
when "\e[A"
|
66
|
+
puts '== Previous Page =='
|
67
|
+
print_page(fb.previous_page)
|
68
|
+
when "\e[B"
|
69
|
+
puts '== Next Page =='
|
70
|
+
print_page(fb.next_page)
|
71
|
+
end
|
72
|
+
cmd = read_char
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
command :twitter do |c|
|
79
|
+
c.syntax = 'second_handler twitter'
|
80
|
+
c.description = 'Show selling information of twitter'
|
81
|
+
# Implementing.
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'koala'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module SecondHandler
|
5
|
+
class FbGroupPost
|
6
|
+
def initialize (access_token, group_id)
|
7
|
+
@graph = Koala::Facebook::API.new(access_token)
|
8
|
+
@group_id = group_id
|
9
|
+
end
|
10
|
+
|
11
|
+
def first_page
|
12
|
+
@feed = @graph.get_connections(@group_id, "feed", :fields => ["attachments{media,subattachments{media}}","id","message","updated_time"])
|
13
|
+
end
|
14
|
+
|
15
|
+
def next_page
|
16
|
+
@feed = @feed.next_page
|
17
|
+
end
|
18
|
+
|
19
|
+
def previous_page
|
20
|
+
@feed = @feed.previous_page
|
21
|
+
end
|
22
|
+
|
23
|
+
# return feed of current page infomation , including image
|
24
|
+
def get_content
|
25
|
+
@feed.map do |item|
|
26
|
+
tmp = Hash.new
|
27
|
+
tmp["id"] = item["id"]
|
28
|
+
tmp["message"] = item["message"]
|
29
|
+
tmp["updated_time"] = item["updated_time"]
|
30
|
+
tmp["attachments"] = attachment_helper(item["attachments"])
|
31
|
+
tmp
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def attachment_helper (attach_hash)
|
39
|
+
ok_data = []
|
40
|
+
if attach_hash && attach_hash["data"].first["media"]
|
41
|
+
ok_data << attach_hash["data"].first["media"]
|
42
|
+
end
|
43
|
+
if attach_hash && attach_hash["data"].first["subattachments"]
|
44
|
+
attach_hash["data"].first["subattachments"].each do |item|
|
45
|
+
ok_data << item
|
46
|
+
end
|
47
|
+
end
|
48
|
+
ok_data
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
2
|
+
require 'second_handler/version'
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'secondHandler'
|
5
|
+
s.version = SecondHandler::VERSION
|
6
|
+
s.date = SecondHandler::DATE
|
7
|
+
s.executables << 'second_handler'
|
8
|
+
s.summary = ''
|
9
|
+
s.description = 'SecondHand-ler is a retriever for second-hand information of Twitter and Facebook'
|
10
|
+
s.authors = ['Sheng Jung Wu', 'Calvin Jeng', 'Henry Chang', 'Yi Wei Huang']
|
11
|
+
s.files = `git ls-files`.split("\n")
|
12
|
+
s.test_files = `git ls-files spec/*`.split("\n")
|
13
|
+
s.homepage = 'https://github.com/Smartibuy/SecondHand-ler'
|
14
|
+
s.license = 'MIT'
|
15
|
+
|
16
|
+
# depend gem
|
17
|
+
s.add_development_dependency 'minitest'
|
18
|
+
s.add_runtime_dependency 'koala'
|
19
|
+
s.add_runtime_dependency 'commander'
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: secondHandler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sheng Jung Wu
|
8
|
+
- Calvin Jeng
|
9
|
+
- Henry Chang
|
10
|
+
- Yi Wei Huang
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 2015-10-24 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: minitest
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: koala
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: commander
|
46
|
+
requirement: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
description: SecondHand-ler is a retriever for second-hand information of Twitter
|
59
|
+
and Facebook
|
60
|
+
email:
|
61
|
+
executables:
|
62
|
+
- second_handler
|
63
|
+
extensions: []
|
64
|
+
extra_rdoc_files: []
|
65
|
+
files:
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/second_handler
|
71
|
+
- lib/second_handler.rb
|
72
|
+
- lib/second_handler/version.rb
|
73
|
+
- secondhandler.gemspec
|
74
|
+
- spec/second_handler_spec.rb
|
75
|
+
homepage: https://github.com/Smartibuy/SecondHand-ler
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.4.5.1
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: ''
|
99
|
+
test_files:
|
100
|
+
- spec/second_handler_spec.rb
|