zorki 0.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/.github/workflows/main.yml +18 -0
- data/.gitignore +12 -0
- data/.rubocop.yml +67 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +162 -0
- data/LICENSE.txt +21 -0
- data/README.md +85 -0
- data/Rakefile +16 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/generators/zorki.rb +3 -0
- data/lib/generators/zorki_generator.rb +6 -0
- data/lib/helpers/configuration.rb +28 -0
- data/lib/zorki/monkeypatch.rb +50 -0
- data/lib/zorki/post.rb +46 -0
- data/lib/zorki/scrapers/post_scraper.rb +125 -0
- data/lib/zorki/scrapers/scraper.rb +227 -0
- data/lib/zorki/scrapers/user_scraper.rb +74 -0
- data/lib/zorki/user.rb +52 -0
- data/lib/zorki/version.rb +5 -0
- data/lib/zorki.rb +74 -0
- data/zorki.gemspec +43 -0
- data/zorki.logs +300 -0
- metadata +152 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 384abb984483d4f38da44e77b7cd359e7d3aadea7c96765bc5b2837c3e79e99d
|
4
|
+
data.tar.gz: 48bf93b460b4c947cc9bf47f97dc469de124686cb763eccfa8ef7ef00e11f2b6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e70b44d624a51df5a7ca6d9b6078cf3b44c8da1c07291aee60e4d554e2bc5705cfab3cea112ccbc79f6354d1092dca90330b7697f4e19606034857de361a08e3
|
7
|
+
data.tar.gz: b819d82e750f72cb55ab34b2a7b8332c70828220857501c22315480e644c2b88d5732f3b4074d7d240015a70dadace213b4a1e388145a6d50d544ef36b20b655
|
@@ -0,0 +1,18 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push,pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- uses: actions/checkout@v2
|
10
|
+
- name: Set up Ruby
|
11
|
+
uses: ruby/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: 3.1.2
|
14
|
+
- name: Run the default task
|
15
|
+
run: |
|
16
|
+
gem install bundler -v 2.2.14
|
17
|
+
bundle install
|
18
|
+
rubocop
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rails
|
3
|
+
|
4
|
+
inherit_gem:
|
5
|
+
rubocop-rails_config:
|
6
|
+
- config/rails.yml
|
7
|
+
|
8
|
+
AllCops:
|
9
|
+
Exclude:
|
10
|
+
- db/schema.rb
|
11
|
+
- 'node_modules/**/*'
|
12
|
+
- 'redis-stable/**/*'
|
13
|
+
- 'bin/**/*'
|
14
|
+
- 'vendor/**/*'
|
15
|
+
TargetRubyVersion: 3.0
|
16
|
+
|
17
|
+
# Rails generates this file
|
18
|
+
Style/BlockComments:
|
19
|
+
Exclude:
|
20
|
+
- 'db/seeds.rb'
|
21
|
+
|
22
|
+
# This sets us to use the standard Rails format instead of Rubocop's
|
23
|
+
# opinionated Ruby style.
|
24
|
+
Style/FrozenStringLiteralComment:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
# This sets us to use the standard Rails format instead of Rubocop's
|
28
|
+
# opinionated Ruby style.
|
29
|
+
Style/ClassAndModuleChildren:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
# Rails generates this file
|
33
|
+
Layout/IndentationStyle:
|
34
|
+
Exclude:
|
35
|
+
- 'db/seeds.rb'
|
36
|
+
|
37
|
+
# Temporarily turn this off
|
38
|
+
Metrics/AbcSize:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
Metrics/ClassLength:
|
42
|
+
Enabled: true
|
43
|
+
|
44
|
+
Lint/RescueException:
|
45
|
+
Enabled: true
|
46
|
+
|
47
|
+
Lint/Debugger:
|
48
|
+
Enabled: true
|
49
|
+
|
50
|
+
Rails/HasManyOrHasOneDependent:
|
51
|
+
Enabled: true
|
52
|
+
|
53
|
+
Rails/HasAndBelongsToMany:
|
54
|
+
Enabled: true
|
55
|
+
|
56
|
+
Style/NumericPredicate:
|
57
|
+
Enabled: true
|
58
|
+
|
59
|
+
# This sets us to use the standard Rails format instead of Rubocop's
|
60
|
+
# opinionated Ruby style.
|
61
|
+
Layout/EmptyLinesAroundAccessModifier:
|
62
|
+
Enabled: true
|
63
|
+
EnforcedStyle: 'around'
|
64
|
+
|
65
|
+
# We're not a Rails app, just using their style sheet
|
66
|
+
Rails/AssertNot:
|
67
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at cguess@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in zorki.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "rake", "~> 13.0"
|
9
|
+
|
10
|
+
gem "minitest", "~> 5.0"
|
11
|
+
|
12
|
+
gem "rubocop", "~> 1.7"
|
13
|
+
|
14
|
+
gem "rubocop-rails", "~> 2.19.1", require: false # Rails specific styles
|
15
|
+
gem "rubocop-rails_config"
|
16
|
+
|
17
|
+
gem "dotenv", "~> 2.7.6"
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
zorki (0.1.0)
|
5
|
+
apparition
|
6
|
+
capybara
|
7
|
+
oj
|
8
|
+
selenium-devtools
|
9
|
+
selenium-webdriver
|
10
|
+
typhoeus
|
11
|
+
|
12
|
+
GEM
|
13
|
+
remote: https://rubygems.org/
|
14
|
+
specs:
|
15
|
+
actionpack (7.0.4.3)
|
16
|
+
actionview (= 7.0.4.3)
|
17
|
+
activesupport (= 7.0.4.3)
|
18
|
+
rack (~> 2.0, >= 2.2.0)
|
19
|
+
rack-test (>= 0.6.3)
|
20
|
+
rails-dom-testing (~> 2.0)
|
21
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
22
|
+
actionview (7.0.4.3)
|
23
|
+
activesupport (= 7.0.4.3)
|
24
|
+
builder (~> 3.1)
|
25
|
+
erubi (~> 1.4)
|
26
|
+
rails-dom-testing (~> 2.0)
|
27
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
28
|
+
activesupport (7.0.4.3)
|
29
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
30
|
+
i18n (>= 1.6, < 2)
|
31
|
+
minitest (>= 5.1)
|
32
|
+
tzinfo (~> 2.0)
|
33
|
+
addressable (2.8.4)
|
34
|
+
public_suffix (>= 2.0.2, < 6.0)
|
35
|
+
apparition (0.6.0)
|
36
|
+
capybara (~> 3.13, < 4)
|
37
|
+
websocket-driver (>= 0.6.5)
|
38
|
+
ast (2.4.2)
|
39
|
+
builder (3.2.4)
|
40
|
+
capybara (3.39.1)
|
41
|
+
addressable
|
42
|
+
matrix
|
43
|
+
mini_mime (>= 0.1.3)
|
44
|
+
nokogiri (~> 1.8)
|
45
|
+
rack (>= 1.6.0)
|
46
|
+
rack-test (>= 0.6.3)
|
47
|
+
regexp_parser (>= 1.5, < 3.0)
|
48
|
+
xpath (~> 3.2)
|
49
|
+
concurrent-ruby (1.2.2)
|
50
|
+
crass (1.0.6)
|
51
|
+
dotenv (2.7.6)
|
52
|
+
erubi (1.12.0)
|
53
|
+
ethon (0.16.0)
|
54
|
+
ffi (>= 1.15.0)
|
55
|
+
ffi (1.15.5)
|
56
|
+
i18n (1.13.0)
|
57
|
+
concurrent-ruby (~> 1.0)
|
58
|
+
json (2.6.3)
|
59
|
+
loofah (2.21.2)
|
60
|
+
crass (~> 1.0.2)
|
61
|
+
nokogiri (>= 1.12.0)
|
62
|
+
matrix (0.4.2)
|
63
|
+
method_source (1.0.0)
|
64
|
+
mini_mime (1.1.2)
|
65
|
+
minitest (5.18.0)
|
66
|
+
nokogiri (1.14.4-arm64-darwin)
|
67
|
+
racc (~> 1.4)
|
68
|
+
oj (3.14.3)
|
69
|
+
parallel (1.23.0)
|
70
|
+
parser (3.2.2.1)
|
71
|
+
ast (~> 2.4.1)
|
72
|
+
public_suffix (5.0.1)
|
73
|
+
racc (1.6.2)
|
74
|
+
rack (2.2.7)
|
75
|
+
rack-test (2.1.0)
|
76
|
+
rack (>= 1.3)
|
77
|
+
rails-dom-testing (2.0.3)
|
78
|
+
activesupport (>= 4.2.0)
|
79
|
+
nokogiri (>= 1.6)
|
80
|
+
rails-html-sanitizer (1.5.0)
|
81
|
+
loofah (~> 2.19, >= 2.19.1)
|
82
|
+
railties (7.0.4.3)
|
83
|
+
actionpack (= 7.0.4.3)
|
84
|
+
activesupport (= 7.0.4.3)
|
85
|
+
method_source
|
86
|
+
rake (>= 12.2)
|
87
|
+
thor (~> 1.0)
|
88
|
+
zeitwerk (~> 2.5)
|
89
|
+
rainbow (3.1.1)
|
90
|
+
rake (13.0.6)
|
91
|
+
regexp_parser (2.8.0)
|
92
|
+
rexml (3.2.5)
|
93
|
+
rubocop (1.51.0)
|
94
|
+
json (~> 2.3)
|
95
|
+
parallel (~> 1.10)
|
96
|
+
parser (>= 3.2.0.0)
|
97
|
+
rainbow (>= 2.2.2, < 4.0)
|
98
|
+
regexp_parser (>= 1.8, < 3.0)
|
99
|
+
rexml (>= 3.2.5, < 4.0)
|
100
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
101
|
+
ruby-progressbar (~> 1.7)
|
102
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
103
|
+
rubocop-ast (1.28.1)
|
104
|
+
parser (>= 3.2.1.0)
|
105
|
+
rubocop-md (1.2.0)
|
106
|
+
rubocop (>= 1.0)
|
107
|
+
rubocop-minitest (0.31.0)
|
108
|
+
rubocop (>= 1.39, < 2.0)
|
109
|
+
rubocop-packaging (0.5.2)
|
110
|
+
rubocop (>= 1.33, < 2.0)
|
111
|
+
rubocop-performance (1.17.1)
|
112
|
+
rubocop (>= 1.7.0, < 2.0)
|
113
|
+
rubocop-ast (>= 0.4.0)
|
114
|
+
rubocop-rails (2.19.1)
|
115
|
+
activesupport (>= 4.2.0)
|
116
|
+
rack (>= 1.1)
|
117
|
+
rubocop (>= 1.33.0, < 2.0)
|
118
|
+
rubocop-rails_config (1.13.0)
|
119
|
+
railties (>= 5.0)
|
120
|
+
rubocop (>= 1.48.0)
|
121
|
+
rubocop-ast (>= 1.26.0)
|
122
|
+
rubocop-md
|
123
|
+
rubocop-minitest (~> 0.22)
|
124
|
+
rubocop-packaging (~> 0.5)
|
125
|
+
rubocop-performance (~> 1.11)
|
126
|
+
rubocop-rails (~> 2.0)
|
127
|
+
ruby-progressbar (1.13.0)
|
128
|
+
rubyzip (2.3.2)
|
129
|
+
selenium-devtools (0.113.0)
|
130
|
+
selenium-webdriver (~> 4.2)
|
131
|
+
selenium-webdriver (4.9.1)
|
132
|
+
rexml (~> 3.2, >= 3.2.5)
|
133
|
+
rubyzip (>= 1.2.2, < 3.0)
|
134
|
+
websocket (~> 1.0)
|
135
|
+
thor (1.2.2)
|
136
|
+
typhoeus (1.4.0)
|
137
|
+
ethon (>= 0.9.0)
|
138
|
+
tzinfo (2.0.6)
|
139
|
+
concurrent-ruby (~> 1.0)
|
140
|
+
unicode-display_width (2.4.2)
|
141
|
+
websocket (1.2.9)
|
142
|
+
websocket-driver (0.7.5)
|
143
|
+
websocket-extensions (>= 0.1.0)
|
144
|
+
websocket-extensions (0.1.5)
|
145
|
+
xpath (3.2.0)
|
146
|
+
nokogiri (~> 1.8)
|
147
|
+
zeitwerk (2.6.8)
|
148
|
+
|
149
|
+
PLATFORMS
|
150
|
+
arm64-darwin-22
|
151
|
+
|
152
|
+
DEPENDENCIES
|
153
|
+
dotenv (~> 2.7.6)
|
154
|
+
minitest (~> 5.0)
|
155
|
+
rake (~> 13.0)
|
156
|
+
rubocop (~> 1.7)
|
157
|
+
rubocop-rails (~> 2.19.1)
|
158
|
+
rubocop-rails_config
|
159
|
+
zorki!
|
160
|
+
|
161
|
+
BUNDLED WITH
|
162
|
+
2.4.9
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Christopher Guess
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# Zorki
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/zorki`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Pre Reqs
|
8
|
+
|
9
|
+
This requires the chromedriver
|
10
|
+
|
11
|
+
### MacOS
|
12
|
+
|
13
|
+
`brew install chromedriver`
|
14
|
+
|
15
|
+
### Raspberry OS (aka Rasbian / Debian)
|
16
|
+
Since this requires ARMHF support it's not through regular sources. However, the maintainers of Raspberry OS has made their own!
|
17
|
+
`sudo apt install chromium-chromedriver`
|
18
|
+
|
19
|
+
### Debian/Ubuntu
|
20
|
+
`sudo apt install chromedriver` (should work)
|
21
|
+
|
22
|
+
## Installation
|
23
|
+
|
24
|
+
Add this line to your application's Gemfile:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
gem "zorki"
|
28
|
+
```
|
29
|
+
|
30
|
+
And then execute:
|
31
|
+
|
32
|
+
$ bundle install
|
33
|
+
|
34
|
+
|
35
|
+
### Selenium Standalone
|
36
|
+
We use Selenium's standalone package. To set it up:
|
37
|
+
1. Download the "Selenium Server (Grid)" JAR package at https://www.selenium.dev/downloads/
|
38
|
+
1. Save it to the folder of this package
|
39
|
+
1. Test that it works by running `java -jar ./selenium-server-4.2.1.jar standalone` (note the actual version you downloaded)
|
40
|
+
|
41
|
+
## Testing
|
42
|
+
|
43
|
+
1. Turn on the Selenium server `java -jar ./selenium-server-4.2.1.jar standalone` in a separate pane or window
|
44
|
+
1. `rake test`
|
45
|
+
|
46
|
+
## Development
|
47
|
+
|
48
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
49
|
+
|
50
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
51
|
+
|
52
|
+
## Debugging
|
53
|
+
|
54
|
+
This scraper is prone to break pretty often due to Instagram's GraphQL schema being pretty damn unstable.
|
55
|
+
Whether this is malevolent (to purposely break scrapers) or just happening in the course of development is undetermined and really, doesn't matter.
|
56
|
+
|
57
|
+
Debugging this is a bit of a pain, but I'm laying out a few steps to start at and make this easier.
|
58
|
+
Some of this may sound basic, but it's good to keep it all in mind.
|
59
|
+
|
60
|
+
1. Run the tests `rake test` and note the line where everything is breaking, if it's a schema change
|
61
|
+
this will probably be the same line a few times over. If it's a lot of different lines it's probably
|
62
|
+
your code, not on the Instagram side.
|
63
|
+
1. Set a debug point around the `find_graphql_script` function start in `lib/zorki/scrapers/scraper.rb` file
|
64
|
+
(line 27 as of writing).
|
65
|
+
1. You can also add a begin/rescue block around the find functions looking for the GraphQL blob.
|
66
|
+
1. When the debugger is hit the Chrome instance will be on the page that's causing the issue, from there
|
67
|
+
you can inspect the page itself, looking for the keywords.
|
68
|
+
1. From this point, start fiddling in the debugger, traversing the DOM until you get to a place that looks
|
69
|
+
like it might be the right structure.
|
70
|
+
1. Fix up the find functions (sometimes a reordering of the look ups is enough)
|
71
|
+
1. Trust the tests, run them over and over, modifying as little about the rest of the code as possible,
|
72
|
+
otherwise you may end up changing the structure of everything, we don't want that.
|
73
|
+
1. Ask Chris or Asa if you have questions.
|
74
|
+
|
75
|
+
## Contributing
|
76
|
+
|
77
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/zorki. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/zorki/blob/master/CODE_OF_CONDUCT.md).
|
78
|
+
|
79
|
+
## License
|
80
|
+
|
81
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
82
|
+
|
83
|
+
## Code of Conduct
|
84
|
+
|
85
|
+
Everyone interacting in the Zorki project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/zorki/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
10
|
+
end
|
11
|
+
|
12
|
+
require "rubocop/rake_task"
|
13
|
+
|
14
|
+
RuboCop::RakeTask.new
|
15
|
+
|
16
|
+
task default: %i[test rubocop]
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "zorki"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Borrowed with thanks from https://www.viget.com/articles/easy-gem-configuration-variables-with-defaults/
|
4
|
+
module Configuration
|
5
|
+
def configuration
|
6
|
+
yield self
|
7
|
+
end
|
8
|
+
|
9
|
+
def define_setting(name, default = nil)
|
10
|
+
class_variable_set("@@#{name}", default)
|
11
|
+
|
12
|
+
define_class_method "#{name}=" do |value|
|
13
|
+
class_variable_set("@@#{name}", value)
|
14
|
+
end
|
15
|
+
|
16
|
+
define_class_method name do
|
17
|
+
class_variable_get("@@#{name}")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def define_class_method(name, &block)
|
24
|
+
(class << self; self; end).instance_eval do
|
25
|
+
define_method name, &block
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "logger"
|
2
|
+
require "selenium-webdriver"
|
3
|
+
|
4
|
+
# Design taken from https://blog.appsignal.com/2021/08/24/responsible-monkeypatching-in-ruby.html
|
5
|
+
|
6
|
+
module SeleniumMonkeypatch
|
7
|
+
class << self
|
8
|
+
@@logger = Logger.new(STDOUT)
|
9
|
+
@@logger.level = Logger::INFO
|
10
|
+
|
11
|
+
def apply_patch
|
12
|
+
target_class = find_class
|
13
|
+
target_method = find_method(target_class)
|
14
|
+
|
15
|
+
unless target_method
|
16
|
+
raise "Could not find class or method when patching Selenium::WebDriver::DevTools.send_cmd"
|
17
|
+
end
|
18
|
+
|
19
|
+
@@logger.info "#{__FILE__} is monkeypatching Selenium::WebDriver::DevTools.send_cmd"
|
20
|
+
target_class.prepend(InstanceMethods)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def find_class
|
26
|
+
Kernel.const_get("Selenium::WebDriver::DevTools")
|
27
|
+
rescue NameError
|
28
|
+
end
|
29
|
+
|
30
|
+
def find_method(class_)
|
31
|
+
return unless class_
|
32
|
+
class_.instance_method(:send_cmd)
|
33
|
+
rescue NameError
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
module InstanceMethods
|
38
|
+
# We're monkeypatching the following method so that Selenium doesn't raise errors when we fail to call `continue` on requests
|
39
|
+
def send_cmd(method, **params)
|
40
|
+
data = { method: method, params: params.compact }
|
41
|
+
data[:sessionId] = @session_id if @session_id
|
42
|
+
message = @ws.send_cmd(**data)
|
43
|
+
raise Error::WebDriverError, error_message(message["error"]) if message["error"] && (method != "Fetch.continueRequest")
|
44
|
+
|
45
|
+
message
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
SeleniumMonkeypatch.apply_patch
|
data/lib/zorki/post.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zorki
|
4
|
+
class Post
|
5
|
+
def self.lookup(ids = [])
|
6
|
+
# If a single id is passed in we make it the appropriate array
|
7
|
+
ids = [ids] unless ids.kind_of?(Array)
|
8
|
+
self.scrape(ids)
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :id,
|
12
|
+
:image_file_names,
|
13
|
+
:text,
|
14
|
+
:date,
|
15
|
+
:number_of_likes,
|
16
|
+
:user,
|
17
|
+
:video_file_name,
|
18
|
+
:video_preview_image,
|
19
|
+
:screenshot_file
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def initialize(post_hash = {})
|
24
|
+
@id = post_hash[:id]
|
25
|
+
@image_file_names = post_hash[:images]
|
26
|
+
@text = post_hash[:text]
|
27
|
+
@date = post_hash[:date]
|
28
|
+
@number_of_likes = post_hash[:number_of_likes]
|
29
|
+
@user = post_hash[:user]
|
30
|
+
@video_file_name = post_hash[:video]
|
31
|
+
@video_preview_image = post_hash[:video_preview_image]
|
32
|
+
@screenshot_file = post_hash[:screenshot_file]
|
33
|
+
end
|
34
|
+
|
35
|
+
class << self
|
36
|
+
private
|
37
|
+
|
38
|
+
def scrape(ids)
|
39
|
+
ids.map do |id|
|
40
|
+
post_hash = Zorki::PostScraper.new.parse(id)
|
41
|
+
Post.new(post_hash)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|