Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--format documentation
70 changes: 70 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# human should be able to read 200 chars per line
Layout/LineLength:
Max: 200

# relax branch condition size, code can be too verbose
Metrics/AbcSize:
Max: 40

# short clear method name
Metrics/MethodLength:
Max: 25

# no performance implication
Style/OptionalBooleanParameter:
Enabled: false

# %i(array) is not common in Ruby
Style/SymbolArray:
Enabled: false

# too restrictive
Style/FrozenStringLiteralComment:
Enabled: false

# default complexity is low at 8
Metrics/PerceivedComplexity:
Max: 12

# method length is not a problem
MethodLength:
Max: 30

# if works as well as safe navigation (&.)
Style/SafeNavigation:
Enabled: false

# disable this cop, dont agree with it
Style/FetchEnvVar:
Enabled: false

# buggus check in Rubocop.
# SerpApiClient constructor is rated to 9
# def initialize(params = {})
Metrics/CyclomaticComplexity:
Max: 12

# There is a tradeoff between line length and line count.
Metrics/ClassLength:
Max: 140

# Keyword args are readable.
Metrics/ParameterLists:
CountKeywordArgs: false

# this rule doesn't always work well with Ruby
Layout/FirstHashElementIndentation:
Enabled: false

AllCops:
# hide message
SuggestExtensions: false
# show new cops
NewCops: enable
# exclude rspec files from linting
Exclude:
- 'serpapi.gemspec'
- 'spec/**/*_spec.rb'
- 'spec/spec_helper.rb'
- 'Gemfile'
- 'Rakefile'
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.7.8
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
you can touch the code now
12 changes: 12 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

source 'https://rubygems.org'

ruby '2.7.8'

gem 'nokogiri', '~> 1.15.7'

group :development, :test do
gem 'rspec'
gem 'rubocop'
end
65 changes: 65 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
GEM
remote: https://rubygems.org/
specs:
ast (2.4.3)
diff-lcs (1.6.2)
json (2.20.0)
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
mini_portile2 (2.8.9)
nokogiri (1.15.7)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
parallel (1.28.0)
parser (3.3.11.1)
ast (~> 2.4.1)
racc
prism (1.9.0)
racc (1.8.1)
rainbow (3.1.1)
regexp_parser (2.12.0)
rspec (3.13.2)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.6)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.5)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.8)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.7)
rubocop (1.88.0)
json (~> 2.3)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
parallel (>= 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.49.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.49.1)
parser (>= 3.3.7.2)
prism (~> 1.7)
ruby-progressbar (1.13.0)
unicode-display_width (3.2.0)
unicode-emoji (~> 4.1)
unicode-emoji (4.2.0)

PLATFORMS
ruby

DEPENDENCIES
nokogiri (~> 1.15.7)
rspec
rubocop

RUBY VERSION
ruby 2.7.8p225

BUNDLED WITH
2.1.4
42 changes: 42 additions & 0 deletions july17-live-coding-prep-notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# july 17/18

examining the popes example, we find that the list is inside .appbar, and each list item has role=tab
during our call on friday, i determined that the image js remains the same - base64 jpeg, var ii/s

to make the parser more generalized, first thing to do is modify the code to allow non-kp results through
- copy to new module with more accurate name
- new top-level var: nodes
- rename @kp_key to @node_key, but continue only checking kp for now
- move the kp-specific code to a method call, returning nodes
- final return acts upon nodes instead

after making room for new code, there isn't much to change...
- pull the .appbar
- populate nodes with the .appbar tabs
- override key using the .appbar heading role
- proceed as normal

compare output against https://serpapi.com/playground?q=list+of+popes

it *almost* gives us what we want, but not quite...
- playground image results are a serpapi-specific url. i think this is out of scope, so i will stick with the base64 images that i can find?
- names are missing! try node['title'] fallback
- this is almost what we want, but not quite. title concatenates name with other stuff
- try the aria-label?
- that worked! but i'm leaving the fallback in place

at this point, i will check that the old specs still work on the new module
- all specs work except for one, the one that says there is no KP
- remove this spec, because this is no longer a KP-specific parser
- add a new spec to make sure popes gives us the key we expect
- it does, but some of the names are wrong
- re-order the priority in the names method

but there is another problem - the serpapi playground results has images for all of the popes, not just the ones on the initial html
- i noticed that in the results json, 21 images are actually gstatic.com and not serpapi
- these gstatic urls can be extracted using the id, although they are buried in a big ugly blob of js
- it can be done somewhat similarly to encoded_images
- i leaned on cursor a bit for this one

finally, the serpapi links are slightly different from mine, but there are some common values (q and stick)
- adjust link specs to check common values
16 changes: 16 additions & 0 deletions july20-live-coding-session-notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# july 20

(quick notes, as i need to sleep)
we expanded the parser to pull data from knowledge panel overviews (specifically, albums from the taylor swift page)

i began using cursor toward the end of the call - it tried giving me rails-specific code which is an example of why i am cautious about what it suggests! i also removed the guardrails from the agents file

after the call, i finished getting it working and added specs to compare against the serpapi playground results for albums.

rubocop is now unhappy because the class is too big. we had discussed a little bit about how the code should be split up in the future - this is why.

i will not be refactoring it in this commit, but i would break up the following:
- go back to knowledge panel being its own class
- make new appbar class
- make new module/mixin for the two image scraper methods
- undecided on where determining the object key should go
Loading