fbcrawl-colly 0.2.3 → 1.1.0

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.
@@ -0,0 +1,5 @@
1
+ require 'fbcrawl_services_pb'
2
+ require 'fbcrawl_colly/client'
3
+ module FbCrawlColly
4
+
5
+ end
@@ -0,0 +1,50 @@
1
+ module FbcrawlColly
2
+ class Client
3
+
4
+ def initialize(host_and_port)
5
+ @host_and_port = host_and_port
6
+ @client = new_grpc_client
7
+ @context = nil
8
+ end
9
+
10
+ def login(email, password, totp_secret = "")
11
+ cookies = @client.login(FbcrawlColly::LoginRequest.new(email: email, password: password, totp_secret: totp_secret)).cookies
12
+ @context = FbcrawlColly::Context.new(cookies: cookies)
13
+ cookies
14
+ end
15
+
16
+ def login_with_cookies(cookies)
17
+ @context = FbcrawlColly::Context.new(cookies: cookies)
18
+ end
19
+
20
+ def fetch_user_info(username)
21
+ s = @client.fetch_user_info(FbcrawlColly::FetchUserInfoRequest.new(context: @context, username: username))
22
+ end
23
+
24
+ def fetch_group_info(group_id_or_username)
25
+ s = @client.fetch_group_info(FbcrawlColly::FetchGroupInfoRequest.new(context: @context, group_username: group_id_or_username))
26
+ end
27
+
28
+ def fetch_group_feed(group_id, next_cursor = nil)
29
+ s = @client.fetch_group_feed(FbcrawlColly::FetchGroupFeedRequest.new(context: @context, group_id: group_id, next_cursor: next_cursor))
30
+ end
31
+
32
+ def fetch_post(group_id, post_id, comment_next_cursor = nil)
33
+ s = @client.fetch_post(FbcrawlColly::FetchPostRequest.new(context: @context, group_id: group_id, post_id: post_id, comment_next_cursor: comment_next_cursor))
34
+ end
35
+
36
+ def fetch_content_images(post_id, next_cursor = nil)
37
+ s = @client.fetch_content_images(FbcrawlColly::FetchContentImagesRequest.new(context: @context, post_id: post_id, next_cursor: next_cursor))
38
+ end
39
+
40
+ def fetch_image_url(image_id)
41
+ s = @client.fetch_image_url(FbcrawlColly::FetchImageUrlRequest.new(context: @context, image_id: image_id))
42
+ end
43
+
44
+ private
45
+
46
+ def new_grpc_client
47
+ FbcrawlColly::Grpc::Stub.new(@host_and_port, :this_channel_is_insecure)
48
+ end
49
+ end
50
+ end
@@ -1,3 +1,3 @@
1
1
  module FbcrawlColly
2
- VERSION = "0.2.3"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -0,0 +1,122 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: fbcrawl.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_file("fbcrawl.proto", :syntax => :proto3) do
8
+ add_message "fbcrawl_colly.Empty" do
9
+ end
10
+ add_message "fbcrawl_colly.Context" do
11
+ optional :cookies, :string, 1
12
+ end
13
+ add_message "fbcrawl_colly.LoginRequest" do
14
+ optional :email, :string, 2
15
+ optional :password, :string, 3
16
+ optional :totp_secret, :string, 4
17
+ end
18
+ add_message "fbcrawl_colly.LoginResponse" do
19
+ optional :cookies, :string, 1
20
+ end
21
+ add_message "fbcrawl_colly.LoginWithCookiesRequest" do
22
+ optional :cookies, :string, 1
23
+ end
24
+ add_message "fbcrawl_colly.FetchGroupInfoRequest" do
25
+ optional :context, :message, 1, "fbcrawl_colly.Context"
26
+ optional :group_username, :string, 2
27
+ end
28
+ add_message "fbcrawl_colly.FetchUserInfoRequest" do
29
+ optional :context, :message, 1, "fbcrawl_colly.Context"
30
+ optional :username, :string, 2
31
+ end
32
+ add_message "fbcrawl_colly.FetchGroupFeedRequest" do
33
+ optional :context, :message, 1, "fbcrawl_colly.Context"
34
+ optional :group_id, :int64, 2
35
+ optional :next_cursor, :string, 3
36
+ end
37
+ add_message "fbcrawl_colly.FetchPostRequest" do
38
+ optional :context, :message, 1, "fbcrawl_colly.Context"
39
+ optional :group_id, :int64, 2
40
+ optional :post_id, :int64, 3
41
+ optional :comment_next_cursor, :string, 4
42
+ end
43
+ add_message "fbcrawl_colly.FetchContentImagesRequest" do
44
+ optional :context, :message, 1, "fbcrawl_colly.Context"
45
+ optional :post_id, :int64, 2
46
+ optional :next_cursor, :string, 3
47
+ end
48
+ add_message "fbcrawl_colly.FetchImageUrlRequest" do
49
+ optional :context, :message, 1, "fbcrawl_colly.Context"
50
+ optional :image_id, :int64, 2
51
+ end
52
+ add_message "fbcrawl_colly.FacebookGroup" do
53
+ optional :id, :int64, 1
54
+ optional :name, :string, 2
55
+ optional :member_count, :int64, 3
56
+ end
57
+ add_message "fbcrawl_colly.FacebookUser" do
58
+ optional :id, :int64, 1
59
+ optional :name, :string, 2
60
+ optional :username, :string, 3
61
+ optional :friend_count, :int64, 4
62
+ end
63
+ add_message "fbcrawl_colly.FacebookPost" do
64
+ optional :id, :int64, 1
65
+ optional :group, :message, 2, "fbcrawl_colly.FacebookGroup"
66
+ optional :user, :message, 3, "fbcrawl_colly.FacebookUser"
67
+ optional :content, :string, 4
68
+ optional :comments, :message, 5, "fbcrawl_colly.CommentList"
69
+ optional :content_link, :string, 6
70
+ repeated :content_images, :message, 7, "fbcrawl_colly.FacebookImage"
71
+ optional :content_image, :message, 8, "fbcrawl_colly.FacebookImage"
72
+ optional :created_at, :int64, 9
73
+ optional :reaction_count, :int64, 10
74
+ optional :comment_count, :int64, 11
75
+ end
76
+ add_message "fbcrawl_colly.CommentList" do
77
+ repeated :comments, :message, 5, "fbcrawl_colly.FacebookComment"
78
+ optional :next_cursor, :string, 12
79
+ end
80
+ add_message "fbcrawl_colly.FacebookImage" do
81
+ optional :id, :int64, 1
82
+ optional :url, :string, 2
83
+ end
84
+ add_message "fbcrawl_colly.FacebookComment" do
85
+ optional :id, :int64, 1
86
+ optional :post, :message, 2, "fbcrawl_colly.FacebookPost"
87
+ optional :user, :message, 3, "fbcrawl_colly.FacebookUser"
88
+ optional :content, :string, 4
89
+ optional :created_at, :int64, 5
90
+ end
91
+ add_message "fbcrawl_colly.FacebookPostList" do
92
+ repeated :posts, :message, 1, "fbcrawl_colly.FacebookPost"
93
+ optional :next_cursor, :string, 2
94
+ end
95
+ add_message "fbcrawl_colly.FacebookImageList" do
96
+ repeated :images, :message, 1, "fbcrawl_colly.FacebookImage"
97
+ optional :next_cursor, :string, 2
98
+ end
99
+ end
100
+ end
101
+
102
+ module FbcrawlColly
103
+ Empty = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("fbcrawl_colly.Empty").msgclass
104
+ Context = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("fbcrawl_colly.Context").msgclass
105
+ LoginRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("fbcrawl_colly.LoginRequest").msgclass
106
+ LoginResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("fbcrawl_colly.LoginResponse").msgclass
107
+ LoginWithCookiesRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("fbcrawl_colly.LoginWithCookiesRequest").msgclass
108
+ FetchGroupInfoRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("fbcrawl_colly.FetchGroupInfoRequest").msgclass
109
+ FetchUserInfoRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("fbcrawl_colly.FetchUserInfoRequest").msgclass
110
+ FetchGroupFeedRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("fbcrawl_colly.FetchGroupFeedRequest").msgclass
111
+ FetchPostRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("fbcrawl_colly.FetchPostRequest").msgclass
112
+ FetchContentImagesRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("fbcrawl_colly.FetchContentImagesRequest").msgclass
113
+ FetchImageUrlRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("fbcrawl_colly.FetchImageUrlRequest").msgclass
114
+ FacebookGroup = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("fbcrawl_colly.FacebookGroup").msgclass
115
+ FacebookUser = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("fbcrawl_colly.FacebookUser").msgclass
116
+ FacebookPost = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("fbcrawl_colly.FacebookPost").msgclass
117
+ CommentList = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("fbcrawl_colly.CommentList").msgclass
118
+ FacebookImage = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("fbcrawl_colly.FacebookImage").msgclass
119
+ FacebookComment = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("fbcrawl_colly.FacebookComment").msgclass
120
+ FacebookPostList = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("fbcrawl_colly.FacebookPostList").msgclass
121
+ FacebookImageList = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("fbcrawl_colly.FacebookImageList").msgclass
122
+ end
@@ -0,0 +1,29 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # Source: fbcrawl.proto for package 'fbcrawl_colly'
3
+
4
+ require 'grpc'
5
+ require 'fbcrawl_pb'
6
+
7
+ module FbcrawlColly
8
+ module Grpc
9
+ class Service
10
+
11
+ include GRPC::GenericService
12
+
13
+ self.marshal_class_method = :encode
14
+ self.unmarshal_class_method = :decode
15
+ self.service_name = 'fbcrawl_colly.Grpc'
16
+
17
+ # Sends a greeting
18
+ rpc :Login, FbcrawlColly::LoginRequest, FbcrawlColly::LoginResponse
19
+ rpc :FetchGroupInfo, FbcrawlColly::FetchGroupInfoRequest, FbcrawlColly::FacebookGroup
20
+ rpc :FetchUserInfo, FbcrawlColly::FetchUserInfoRequest, FbcrawlColly::FacebookUser
21
+ rpc :FetchGroupFeed, FbcrawlColly::FetchGroupFeedRequest, FbcrawlColly::FacebookPostList
22
+ rpc :FetchPost, FbcrawlColly::FetchPostRequest, FbcrawlColly::FacebookPost
23
+ rpc :FetchContentImages, FbcrawlColly::FetchContentImagesRequest, FbcrawlColly::FacebookImageList
24
+ rpc :FetchImageUrl, FbcrawlColly::FetchImageUrlRequest, FbcrawlColly::FacebookImage
25
+ end
26
+
27
+ Stub = Service.rpc_stub_class
28
+ end
29
+ end
data/main.go CHANGED
@@ -1,22 +1,17 @@
1
1
  package main
2
2
 
3
- /*
4
- #include <stdio.h>
5
- #include <stdlib.h>
6
-
7
- static void myprint(char* s) {
8
- printf("%s\n", s);
9
- }
10
-
11
-
12
- */
13
3
  import "C"
14
-
15
4
  import (
5
+ context "context"
16
6
  "flag"
17
- "github.com/golang/protobuf/proto"
18
- "qnetwork.net/fbcrawl/fbcolly"
19
- "unsafe"
7
+ "github.com/google/logger"
8
+ "google.golang.org/grpc"
9
+ "io/ioutil"
10
+ "log"
11
+ "net"
12
+ "os"
13
+ "qnetwork.net/fbcrawl/fbcrawl"
14
+ "qnetwork.net/fbcrawl/fbcrawl/pb"
20
15
  )
21
16
 
22
17
  const logPath = "parse.log"
@@ -27,84 +22,81 @@ var password = flag.String("password", "change_me", "facebook password")
27
22
  var otp = flag.String("otp", "123456", "facebook otp")
28
23
  var groupId = flag.String("groupId", "334294967318328", "facebook group id, default is 334294967318328")
29
24
 
30
- var allInstances = map[uintptr]*fbcolly.Fbcolly{}
31
-
32
- //export Init
33
- func Init() uintptr {
25
+ func getColly(context *pb.Context) *fbcolly.Fbcolly {
34
26
  instance := fbcolly.New()
35
- ptr := (uintptr)(unsafe.Pointer(instance))
36
- allInstances[ptr] = instance
37
- return ptr
27
+ if context != nil && len(context.Cookies) > 0 {
28
+ _ = instance.LoginWithCookies(context.Cookies)
29
+ }
30
+
31
+ return instance
38
32
  }
39
33
 
40
- //export FreeColly
41
- func FreeColly(pointer unsafe.Pointer) {
42
- delete(allInstances, uintptr(pointer))
34
+ // server is used to implement helloworld.GreeterServer.
35
+ type server struct {
36
+ pb.GrpcServer
43
37
  }
44
38
 
45
- //export Login
46
- func Login(pointer unsafe.Pointer, email *C.char, password *C.char) *C.char {
47
- p := (*fbcolly.Fbcolly)(pointer)
48
- cookies, err := p.Login(C.GoString(email), C.GoString(password), "")
39
+ func (s server) Login(ctx context.Context, request *pb.LoginRequest) (*pb.LoginResponse, error) {
40
+ p := getColly(nil)
41
+
42
+ cookies, err := p.Login(request.Email, request.Password, request.TotpSecret)
49
43
  if err == nil {
50
- return C.CString(cookies)
44
+ return &pb.LoginResponse{Cookies: cookies}, err
51
45
  }
52
- return nil
46
+ return nil, err
47
+ }
48
+
49
+ func (s server) FetchGroupInfo(ctx context.Context, request *pb.FetchGroupInfoRequest) (*pb.FacebookGroup, error) {
50
+ p := getColly(request.Context)
51
+ err, groupInfo := p.FetchGroupInfo(request.GroupUsername)
52
+ return groupInfo, err
53
53
  }
54
54
 
55
- //export LoginWithCookies
56
- func LoginWithCookies(pointer unsafe.Pointer, cookies *C.char) {
57
- p := (*fbcolly.Fbcolly)(pointer)
58
- p.LoginWithCookies(C.GoString(cookies))
55
+ func (s server) FetchUserInfo(ctx context.Context, request *pb.FetchUserInfoRequest) (*pb.FacebookUser, error) {
56
+ p := getColly(request.Context)
57
+ err, userInfo := p.FetchUserInfo(request.Username)
58
+ return userInfo, err
59
59
  }
60
60
 
61
- //export FetchGroupFeed
62
- func FetchGroupFeed(pointer unsafe.Pointer, groupId int64) unsafe.Pointer {
63
- p := (*fbcolly.Fbcolly)(pointer)
64
- _, postsList := p.FetchGroupFeed(groupId)
65
- marshaledPostsList, _ := proto.Marshal(postsList)
66
- return C.CBytes(append(marshaledPostsList, 0))
61
+ func (s server) FetchGroupFeed(ctx context.Context, request *pb.FetchGroupFeedRequest) (*pb.FacebookPostList, error) {
62
+ p := getColly(request.Context)
63
+ err, postsList := p.FetchGroupFeed(request.GroupId, request.NextCursor)
64
+ return postsList, err
67
65
  }
68
66
 
69
- //export FetchPost
70
- func FetchPost(pointer unsafe.Pointer, groupId int64, postId int64) unsafe.Pointer {
71
- p := (*fbcolly.Fbcolly)(pointer)
72
- _, post := p.FetchPost(groupId, postId)
73
- marshaledPost, _ := proto.Marshal(post)
74
- return C.CBytes(append(marshaledPost, 0))
67
+ func (s server) FetchPost(ctx context.Context, request *pb.FetchPostRequest) (*pb.FacebookPost, error) {
68
+ p := getColly(request.Context)
69
+ err, post := p.FetchPost(request.GroupId, request.PostId, request.CommentNextCursor)
70
+ return post, err
75
71
  }
76
72
 
77
- //export FetchContentImages
78
- func FetchContentImages(pointer unsafe.Pointer, postId int64) unsafe.Pointer {
79
- p := (*fbcolly.Fbcolly)(pointer)
80
- _, imageList := p.FetchContentImages(postId)
81
- marshaled, _ := proto.Marshal(imageList)
82
- return C.CBytes(append(marshaled, 0))
73
+ func (s server) FetchContentImages(ctx context.Context, request *pb.FetchContentImagesRequest) (*pb.FacebookImageList, error) {
74
+ p := getColly(request.Context)
75
+ err, imageList := p.FetchContentImages(request.PostId, request.NextCursor)
76
+ return imageList, err
83
77
  }
84
78
 
85
- //export FetchImageUrl
86
- func FetchImageUrl(pointer unsafe.Pointer, imageId int64) unsafe.Pointer {
87
- p := (*fbcolly.Fbcolly)(pointer)
88
- _, image := p.FetchImageUrl(imageId)
89
- marshaled, _ := proto.Marshal(image)
90
- return C.CBytes(append(marshaled, 0))
79
+ func (s server) FetchImageUrl(ctx context.Context, request *pb.FetchImageUrlRequest) (*pb.FacebookImage, error) {
80
+ p := getColly(request.Context)
81
+ err, image := p.FetchImageUrl(request.ImageId)
82
+ return image, err
91
83
  }
92
84
 
93
85
  func main() {
94
- //r := regexp.MustCompile("/([\\d\\w.]+)").FindStringSubmatch()[1]
95
- //print(r.FindStringSubmatch("/liem.phamthanh.161?refid=18&__tn__=R")[1])
96
- //flag.Parse()
97
- //
98
- ////post := fbcrawl.FacebookPost{}
99
- ////bPost, err := proto.Marshal(&post)
100
- //
101
- //lf, err := os.OpenFile(logPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0660)
102
- //if err != nil {
103
- // logger.Fatalf("Failed to open log file: %v", err)
104
- //}
105
- //defer lf.Close()
106
- //defer logger.Init("fb-colly", *verbose, false, lf).Close()
107
- //f := fbcolly.New()
108
- //err = f.Login(*email, *password, *otp)
109
- //f.FetchGroupFeed(*groupId)
86
+ logger.Init("fb-colly", true, false, ioutil.Discard)
87
+
88
+ port := os.Getenv("PORT")
89
+ if len(port) == 0 {
90
+ port = "50051"
91
+ }
92
+ lis, err := net.Listen("tcp", ":"+port)
93
+ logger.Info("Port listened at", port)
94
+ if err != nil {
95
+ log.Fatalf("failed to listen: %v", err)
96
+ }
97
+ s := grpc.NewServer()
98
+ pb.RegisterGrpcServer(s, &server{})
99
+ if err := s.Serve(lis); err != nil {
100
+ log.Fatalf("failed to serve: %v", err)
101
+ }
110
102
  }
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fbcrawl-colly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Duy Le
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-14 00:00:00.000000000 Z
11
+ date: 2020-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: ffi
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: google-protobuf
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -39,13 +25,13 @@ dependencies:
39
25
  - !ruby/object:Gem::Version
40
26
  version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
- name: rake-compiler
28
+ name: grpc
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - ">="
46
32
  - !ruby/object:Gem::Version
47
33
  version: '0'
48
- type: :development
34
+ type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
@@ -56,12 +42,12 @@ description: Crawl mbasic.facebook.com using GO Colly
56
42
  email:
57
43
  - duyleekun@gmail.com
58
44
  executables: []
59
- extensions:
60
- - ext/fbcrawl_colly/extconf.rb
45
+ extensions: []
61
46
  extra_rdoc_files: []
62
47
  files:
63
48
  - ".gitignore"
64
49
  - CODE_OF_CONDUCT.md
50
+ - Dockerfile
65
51
  - Gemfile
66
52
  - Gemfile.lock
67
53
  - LICENSE.txt
@@ -69,18 +55,19 @@ files:
69
55
  - Rakefile
70
56
  - bin/console
71
57
  - bin/setup
72
- - ext/fbcrawl_colly/.gitignore
73
- - ext/fbcrawl_colly/Makefile
74
- - ext/fbcrawl_colly/extconf.rb
75
- - fbcolly/fbcolly.go
76
58
  - fbcrawl-colly.gemspec
77
59
  - fbcrawl.proto
60
+ - fbcrawl/fbcolly.go
61
+ - fbcrawl/pb/fbcrawl.pb.go
62
+ - fbcrawl/pb/fbcrawl_grpc.pb.go
78
63
  - go.mod
79
64
  - go.sum
80
65
  - lib/fbcrawl-colly.rb
81
- - lib/fbcrawl_colly/colly.rb
82
- - lib/fbcrawl_colly/ffi.rb
66
+ - lib/fbcrawl_colly.rb
67
+ - lib/fbcrawl_colly/client.rb
83
68
  - lib/fbcrawl_colly/version.rb
69
+ - lib/pb/fbcrawl_pb.rb
70
+ - lib/pb/fbcrawl_services_pb.rb
84
71
  - main.go
85
72
  homepage: http://github.com/duyleekun/fbcrawl-colly
86
73
  licenses:
@@ -93,6 +80,7 @@ post_install_message:
93
80
  rdoc_options: []
94
81
  require_paths:
95
82
  - lib
83
+ - lib/pb
96
84
  required_ruby_version: !ruby/object:Gem::Requirement
97
85
  requirements:
98
86
  - - ">="