leadhypebot 1.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.
- checksums.yaml +7 -0
- data/lib/leadhypebot.rb +179 -0
- metadata +163 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aa7538c1de3c1336b53fa69ae0a3c4e679cb0ac60745337292da940de5b860b5
|
4
|
+
data.tar.gz: e9fcd2b752c01bbf716b9fd8fb5afaf12d17bfdbe2d4f17ccd12ccda8cd7769d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0d169bb8362e523c078544b442d9710c4523c1aba3148f2e961534cc8f58e37c1607bef629d1d83ffb06448cc7ce2849c6c4bd44a8954d9651a26239eebd5d50
|
7
|
+
data.tar.gz: f16b633b8bd46c87717ce3cbdeab31eeff6321ff50d2799acc23ec2699dcdcdad22559c6d0ddd8516c40dc3a0a328352da6eb9b8021d1659bfe20ea2294125fe
|
data/lib/leadhypebot.rb
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
require 'blackstack-core'
|
2
|
+
require 'blackstack-deployer'
|
3
|
+
require 'simple_command_line_parser'
|
4
|
+
require 'simple_cloud_logging'
|
5
|
+
require 'mechanize'
|
6
|
+
require 'colorize'
|
7
|
+
require 'pry'
|
8
|
+
|
9
|
+
module BlackStack
|
10
|
+
module Bots
|
11
|
+
class LeadHype
|
12
|
+
attr_accessor :email, :password, :agent
|
13
|
+
|
14
|
+
NINJA_SALES_NAVIGATOR = "Sales Navigator"
|
15
|
+
|
16
|
+
STATUS_ALL = 'All'
|
17
|
+
STATUS_COMPLETED = 'Completed'
|
18
|
+
STATUS_RUNNING = 'Running'
|
19
|
+
STATUS_ERROR = 'Error'
|
20
|
+
STATUS_PENDING = 'Pending'
|
21
|
+
|
22
|
+
# constructor
|
23
|
+
def initialize(init_email, init_password)
|
24
|
+
self.email = init_email
|
25
|
+
self.password = init_password
|
26
|
+
self.agent = Mechanize.new
|
27
|
+
end
|
28
|
+
|
29
|
+
# login to LeadHype.
|
30
|
+
# this method is for internal use only. End users should not call this method.
|
31
|
+
def login(l=nil)
|
32
|
+
l = BlackStack::DummyLogger.new(nil) if l.nil?
|
33
|
+
|
34
|
+
# visit LeadHype login page
|
35
|
+
l.logs "visiting LeadHype login page... "
|
36
|
+
page = self.agent.get('https://tool.leadhype.com')
|
37
|
+
l.done
|
38
|
+
|
39
|
+
# get the form with id='login_form'
|
40
|
+
l.logs "getting login form... "
|
41
|
+
form = page.form_with(:id => 'login_form')
|
42
|
+
l.done
|
43
|
+
|
44
|
+
# getting the text-field with name='email'
|
45
|
+
l.logs "getting email field... "
|
46
|
+
form.field_with(:name => 'email').value = email
|
47
|
+
l.done
|
48
|
+
|
49
|
+
# getting the text-field with name='password'
|
50
|
+
l.logs "getting password field... "
|
51
|
+
form.field_with(:name => 'password').value = password
|
52
|
+
l.done
|
53
|
+
|
54
|
+
# getting the button with name='login'
|
55
|
+
l.logs "getting login button... "
|
56
|
+
button = form.button_with(:name => 'login')
|
57
|
+
l.done
|
58
|
+
|
59
|
+
# click the button
|
60
|
+
l.logs "clicking login button... "
|
61
|
+
page = agent.submit(form, button)
|
62
|
+
l.done
|
63
|
+
|
64
|
+
# getting the pagetitle to check I logged into successfully
|
65
|
+
l.logs "checking login... "
|
66
|
+
title = page.title
|
67
|
+
if title == 'Membership Dashboard'
|
68
|
+
l.logf 'success'.green
|
69
|
+
else
|
70
|
+
l.logf 'failed'.red
|
71
|
+
raise 'login failed'
|
72
|
+
end
|
73
|
+
|
74
|
+
# return the agent
|
75
|
+
#agent
|
76
|
+
end # def login
|
77
|
+
|
78
|
+
# getting SalesNavigator jobs from LeadHype.
|
79
|
+
def sales_navigator_jobs(search=nil, status=nil, page=1, l=nil)
|
80
|
+
ret = []
|
81
|
+
l = BlackStack::DummyLogger.new(nil) if l.nil?
|
82
|
+
url = 'https://tool.leadhype.com/dashboard/history/?'
|
83
|
+
|
84
|
+
# apply filters
|
85
|
+
url += "search=#{CGI.escape(search.to_s)}&"
|
86
|
+
url += "status=#{CGI.escape(status)}&" unless status.nil?
|
87
|
+
#binding.pry
|
88
|
+
# visit LeadHype history page
|
89
|
+
l.logs "visiting LeadHype history page... "
|
90
|
+
page = self.agent.get(url)
|
91
|
+
l.done
|
92
|
+
|
93
|
+
# checking page title
|
94
|
+
l.logs "checking page title... "
|
95
|
+
title = page.title
|
96
|
+
if title == 'Jobs'
|
97
|
+
l.logf 'success'.green
|
98
|
+
else
|
99
|
+
l.logf 'failed'.red
|
100
|
+
raise 'failed to get history page'
|
101
|
+
end
|
102
|
+
|
103
|
+
# getting the first table
|
104
|
+
l.logs "getting first table... "
|
105
|
+
table = page.search('table').first
|
106
|
+
l.done
|
107
|
+
|
108
|
+
# no results = no table
|
109
|
+
return ret if table.nil?
|
110
|
+
|
111
|
+
# getting the rows into the table
|
112
|
+
l.logs "getting rows into the table... "
|
113
|
+
rows = table.search('tr')
|
114
|
+
l.done
|
115
|
+
|
116
|
+
# iterating from the second row (the frist one is the header)
|
117
|
+
i = 1
|
118
|
+
while i < rows.length
|
119
|
+
# getting the row
|
120
|
+
row = rows[i]
|
121
|
+
# getting cells
|
122
|
+
tds = row.search('td')
|
123
|
+
# build the hash descriptor
|
124
|
+
job = {}
|
125
|
+
job[:ninja] = tds[2].text.strip
|
126
|
+
job[:parameter] = tds[3].text.strip
|
127
|
+
job[:status] = tds[5].text.strip
|
128
|
+
job[:id] = tds[6].search('a').first['href']
|
129
|
+
job[:link] = "https://tool.leadhype.com/view/front/controller.php?getResult&id=#{job[:id]}&filename=#{CGI.escape(job[:parameter])}"
|
130
|
+
ret << job if job[:ninja] == NINJA_SALES_NAVIGATOR
|
131
|
+
# hop to the next row
|
132
|
+
i += 1
|
133
|
+
end # while
|
134
|
+
|
135
|
+
# return
|
136
|
+
ret
|
137
|
+
end
|
138
|
+
|
139
|
+
# return array of pending jobs
|
140
|
+
def pending_jobs(page=1, l=nil)
|
141
|
+
self.sales_navigator_jobs(nil, STATUS_PENDING, page, l)
|
142
|
+
end
|
143
|
+
|
144
|
+
# return array of pending jobs
|
145
|
+
def error_jobs(page=1, l=nil)
|
146
|
+
self.sales_navigator_jobs(nil, STATUS_ERROR, page, l)
|
147
|
+
end
|
148
|
+
|
149
|
+
# download the CSV of a given job with the parameter `s` into the file "/tmp/#{s}.csv"
|
150
|
+
def download(s, l=nil)
|
151
|
+
l = BlackStack::DummyLogger.new(nil) if l.nil?
|
152
|
+
|
153
|
+
# jobs
|
154
|
+
jobs = self.sales_navigator_jobs(s, nil, 1, l)
|
155
|
+
|
156
|
+
# validate: must find no more than 1 job
|
157
|
+
raise 'More than 1 job found' if jobs.length > 1
|
158
|
+
|
159
|
+
# validate: must find 1 job
|
160
|
+
raise 'Job not found' if jobs.length == 0
|
161
|
+
|
162
|
+
# download the file
|
163
|
+
l.logs "downloading the file... "
|
164
|
+
page = self.agent.get(jobs[0][:link])
|
165
|
+
l.done
|
166
|
+
|
167
|
+
# save the file
|
168
|
+
l.logs "saving the file... "
|
169
|
+
f = File.open("/tmp/#{s}.csv", 'w')
|
170
|
+
f.write(page.content)
|
171
|
+
f.close
|
172
|
+
l.done
|
173
|
+
end # def download
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
end # class LeadHype
|
178
|
+
end # module Bots
|
179
|
+
end
|
metadata
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: leadhypebot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Leandro Daniel Sardi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-05-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: blackstack-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.2.3
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.2.3
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.2.3
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.2.3
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: simple_command_line_parser
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 1.1.2
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.1.2
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 1.1.2
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.1.2
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: simple_cloud_logging
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 1.2.2
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 1.2.2
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.2.2
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 1.2.2
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: mechanize
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - "~>"
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 2.8.5
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.8.5
|
83
|
+
type: :runtime
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.8.5
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 2.8.5
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: colorize
|
95
|
+
requirement: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - "~>"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: 0.8.1
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 0.8.1
|
103
|
+
type: :runtime
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 0.8.1
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: 0.8.1
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: pry
|
115
|
+
requirement: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - "~>"
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: 0.14.2
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 0.14.2
|
123
|
+
type: :runtime
|
124
|
+
prerelease: false
|
125
|
+
version_requirements: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - "~>"
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: 0.14.2
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: 0.14.2
|
133
|
+
description: 'Find documentation here: https://github.com/leandrosardi/leadhypebot'
|
134
|
+
email: leandro.sardi@expandedventure.com
|
135
|
+
executables: []
|
136
|
+
extensions: []
|
137
|
+
extra_rdoc_files: []
|
138
|
+
files:
|
139
|
+
- lib/leadhypebot.rb
|
140
|
+
homepage: https://rubygems.org/gems/leadhypebot
|
141
|
+
licenses:
|
142
|
+
- MIT
|
143
|
+
metadata: {}
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
requirements: []
|
159
|
+
rubygems_version: 3.3.7
|
160
|
+
signing_key:
|
161
|
+
specification_version: 4
|
162
|
+
summary: Ruby library for automation operation on the LeadHype Scraper platform.
|
163
|
+
test_files: []
|