tweaks for march 2025 user page updates

This commit is contained in:
Dylan Knutson
2025-03-04 15:16:30 +00:00
parent 67de25a2c2
commit 259ace9862
8 changed files with 5229 additions and 22 deletions

View File

@@ -389,6 +389,7 @@ class Domain::Fa::Job::Base < Scraper::JobBase
user.num_favorites = user_page.num_favorites
user.num_watched_by = user_page.num_watched_by
user.num_watching = user_page.num_watching
user.account_status = user_page.account_status&.to_s
user.profile_html =
user_page.profile_html.encode("UTF-8", invalid: :replace, undef: :replace)
if url = user_page.profile_thumb_url

View File

@@ -30,6 +30,8 @@ class Domain::Fa::Parser::UserPageHelper < Domain::Fa::Parser::Base
@main_about = T.let(nil, T.nilable(Nokogiri::XML::Element))
@num_watched_by = T.let(nil, T.nilable(Integer))
@num_watching = T.let(nil, T.nilable(Integer))
@march_2025_update =
T.let(elem.css(".js-displayName").first.present?, T::Boolean)
@elem = elem
@page_version = page_version
@@ -48,6 +50,10 @@ class Domain::Fa::Parser::UserPageHelper < Domain::Fa::Parser::Base
def name
@name ||=
begin
if @march_2025_update
return @elem.css(".js-displayName")&.first&.text&.strip
end
elem =
case @page_version
when VERSION_0, VERSION_1
@@ -89,20 +95,28 @@ class Domain::Fa::Parser::UserPageHelper < Domain::Fa::Parser::Base
if @elem.css("userpage-nav-header img.userIcon.type-admin").first
:admin
else
elem =
case @page_version
when VERSION_2
@elem.css("userpage-nav-user-details username")
else
unimplemented_version!
end
name = elem&.first&.text&.strip || ""
if @march_2025_update
elem = @elem.css(".c-usernameBlock__symbol")
symbol = elem&.first&.text&.strip || ""
else
elem =
case @page_version
when VERSION_2
@elem.css("userpage-nav-user-details username")
else
unimplemented_version!
end
name = elem&.first&.text&.strip || ""
symbol = name[0]
end
case name[0]
case symbol
when "~"
:active
when "!"
:suspended
when "@"
:admin
when "-"
:banned
when ""
@@ -157,13 +171,23 @@ class Domain::Fa::Parser::UserPageHelper < Domain::Fa::Parser::Base
&.strip,
)
when VERSION_2
date_str =
@elem
.css("username span")
.find { |elem| elem&.text&.strip == "Registered:" }
&.next_sibling
&.text
&.strip
if @march_2025_update
date_str =
@elem
.css("userpage-nav-user-details .user-title .hideonmobile")
.find { |elem| elem&.text&.strip == "Registered:" }
&.next_sibling
&.text
&.strip
else
date_str =
@elem
.css("username span")
.find { |elem| elem&.text&.strip == "Registered:" }
&.next_sibling
&.text
&.strip
end
Time.zone.parse(date_str) if date_str
else
unimplemented_version!
@@ -325,13 +349,24 @@ class Domain::Fa::Parser::UserPageHelper < Domain::Fa::Parser::Base
end
section_elem = section_elem.css(".section-body").first
section_elem
.css("a")
.map do |link_elem|
href = link_elem["href"]
url_name =
%r{/user/(.+)/}.match(href)&.[](1) || raise("invalid url: #{href}")
name = link_elem.css(".artist_name").first.text.strip
if @march_2025_update
name =
link_elem
.css(".c-usernameBlockSimple__displayName")
.first
.text
.strip
else
name = link_elem.css(".artist_name").first.text.strip
end
RecentUser.new(name:, url_name:)
end
else

View File

@@ -53,11 +53,11 @@ class Domain::User::FaUser < Domain::User
validates :url_name, presence: true
validates :state, presence: true
validates :account_status,
inclusion: {
in: %w[ok account_disabled error],
allow_nil: true,
}
# validates :account_status,
# inclusion: {
# in: %w[active suspended banned deceased],
# allow_nil: true,
# }
after_initialize { self.state ||= "ok" if new_record? }

View File

@@ -36,6 +36,7 @@ describe Domain::Fa::Job::UserPageJob do
expect(user.num_comments_recieved).to eq(47_931)
expect(user.num_comments_given).to eq(17_741)
expect(user.num_journals).to eq(5)
expect(user.account_status).to eq("active")
end
it "enqueues a favs job scan" do

View File

@@ -539,6 +539,143 @@ describe Domain::Fa::Parser::Page do
end
end
context "march 2025 user page layout updates" do
it "gets the right page fields" do
parser =
get_parser_at(
Rails.root.join(
"test/fixtures/files/domain/fa/user_page/user_page_gnilica_03_2025_update.html",
),
)
assert_page_type parser, :probably_user_page?
up = parser.user_page
assert_equal 89, up.num_pageviews
assert_equal 1, up.num_watched_by
assert_equal 2, up.num_watching
assert_equal 3, up.num_favorites
assert_equal 1, up.num_comments_recieved
assert_equal 0, up.num_comments_given
assert_equal 1, up.num_submissions
assert_equal "gnilica", up.name
assert_equal :active, up.account_status
assert_equal ["WildSteppe"], up.recent_watchers.map(&:name)
assert_equal %w[WildSteppe just_dosha], up.recent_watching.map(&:name)
assert_equal ["wildsteppe"], up.recent_watchers.map(&:url_name)
assert_equal %w[wildsteppe justdosha], up.recent_watching.map(&:url_name)
assert_equal Time.zone.parse("Nov 8, 2023 12:16"), up.registered_since
assert_equal [55_315_013], up.recent_gallery_fa_ids
assert_equal [], up.recent_fav_fa_ids
end
it "works with deceased account" do
parser =
get_parser_at(
Rails.root.join(
"test/fixtures/files/domain/fa/user_page/user_page_dragoneer_03_2025_update.html",
),
)
assert_page_type parser, :probably_user_page?
up = parser.user_page
assert_equal "Dragoneer", up.name
assert_equal :deceased, up.account_status
assert_equal [
57_640_158,
57_631_759,
57_574_876,
57_573_028,
57_557_857,
57_550_264,
57_536_644,
57_414_032,
57_268_996,
57_253_476,
57_058_401,
56_515_114,
57_056_700,
56_527_550,
56_984_570,
56_891_225,
56_975_323,
56_943_559,
56_912_979,
56_912_982,
],
up.recent_fav_fa_ids
assert_equal [
52_163_102,
52_151_943,
52_141_347,
52_138_550,
52_130_147,
52_082_293,
52_082_271,
51_908_294,
51_894_361,
51_881_908,
51_857_730,
51_799_409,
51_785_417,
51_783_907,
51_746_087,
51_746_065,
51_362_239,
51_301_232,
51_277_956,
51_264_723,
],
up.recent_gallery_fa_ids
assert_equal %w[
kingexcalibur
drembonaarkrah
chakat-jaggerfrost
neo-kitsune
wolfiezwolf
idididid
uddebo86
wyq
eternalkrush
sabredragon
honeycumb
anthroperson18
],
up.recent_watchers.map(&:url_name)
assert_equal %w[
augurynite
inkchubs
larru-larru
zekeobsidian
appleofmyshampoo
vaspi
dissimulated
omeome
mazaku
lamor
grasseater98
videlthewusky
],
up.recent_watching.map(&:url_name)
end
it "works with a staff account" do
parser =
get_parser_at(
Rails.root.join(
"test/fixtures/files/domain/fa/user_page/user_page_ash_staff_03_2025_update.html",
),
)
assert_page_type parser, :probably_user_page?
up = parser.user_page
assert_equal "Ash", up.name
assert_equal :admin, up.account_status
end
end
def get_parser(file, require_logged_in: true)
path = File.join("domain/fa/parser/redux", file)
get_parser_at(path, require_logged_in:)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long