detect tz based on logged in user
This commit is contained in:
@@ -5,18 +5,9 @@ class Domain::Fa::Parser::Base
|
||||
sig { returns(Symbol) }
|
||||
attr_reader :page_version
|
||||
|
||||
sig { returns(T.any(Time, ActiveSupport::TimeWithZone)) }
|
||||
attr_reader :requested_at
|
||||
|
||||
sig do
|
||||
params(
|
||||
page_version: Symbol,
|
||||
requested_at: T.any(Time, ActiveSupport::TimeWithZone),
|
||||
).void
|
||||
end
|
||||
def initialize(page_version:, requested_at:)
|
||||
sig { params(page_version: Symbol).void }
|
||||
def initialize(page_version:)
|
||||
@page_version = page_version
|
||||
@requested_at = requested_at
|
||||
end
|
||||
|
||||
sig { returns(T.noreturn) }
|
||||
|
||||
@@ -19,21 +19,16 @@ class Domain::Fa::Parser::Page < Domain::Fa::Parser::Base
|
||||
)
|
||||
end
|
||||
def self.from_log_entry(log_entry, require_logged_in: true)
|
||||
new(
|
||||
T.must(log_entry.response_bytes),
|
||||
requested_at: T.must(log_entry.requested_at),
|
||||
require_logged_in:,
|
||||
)
|
||||
new(T.must(log_entry.response_bytes), require_logged_in:)
|
||||
end
|
||||
|
||||
sig do
|
||||
params(
|
||||
page_html: T.any(String, Nokogiri::HTML4::Document),
|
||||
requested_at: T.any(Time, ActiveSupport::TimeWithZone),
|
||||
require_logged_in: T::Boolean,
|
||||
).void
|
||||
end
|
||||
def initialize(page_html, requested_at:, require_logged_in: true)
|
||||
def initialize(page_html, require_logged_in: true)
|
||||
@page =
|
||||
if page_html.is_a? Nokogiri::HTML::Document
|
||||
page_html
|
||||
@@ -53,7 +48,7 @@ class Domain::Fa::Parser::Page < Domain::Fa::Parser::Base
|
||||
VERSION_0
|
||||
end
|
||||
|
||||
super(page_version:, requested_at:)
|
||||
super(page_version:)
|
||||
|
||||
if require_logged_in && !submission_not_found?
|
||||
raise Domain::Fa::Parser::NotLoggedInError unless logged_in?
|
||||
@@ -113,30 +108,21 @@ class Domain::Fa::Parser::Page < Domain::Fa::Parser::Base
|
||||
|
||||
sig { returns(Time) }
|
||||
def server_local_time
|
||||
Time.parse("#{server_local_time_string} #{server_time_zone_offset}")
|
||||
ActiveSupport::TimeZone.new("America/Los_Angeles").parse(
|
||||
server_local_time_string,
|
||||
)
|
||||
end
|
||||
|
||||
sig { returns(String) }
|
||||
def server_time_zone_offset
|
||||
server_in_utc =
|
||||
Time.use_zone("UTC") { Time.parse(server_local_time_string) }
|
||||
requested_in_utc = requested_at.in_time_zone("UTC")
|
||||
difference_hours = ((server_in_utc - requested_in_utc) / 3600)
|
||||
|
||||
# get just the decimal part of the difference
|
||||
decimal_part = difference_hours - difference_hours.to_i
|
||||
minutes = (decimal_part * 60).abs
|
||||
if minutes > 3
|
||||
raise(
|
||||
"server time zone offset not at an hour boundary: #{difference_hours.round(1)} hours; #{minutes.round(1)} minutes",
|
||||
)
|
||||
end
|
||||
|
||||
difference_hours = difference_hours.to_i
|
||||
if difference_hours >= 0
|
||||
"+#{difference_hours.to_s.rjust(2, "0")}:00"
|
||||
sig { returns(ActiveSupport::TimeZone) }
|
||||
def logged_in_user_tz
|
||||
case logged_in_user
|
||||
when "zzreg"
|
||||
ActiveSupport::TimeZone.new("America/Los_Angeles")
|
||||
when "ddwhatnow"
|
||||
ActiveSupport::TimeZone.new("America/New_York")
|
||||
else
|
||||
"-#{difference_hours.abs.to_s.rjust(2, "0")}:00"
|
||||
# server default?
|
||||
ActiveSupport::TimeZone.new("America/Los_Angeles")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -192,11 +178,7 @@ class Domain::Fa::Parser::Page < Domain::Fa::Parser::Base
|
||||
when VERSION_2
|
||||
# in the format `May 11, 2023 10:54 AM`
|
||||
date_string = @page.css("span.popup_date").first&.attr("title")
|
||||
if date_string
|
||||
Time.parse("#{date_string} #{server_time_zone_offset}")
|
||||
else
|
||||
nil
|
||||
end
|
||||
date_string ? logged_in_user_tz.parse(date_string) : nil
|
||||
else
|
||||
unimplemented_version!
|
||||
end
|
||||
|
||||
@@ -152,7 +152,7 @@ class Domain::Fa::Parser::SubmissionParserHelper < Domain::Fa::Parser::Base
|
||||
def posted_date
|
||||
@posted_date ||=
|
||||
begin
|
||||
time_zone_offset = @page.server_time_zone_offset
|
||||
time_zone_offset = @page.logged_in_user_tz
|
||||
|
||||
case @page_version
|
||||
when VERSION_0, VERSION_1
|
||||
@@ -166,14 +166,11 @@ class Domain::Fa::Parser::SubmissionParserHelper < Domain::Fa::Parser::Base
|
||||
date_str = child.try(:[], "title").try(:strip)
|
||||
if date_str
|
||||
date_str = date_str.gsub(/(\d+)(st|nd|rd|th)/, '\1')
|
||||
date_str = "#{date_str} #{time_zone_offset}"
|
||||
Time.strptime(date_str, "%b %d, %Y %I:%M %p %z")
|
||||
time_zone_offset.strptime(date_str, "%b %d, %Y %I:%M %p")
|
||||
end
|
||||
when VERSION_2
|
||||
date_str = @elem.css(".popup_date").first["title"]
|
||||
date_str = "#{date_str} #{time_zone_offset}"
|
||||
# e.g. 'Feb 18, 2023 06:47 PM'
|
||||
Time.strptime(date_str, "%b %d, %Y %I:%M %p %z") if date_str
|
||||
time_zone_offset.strptime(date_str, "%b %d, %Y %I:%M %p") if date_str
|
||||
else
|
||||
raise("unimplemented version #{@page_version}")
|
||||
end
|
||||
|
||||
@@ -180,27 +180,25 @@ class Domain::Fa::Parser::UserPageHelper < Domain::Fa::Parser::Base
|
||||
&.strip
|
||||
when VERSION_2
|
||||
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
|
||||
@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
|
||||
@elem
|
||||
.css("username span")
|
||||
.find { |elem| elem&.text&.strip == "Registered:" }
|
||||
&.next_sibling
|
||||
&.text
|
||||
&.strip
|
||||
end
|
||||
else
|
||||
unimplemented_version!
|
||||
end
|
||||
|
||||
Time.parse("#{time_str} #{@page.server_time_zone_offset}") if time_str
|
||||
@page.logged_in_user_tz.parse(time_str) if time_str
|
||||
end
|
||||
end
|
||||
|
||||
@@ -323,8 +321,7 @@ class Domain::Fa::Parser::UserPageHelper < Domain::Fa::Parser::Base
|
||||
.parse(json)
|
||||
.map do |fa_id, data|
|
||||
date_full = data["date_full"]
|
||||
faved_at =
|
||||
Time.parse("#{date_full} #{@page.server_time_zone_offset}")
|
||||
faved_at = @page.logged_in_user_tz.parse(date_full)
|
||||
FavoritesData.new(
|
||||
fa_id: fa_id.to_i,
|
||||
title: data["title"],
|
||||
|
||||
@@ -175,18 +175,17 @@ class Domain::Post::FaPost < Domain::Post
|
||||
sig { override.returns(T.nilable(ActiveSupport::TimeWithZone)) }
|
||||
def posted_at
|
||||
pa = super
|
||||
return pa if pa
|
||||
begin
|
||||
contents = guess_last_submission_log_entry
|
||||
if contents && contents.response_bytes
|
||||
parser =
|
||||
Domain::Fa::Parser::Page.from_log_entry(
|
||||
contents,
|
||||
require_logged_in: false,
|
||||
)
|
||||
if parser.probably_submission?
|
||||
parser.submission.posted_date&.in_time_zone("UTC")
|
||||
end
|
||||
return pa unless pa.nil?
|
||||
|
||||
log_entry = guess_last_submission_log_entry
|
||||
if log_entry&.response_bytes
|
||||
parser =
|
||||
Domain::Fa::Parser::Page.from_log_entry(
|
||||
log_entry,
|
||||
require_logged_in: false,
|
||||
)
|
||||
if parser.probably_submission?
|
||||
parser.submission.posted_date&.in_time_zone("UTC")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -122,7 +122,7 @@ describe Domain::Fa::Job::ScanPostJob do
|
||||
"https://d.furaffinity.net/art/-creeps/1738343855/1738343855.-creeps_slayerlr.jpg",
|
||||
)
|
||||
expect(post.posted_at).to be_within(1.second).of(
|
||||
Time.parse("Jan 31, 2025 12:17 PM -07:00"),
|
||||
Time.parse("Jan 31, 2025 12:17 PM -08:00"),
|
||||
)
|
||||
expect(post.scanned_at).to be_within(3.seconds).of(Time.now)
|
||||
end
|
||||
@@ -191,7 +191,7 @@ describe Domain::Fa::Job::ScanPostJob do
|
||||
)
|
||||
expect(post.creator).to eq(creator)
|
||||
expect(post.posted_at).to be_within(1.second).of(
|
||||
Time.parse("Feb 1, 2025 07:15 AM -07:00"),
|
||||
Time.parse("Feb 1, 2025 07:15 AM -08:00"),
|
||||
)
|
||||
expect(post.keywords).to match(array_including("wolfgang", "kiss"))
|
||||
expect(post.scanned_at).to be_within(3.seconds).of(Time.now)
|
||||
|
||||
@@ -62,7 +62,7 @@ describe Domain::Fa::Job::UserPageJob do
|
||||
expect(user.num_comments_given).to eq(17_741)
|
||||
expect(user.num_journals).to eq(5)
|
||||
expect(user.account_status).to eq("active")
|
||||
expect(user.registered_at).to eq(Time.parse("Dec 11, 2005 10:28 -07:00"))
|
||||
expect(user.registered_at).to eq(Time.parse("Dec 11, 2005 10:28 -08:00"))
|
||||
end
|
||||
|
||||
it "enqueues a favs job scan" do
|
||||
|
||||
@@ -31,17 +31,13 @@ describe Domain::Fa::Parser::Page do
|
||||
end
|
||||
|
||||
it "user_page_is_correct" do
|
||||
parser =
|
||||
get_parser(
|
||||
"user_page_miles_df.html",
|
||||
requested_at: Time.parse("Feb 23rd, 2016 08:57 AM UTC"),
|
||||
)
|
||||
parser = get_parser("user_page_miles_df.html")
|
||||
assert parser.probably_user_page?
|
||||
|
||||
expect(parser.server_local_time_string).to eq("Feb 23rd, 2016 01:57 AM")
|
||||
expect(parser.server_time_zone_offset).to eq("-07:00")
|
||||
expect(parser.logged_in_user_tz.formatted_offset).to eq("-08:00")
|
||||
expect(parser.server_local_time).to eq(
|
||||
Time.parse("Feb 23rd, 2016 08:57 AM UTC"),
|
||||
Time.parse("Feb 23rd, 2016 09:57 AM UTC"),
|
||||
)
|
||||
|
||||
up = parser.user_page
|
||||
@@ -58,7 +54,7 @@ describe Domain::Fa::Parser::Page do
|
||||
assert_equal 6645, up.num_comments_given
|
||||
assert_equal 55, up.num_journals
|
||||
assert_equal 365_602, up.num_favorites
|
||||
assert_equal Time.parse("Jan 12th, 2006 07:52 -07:00"), up.registered_since
|
||||
assert_equal Time.parse("Jan 12th, 2006 07:52 -08:00"), up.registered_since
|
||||
end
|
||||
|
||||
it "user page old old version is correct" do
|
||||
@@ -178,13 +174,9 @@ describe Domain::Fa::Parser::Page do
|
||||
end
|
||||
|
||||
it "submission_is_correct" do
|
||||
parser =
|
||||
get_parser(
|
||||
"submission_19143193_miles_df.html",
|
||||
requested_at: Time.parse("Feb 24th, 2016 07:16 UTC"),
|
||||
)
|
||||
parser = get_parser("submission_19143193_miles_df.html")
|
||||
assert parser.probably_submission?
|
||||
assert_equal "-07:00", parser.server_time_zone_offset
|
||||
assert_equal "-08:00", parser.logged_in_user_tz.formatted_offset
|
||||
assert_equal Domain::Fa::Parser::Page::VERSION_0, parser.page_version
|
||||
|
||||
sub = parser.submission
|
||||
@@ -194,7 +186,7 @@ describe Domain::Fa::Parser::Page do
|
||||
assert_equal "Miles-DF", sub.artist
|
||||
assert_equal "//d.facdn.net/art/miles-df/1455889648/1455889648.miles-df_miles-df_stream.jpg",
|
||||
sub.full_res_img
|
||||
expect(Time.parse("Feb 19th, 2016 08:47 AM -07:00")).to be_within(
|
||||
expect(Time.parse("Feb 19th, 2016 08:47 AM -08:00")).to be_within(
|
||||
1.second,
|
||||
).of(sub.posted_date)
|
||||
assert_equal "All", sub.category
|
||||
@@ -208,14 +200,10 @@ describe Domain::Fa::Parser::Page do
|
||||
assert_equal [], sub.keywords_array
|
||||
assert sub.description_html =~ /Yep, me/
|
||||
|
||||
parser =
|
||||
get_parser(
|
||||
"submission_19190013_korichi.html",
|
||||
requested_at: Time.parse("Feb 24th, 2016 05:55 UTC"),
|
||||
)
|
||||
parser = get_parser("submission_19190013_korichi.html")
|
||||
assert parser.probably_submission?
|
||||
assert_equal "Feb 24th, 2016 12:55 AM", parser.server_local_time_string
|
||||
assert_equal "-05:00", parser.server_time_zone_offset
|
||||
assert_equal "-08:00", parser.logged_in_user_tz.formatted_offset
|
||||
|
||||
sub = parser.submission
|
||||
assert_equal 19_190_013, sub.id
|
||||
@@ -226,7 +214,7 @@ describe Domain::Fa::Parser::Page do
|
||||
assert_equal 82, sub.num_views
|
||||
assert_equal "Male", sub.gender
|
||||
assert_equal "Dragon (Other)", sub.species
|
||||
expect(Time.parse("Feb 24, 2016 12:51 AM -05:00")).to be_within(
|
||||
expect(Time.parse("Feb 24, 2016 12:51 AM -08:00")).to be_within(
|
||||
1.second,
|
||||
).of(sub.posted_date)
|
||||
assert_equal %w[kobold frog hunting male frog mighty hunter],
|
||||
@@ -234,11 +222,7 @@ describe Domain::Fa::Parser::Page do
|
||||
end
|
||||
|
||||
it "updated_fa_1_submission" do
|
||||
parser =
|
||||
get_parser(
|
||||
"submission_21773129_new_fa_feretta.html",
|
||||
requested_at: Time.parse("Nov 28th, 2016 05:13 UTC"),
|
||||
)
|
||||
parser = get_parser("submission_21773129_new_fa_feretta.html")
|
||||
assert parser.probably_submission?
|
||||
assert_equal Domain::Fa::Parser::Page::VERSION_1, parser.page_version
|
||||
|
||||
@@ -250,7 +234,7 @@ describe Domain::Fa::Parser::Page do
|
||||
assert sub.description_html =~ /Forgot to put this up/
|
||||
assert_equal "//d.facdn.net/art/feretta/1479650817/1479650802.feretta_161004_space_vixen_hop_desktop.jpg",
|
||||
sub.full_res_img
|
||||
expect(Time.parse("Nov 20, 2016 9:06AM -07:00")).to be_within(1.second).of(
|
||||
expect(Time.parse("Nov 20, 2016 9:06AM -08:00")).to be_within(1.second).of(
|
||||
sub.posted_date,
|
||||
)
|
||||
assert_equal "Artwork (Digital)", sub.category
|
||||
@@ -378,11 +362,11 @@ describe Domain::Fa::Parser::Page do
|
||||
submission.artist_avatar_url
|
||||
end
|
||||
|
||||
def get_parser(file_name, require_logged_in: true, requested_at: Time.now)
|
||||
def get_parser(file_name, require_logged_in: true)
|
||||
file_path = "domain/fa/parser/legacy/#{file_name}"
|
||||
contents =
|
||||
SpecUtil.read_fixture_file(file_path) ||
|
||||
raise("Couldn't open #{file_path}")
|
||||
Domain::Fa::Parser::Page.new(contents, requested_at:, require_logged_in:)
|
||||
Domain::Fa::Parser::Page.new(contents, require_logged_in:)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -31,15 +31,11 @@ describe Domain::Fa::Parser::Page do
|
||||
end
|
||||
|
||||
it "user_page_is_correct" do
|
||||
parser =
|
||||
get_parser(
|
||||
"user_page_miles_df.html",
|
||||
requested_at: Time.parse("Feb 18, 2023 06:47 PM UTC"),
|
||||
)
|
||||
parser = get_parser("user_page_miles_df.html")
|
||||
assert parser.logged_in?
|
||||
assert_page_type parser, :probably_user_page?
|
||||
assert parser.probably_user_page?
|
||||
assert_equal "-05:00", parser.server_time_zone_offset
|
||||
assert_equal "-08:00", parser.logged_in_user_tz.formatted_offset
|
||||
up = parser.user_page
|
||||
|
||||
assert_equal "Miles-DF", up.name
|
||||
@@ -51,7 +47,7 @@ describe Domain::Fa::Parser::Page do
|
||||
assert_equal 7_227, up.num_comments_given
|
||||
assert_equal 6, up.num_journals
|
||||
assert_equal 1_236_200, up.num_favorites
|
||||
assert_equal Time.parse("Jan 12th, 2006 07:52 -0500"), up.registered_since
|
||||
assert_equal Time.parse("Jan 12th, 2006 07:52 -08:00"), up.registered_since
|
||||
assert_equal "//a.furaffinity.net/1556545516/miles-df.gif",
|
||||
up.profile_thumb_url
|
||||
end
|
||||
@@ -182,11 +178,7 @@ describe Domain::Fa::Parser::Page do
|
||||
end
|
||||
|
||||
it "adult_submission" do
|
||||
parser =
|
||||
get_parser(
|
||||
"submission_51067352_adult.html",
|
||||
requested_at: Time.parse("Feb 19, 2023 08:35 PM UTC"),
|
||||
)
|
||||
parser = get_parser("submission_51067352_adult.html")
|
||||
assert_page_type parser, :probably_submission?
|
||||
sub = parser.submission
|
||||
assert_equal 51_067_352, sub.id
|
||||
@@ -196,7 +188,7 @@ describe Domain::Fa::Parser::Page do
|
||||
assert_equal :adult, sub.rating
|
||||
assert_equal "//d.furaffinity.net/art/cleverderpy/1676764142/1676764142.cleverderpy_tarryn_and_rosie_shaymin_tar_cv_00001.png",
|
||||
sub.full_res_img
|
||||
assert_equal Time.parse("Feb 18, 2023 06:49 PM -07:00"), sub.posted_date
|
||||
assert_equal Time.parse("Feb 18, 2023 06:49 PM -08:00"), sub.posted_date
|
||||
assert_equal "Artwork (Digital)", sub.category
|
||||
assert_equal "Vore", sub.theme
|
||||
assert_equal "Unspecified / Any", sub.species
|
||||
@@ -209,11 +201,7 @@ describe Domain::Fa::Parser::Page do
|
||||
end
|
||||
|
||||
it "submission_is_correct" do
|
||||
parser =
|
||||
get_parser(
|
||||
"submission_51067333_blauhaher.html",
|
||||
requested_at: Time.parse("Feb 18, 2023 22:56 UTC"),
|
||||
)
|
||||
parser = get_parser("submission_51067333_blauhaher.html")
|
||||
assert_page_type parser, :probably_submission?
|
||||
|
||||
sub = parser.submission
|
||||
@@ -228,7 +216,7 @@ describe Domain::Fa::Parser::Page do
|
||||
sub.small_img
|
||||
assert_equal "//d.furaffinity.net/art/blauhaher/1676764049/1676764049.blauhaher_хорнь.png",
|
||||
sub.full_res_img
|
||||
assert_equal Time.parse("Feb 18, 2023 06:47 PM -07:00"), sub.posted_date
|
||||
assert_equal Time.parse("Feb 18, 2023 06:47 PM -08:00"), sub.posted_date
|
||||
assert_equal "Artwork (Digital)", sub.category
|
||||
assert_equal "Doodle", sub.theme
|
||||
assert_equal "Unspecified / Any", sub.species
|
||||
@@ -242,11 +230,7 @@ describe Domain::Fa::Parser::Page do
|
||||
end
|
||||
|
||||
it "submission_with_tags" do
|
||||
parser =
|
||||
get_parser(
|
||||
"submission_19190013_korichi.html",
|
||||
requested_at: Time.parse("Feb 18, 2023 09:32 PM UTC"),
|
||||
)
|
||||
parser = get_parser("submission_19190013_korichi.html")
|
||||
assert_page_type parser, :probably_submission?
|
||||
|
||||
sub = parser.submission
|
||||
@@ -259,17 +243,13 @@ describe Domain::Fa::Parser::Page do
|
||||
assert_equal 6272, sub.num_views
|
||||
assert_equal "Male", sub.gender
|
||||
assert_equal "Dragon (Other)", sub.species
|
||||
assert_equal Time.parse("Feb 24, 2016 12:51 AM -05:00"), sub.posted_date
|
||||
assert_equal Time.parse("Feb 24, 2016 12:51 AM -08:00"), sub.posted_date
|
||||
assert_equal %w[kobold frog hunting male frog mighty hunter],
|
||||
sub.keywords_array
|
||||
end
|
||||
|
||||
it "text_only_submission" do
|
||||
parser =
|
||||
get_parser(
|
||||
"submission_10327196_icyfoxy_text_only.html",
|
||||
requested_at: Time.parse("Feb 18, 2023 02:42 PM UTC"),
|
||||
)
|
||||
parser = get_parser("submission_10327196_icyfoxy_text_only.html")
|
||||
assert_page_type parser, :probably_submission?
|
||||
|
||||
sub = parser.submission
|
||||
@@ -308,7 +288,7 @@ describe Domain::Fa::Parser::Page do
|
||||
],
|
||||
sub.keywords_array
|
||||
assert_equal "Other / Not Specified", sub.gender
|
||||
expect(Time.parse("Apr 9, 2013 12:10 AM +02:00")).to be_within(1.second).of(
|
||||
expect(Time.parse("Apr 9, 2013 12:10 AM -07:00")).to be_within(1.second).of(
|
||||
sub.posted_date,
|
||||
)
|
||||
end
|
||||
@@ -449,11 +429,7 @@ describe Domain::Fa::Parser::Page do
|
||||
end
|
||||
|
||||
it "works with FA+ users" do
|
||||
parser =
|
||||
get_parser(
|
||||
"marzimoo_user_page.html",
|
||||
requested_at: Time.parse("Aug 25, 2023 08:59 PM UTC"),
|
||||
)
|
||||
parser = get_parser("marzimoo_user_page.html")
|
||||
assert_page_type parser, :probably_user_page?
|
||||
up = parser.user_page
|
||||
assert_equal up.name, "MarziMoo"
|
||||
@@ -493,11 +469,7 @@ describe Domain::Fa::Parser::Page do
|
||||
end
|
||||
|
||||
it "parses 2025 format" do
|
||||
parser =
|
||||
get_parser(
|
||||
"submission_59584979_2025_style_keywords.html",
|
||||
requested_at: Time.parse("Jan 20, 2025 16:25 UTC"),
|
||||
)
|
||||
parser = get_parser("submission_59584979_2025_style_keywords.html")
|
||||
assert_page_type parser, :probably_submission?
|
||||
sub = parser.submission
|
||||
|
||||
@@ -571,10 +543,9 @@ describe Domain::Fa::Parser::Page do
|
||||
Rails.root.join(
|
||||
"test/fixtures/files/domain/fa/user_page/user_page_gnilica_03_2025_update.html",
|
||||
),
|
||||
requested_at: Time.parse("Mar 4, 2025 01:55 PM UTC"),
|
||||
)
|
||||
assert_page_type parser, :probably_user_page?
|
||||
assert_equal "-07:00", parser.server_time_zone_offset
|
||||
assert_equal "-05:00", parser.logged_in_user_tz.formatted_offset
|
||||
|
||||
up = parser.user_page
|
||||
assert_equal 89, up.num_pageviews
|
||||
@@ -592,7 +563,7 @@ describe Domain::Fa::Parser::Page do
|
||||
|
||||
assert_equal ["wildsteppe"], up.recent_watchers.map(&:url_name)
|
||||
assert_equal %w[wildsteppe justdosha], up.recent_watching.map(&:url_name)
|
||||
assert_equal Time.parse("Nov 8, 2023 12:16 PM -0700"), up.registered_since
|
||||
assert_equal Time.parse("Nov 8, 2023 12:16 PM -0500"), up.registered_since
|
||||
|
||||
assert_equal [55_315_013], up.recent_gallery_fa_ids
|
||||
assert_equal [], up.recent_fav_fa_ids
|
||||
@@ -710,7 +681,6 @@ describe Domain::Fa::Parser::Page do
|
||||
Rails.root.join(
|
||||
"test/fixtures/files/domain/fa/parser/redux/submission_48178881_no_gender_fields.html",
|
||||
),
|
||||
requested_at: Time.parse("Jun 18, 2025 14:55 UTC"),
|
||||
)
|
||||
assert_page_type parser, :probably_submission?
|
||||
sub = parser.submission
|
||||
@@ -729,10 +699,7 @@ describe Domain::Fa::Parser::Page do
|
||||
describe "#favorites_json_data" do
|
||||
it "works with a user page with old embedded json format" do
|
||||
parser =
|
||||
get_fa_parser(
|
||||
"user_page/user_page_zzreg_one_scrap_submission.html",
|
||||
requested_at: Time.parse("Feb 27, 2025 10:56 PM UTC"),
|
||||
)
|
||||
get_fa_parser("user_page/user_page_zzreg_one_scrap_submission.html")
|
||||
up = parser.user_page
|
||||
expect(up.favorites_json_data.length).to eq(20)
|
||||
|
||||
@@ -744,7 +711,7 @@ describe Domain::Fa::Parser::Page do
|
||||
expect(fav0.title).to eq("Monty")
|
||||
date_full = "Feb 7, 2025 01:32 AM"
|
||||
expect(fav0.date_full).to eq(date_full)
|
||||
faved_at = Time.parse(date_full + " -07:00")
|
||||
faved_at = Time.parse(date_full + " -08:00")
|
||||
expect(fav0.faved_at).to eq(faved_at)
|
||||
end
|
||||
|
||||
@@ -752,7 +719,6 @@ describe Domain::Fa::Parser::Page do
|
||||
parser =
|
||||
get_fa_parser(
|
||||
"user_page/user_page_zzreg_new_submission_data_elem.html",
|
||||
requested_at: Time.parse("Jul 8, 2025 08:04 PM UTC"),
|
||||
)
|
||||
up = parser.user_page
|
||||
expect(up.favorites_json_data.length).to eq(20)
|
||||
@@ -783,11 +749,7 @@ describe Domain::Fa::Parser::Page do
|
||||
describe "parsing a favorites page" do
|
||||
describe "#most_recent_faved_at_time" do
|
||||
it "works with a favorites page with old embedded json format" do
|
||||
parser =
|
||||
get_fa_parser(
|
||||
"favorites/favs_zzreg_page_0_first.html",
|
||||
requested_at: Time.parse("May 17, 2023 08:52 PM UTC"),
|
||||
)
|
||||
parser = get_fa_parser("favorites/favs_zzreg_page_0_first.html")
|
||||
expect(parser.most_recent_faved_at_time).to eq(
|
||||
Time.parse("May 11, 2023 10:54 AM -07:00"),
|
||||
)
|
||||
@@ -795,10 +757,7 @@ describe Domain::Fa::Parser::Page do
|
||||
|
||||
it "works with a favorites page with new json format" do
|
||||
parser =
|
||||
get_fa_parser(
|
||||
"favorites/favs_zzreg_page_0_new_data_format.html",
|
||||
requested_at: Time.parse("Jul 8, 2025 09:36 PM UTC"),
|
||||
)
|
||||
get_fa_parser("favorites/favs_zzreg_page_0_new_data_format.html")
|
||||
expect(parser.most_recent_faved_at_time).to eq(
|
||||
Time.parse("Jul 8, 2025 01:04 PM -07:00"),
|
||||
)
|
||||
@@ -812,13 +771,12 @@ describe Domain::Fa::Parser::Page do
|
||||
get_fa_parser(
|
||||
"user_page/user_page_fenford_11_2016.html",
|
||||
version: Domain::Fa::Parser::Page::VERSION_0,
|
||||
requested_at: Time.parse("Nov 26th, 2016 18:34 UTC"),
|
||||
)
|
||||
|
||||
expect(parser.server_local_time_string).to eq("Nov 26th, 2016 01:34 PM")
|
||||
expect(parser.server_time_zone_offset).to eq("-05:00")
|
||||
expect(parser.logged_in_user_tz.formatted_offset).to eq("-08:00")
|
||||
expect(parser.server_local_time).to eq(
|
||||
Time.parse("Nov 26th, 2016 01:34 PM -0500"),
|
||||
Time.parse("Nov 26th, 2016 01:34 PM -0800"),
|
||||
)
|
||||
end
|
||||
|
||||
@@ -827,13 +785,12 @@ describe Domain::Fa::Parser::Page do
|
||||
get_fa_parser(
|
||||
"user_page/user_page_fenford_07_2025.html",
|
||||
version: Domain::Fa::Parser::Page::VERSION_2,
|
||||
requested_at: Time.parse("Jul 9th, 2025 00:34 UTC"),
|
||||
)
|
||||
|
||||
expect(parser.server_local_time_string).to eq("Jul 8, 2025 03:34 PM")
|
||||
expect(parser.server_time_zone_offset).to eq("-09:00")
|
||||
expect(parser.logged_in_user_tz.formatted_offset).to eq("-08:00")
|
||||
expect(parser.server_local_time).to eq(
|
||||
Time.parse("Jul 8th, 2025 3:34 PM -0900"),
|
||||
Time.parse("Jul 8th, 2025 3:34 PM -0700"),
|
||||
)
|
||||
end
|
||||
end
|
||||
@@ -845,9 +802,8 @@ describe Domain::Fa::Parser::Page do
|
||||
get_fa_parser(
|
||||
"user_page/user_page_fenford_11_2016.html",
|
||||
version: Domain::Fa::Parser::Page::VERSION_0,
|
||||
requested_at: Time.parse("2016-11-26 18:34:57 UTC"),
|
||||
)
|
||||
expect(parser.server_time_zone_offset).to eq("-05:00")
|
||||
expect(parser.logged_in_user_tz.formatted_offset).to eq("-08:00")
|
||||
end
|
||||
|
||||
it "works with a user page from 2025" do
|
||||
@@ -855,44 +811,29 @@ describe Domain::Fa::Parser::Page do
|
||||
get_fa_parser(
|
||||
"user_page/user_page_fenford_07_2025.html",
|
||||
version: Domain::Fa::Parser::Page::VERSION_2,
|
||||
requested_at: Time.parse("2025-07-08 22:35:13 UTC"),
|
||||
)
|
||||
expect(parser.server_time_zone_offset).to eq("-07:00")
|
||||
end
|
||||
|
||||
it "raises if the server time zone offset is not at an hour boundary" do
|
||||
parser =
|
||||
get_fa_parser(
|
||||
"user_page/user_page_fenford_07_2025.html",
|
||||
version: Domain::Fa::Parser::Page::VERSION_2,
|
||||
requested_at: Time.parse("2025-07-08 22:48:12 UTC"),
|
||||
)
|
||||
expect { parser.server_time_zone_offset }.to raise_error(
|
||||
/server time zone offset not at an hour boundary/,
|
||||
)
|
||||
expect(parser.logged_in_user_tz.formatted_offset).to eq("-08:00")
|
||||
end
|
||||
end
|
||||
|
||||
def get_fa_parser(
|
||||
file,
|
||||
require_logged_in: true,
|
||||
version: Domain::Fa::Parser::Page::VERSION_2,
|
||||
requested_at: Time.now
|
||||
version: Domain::Fa::Parser::Page::VERSION_2
|
||||
)
|
||||
path = File.join("domain/fa", file)
|
||||
get_parser_at(path, require_logged_in:, version:, requested_at:)
|
||||
get_parser_at(path, require_logged_in:, version:)
|
||||
end
|
||||
|
||||
def get_parser(file, require_logged_in: true, requested_at: Time.now)
|
||||
def get_parser(file, require_logged_in: true)
|
||||
path = File.join("domain/fa/parser/redux", file)
|
||||
get_parser_at(path, require_logged_in:, requested_at:)
|
||||
get_parser_at(path, require_logged_in:)
|
||||
end
|
||||
|
||||
def get_parser_at(
|
||||
path,
|
||||
require_logged_in: true,
|
||||
version: Domain::Fa::Parser::Page::VERSION_2,
|
||||
requested_at: Time.now
|
||||
version: Domain::Fa::Parser::Page::VERSION_2
|
||||
)
|
||||
path = path.to_s
|
||||
contents =
|
||||
@@ -901,7 +842,6 @@ describe Domain::Fa::Parser::Page do
|
||||
Domain::Fa::Parser::Page.new(
|
||||
contents,
|
||||
require_logged_in: require_logged_in,
|
||||
requested_at: requested_at,
|
||||
)
|
||||
assert_equal version,
|
||||
parser.page_version,
|
||||
|
||||
Reference in New Issue
Block a user