bots 1.0.7 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/browser.rb +62 -0
  3. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46e3e095564f34c1f9a0375dd4fefb669d4920b23a8c8d925b5a598250cc9ee2
4
- data.tar.gz: 65075cef5bebe85cfbbd5098363ece05a19673144c3ba487e6c844523dc5195f
3
+ metadata.gz: 63a5cef7be688d0bd777c7fde8fe8f52dd9a6789106b7691c2b6c3bfc8300144
4
+ data.tar.gz: b6e1e2df2d171bc4bae8fe50652221551d27b76b6945b76634c612fb63e37ba3
5
5
  SHA512:
6
- metadata.gz: d319b1aee567eb3bad89a2611965409af49a3e7d00997c0c3c6b0060ea68fe60c82c4d4b4c4e51bcb4efb7b5393c0fe5438ec0b02bd1ee25b42d1354265dddf3
7
- data.tar.gz: abe09849e8951f87a7012096be40bade937d658a1ff64852ea4db96941a90ae0cf5b82e14967dd6010403fc40ecd5bfdaa9ebf70e7e93f2d084d0a3c71f38948
6
+ metadata.gz: d0288d8e1195c903dabe6560ac1ab2482898c46ed91326ed89dbf878663c459f3fbeb043b2b03eaf2aec71dfaa387c5007fec656dc2310b93f1cd5a0eb582560
7
+ data.tar.gz: c1db09ced8386a9c8f341182f62c672110c211973fa6cd409a49de7a62d6cc53278cdccd42dc0497569fd5c5dc83ca2086f0a56e7ad43e91122ccf6af86f19b2
data/lib/browser.rb ADDED
@@ -0,0 +1,62 @@
1
+ module BlackStack
2
+ module Bots
3
+ class Browser < Watir::Browser
4
+ LOCKFILENAME = '/tmp/blackstack.bots.browser.lock'
5
+ attr_accessor :pids, :lockfile
6
+
7
+ def initialize()
8
+ self.lockfile = File.open(LOCKFILENAME, 'w+')
9
+
10
+ n = 30 # timeout in seconds
11
+
12
+ # wait the lock file /tmp/blackstack.bots.browser.lock
13
+ self.lockfile.flock(File::LOCK_EX)
14
+ begin
15
+ # get list of PID of all opened chrome browsers, before launching this one
16
+ pids_before = `pgrep -f chrome`.split("\n")
17
+ # track # of chrome processes
18
+ #print "(#{pids_before.size})"
19
+ # setup driver
20
+ client = Selenium::WebDriver::Remote::Http::Default.new
21
+ begin
22
+ client.read_timeout = n # for newest selenium webdriver version
23
+ rescue => e
24
+ client.timeout = n # deprecated in newest selenium webdriver version
25
+ end
26
+ options = Selenium::WebDriver::Chrome::Options.new
27
+ options.add_argument('--headless')
28
+
29
+ # Add this parameter to run Chrome from a root user.
30
+ # https://stackoverflow.com/questions/50642308/webdriverexception-unknown-error-devtoolsactiveport-file-doesnt-exist-while-t
31
+ options.add_argument('--no-sandbox')
32
+
33
+ driver = Selenium::WebDriver.for :chrome, :options => options, http_client: client
34
+ # create the browser
35
+ super(driver)
36
+ # get list of PID of all opened chrome browsers, after launching this one
37
+ pids_after = `pgrep -f chrome`.split("\n")
38
+ # store list of PID regarding this launched browser
39
+ self.pids = pids_after - pids_before
40
+ rescue => e
41
+ # unlock the file
42
+ self.lockfile.flock(File::LOCK_UN)
43
+ # raise the error
44
+ raise e
45
+ ensure
46
+ # unlock the file
47
+ self.lockfile.flock(File::LOCK_UN)
48
+ end
49
+ end # initialize
50
+
51
+ def close
52
+ # kill all pids regarding this browser
53
+ self.pids.each { |pid| `kill -9 #{pid} >/dev/null 2>&1` }
54
+ end # close
55
+
56
+ def quit
57
+ # kill all pids regarding this browser
58
+ self.pids.each { |pid| `kill -9 #{pid} >/dev/null 2>&1` }
59
+ end # quit
60
+ end # Browser
61
+ end # Bots
62
+ end # BlackStack
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bots
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leandro Daniel Sardi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-24 00:00:00.000000000 Z
11
+ date: 2023-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simple_cloud_logging
@@ -218,6 +218,7 @@ extra_rdoc_files: []
218
218
  files:
219
219
  - lib/base.rb
220
220
  - lib/bots.rb
221
+ - lib/browser.rb
221
222
  - lib/google.rb
222
223
  - lib/indeed.rb
223
224
  - lib/scraper.rb