Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
18 changes: 17 additions & 1 deletion lib/faexport/scraper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@

def budlist(name, page, is_watchers)
mode = is_watchers ? "to" : "by"
page = page - 1 # FA changed watchers list pages from being 1-indexed, to 0-indexed. So we have to convert to ensure backward compatibility.
url = "watchlist/#{mode}/#{escape(name)}/#{page}/"
html = fetch(url)

Expand Down Expand Up @@ -1318,7 +1319,7 @@
rescue OpenURI::HTTPError => e
$http_errors.increment(labels: { page_type: page_type })
# Detect and handle known errors
if e.io.status[0] == "403" || e.io.status[0] == "503"
if e.io.status[0] == "403" || e.io.status[0] == "503" || e.io.status[0] == "400"
raw = e.io.read
html = Nokogiri::HTML(raw.encode("UTF-8", invalid: :replace, undef: :replace).delete("\000"))

Expand All @@ -1334,6 +1335,18 @@
$slowdown_errors.increment(labels: { page_type: page_type })
raise FASlowdownError.new(url)
end

# Handle user not found errors
if e.io.status[0] == "400"
head = html.xpath("//head//title").first
if head.content == "System Error"
error_msg = html.at_css("table.maintable td.alt1 font").content
# Handle user profile not found, and user not found on journal listing
if error_msg.include?("This user cannot be found") || error_msg.include?("User not found!")
raise FANoUserError.new(url)
end
end
end
end
# Retry some types of error
if e.io.status[0] == "502" || e.io.status[0] == "520"
Expand Down Expand Up @@ -1428,6 +1441,9 @@
if maintable_content.include?("has voluntarily disabled access to their account and all of its contents.")
raise FAAccountDisabledError.new(url)
end
if maintable_content.include?("Access has been disabled to the account and contents of user")
raise FAAccountDisabledError.new(url)
end

# Handle user not existing (this version of the error is raised by watchers lists and galleries)
if maintable_content.include?("Provided username not found in the database.") ||
Expand Down
3 changes: 3 additions & 0 deletions lib/faexport/views/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,9 @@ Accounts that are watching or watched by the specified user.
By default, the first 200 users are returned.
You can pass a parameter `?page=2` to load more.

**Note:** The first page, and the default page, is page 1. Furaffinity has changed their site to zero-index pages, but
for backwards compatibility, FAExport continues to 1-index them.

*Formats:* `json`, `xml`

~~~json
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/check_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
RSpec::Matchers.define :be_valid_date_and_match_iso do |iso_string|
match do |date_string|
expect(date_string).not_to be_blank
expect(date_string).to match(/[A-Z][a-z]{2} [0-9]+([a-z]{2})?, [0-9]{4},? [0-9]{2}:[0-9]{2}( ?[AP]M)?/)
expect(date_string).to match(/[A-Z][a-z]{2,} [0-9]+([a-z]{2})?, [0-9]{4},? [0-9]{2}:[0-9]{2}(:[0-9]{2})?( ?[AP]M)?/)
expect(iso_string).not_to be_blank
expect(iso_string).to eql(Time.parse("#{date_string} UTC").iso8601)
end
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/fa_parsing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@
expect(sub[:category]).not_to be_blank
expect(sub[:theme]).not_to be_blank
expect(sub[:species]).not_to be_blank
expect(sub[:gender]).not_to be_blank
expect(sub[:gender]).to be_blank
expect(sub[:favorites]).to match(/[0-9]+/)
expect(sub[:favorites].to_i).to be_positive
expect(sub[:comments]).to match(/[0-9]+/)
Expand All @@ -486,7 +486,7 @@
expect(sub[:resolution]).not_to be_blank
expect(sub[:rating]).not_to be_blank
expect(sub[:keywords]).to be_instance_of Array
expect(sub[:keywords]).to eql(%w[keyword1 keyword2 keyword3])
expect(sub[:keywords]).to eql(%w[keyword1 keyword2 keyword3 male])
end

it "fails when given non-existent submissions" do
Expand Down Expand Up @@ -657,7 +657,7 @@
expect(sub[:category]).not_to be_blank
expect(sub[:theme]).not_to be_blank
expect(sub[:species]).not_to be_blank
expect(sub[:gender]).not_to be_blank
expect(sub[:gender]).to be_blank
expect(sub[:favorites]).to match(/[0-9]+/)
expect(sub[:favorites].to_i).to be >= 0
expect(sub[:comments]).to match(/[0-9]+/)
Expand Down Expand Up @@ -757,7 +757,7 @@
expect(sub[:category]).not_to be_blank
expect(sub[:theme]).not_to be_blank
expect(sub[:species]).not_to be_blank
expect(sub[:gender]).not_to be_blank
expect(sub[:gender]).to be_blank
expect(sub[:favorites]).to match(/[0-9]+/)
expect(sub[:favorites].to_i).to be_positive
expect(sub[:comments]).to match(/[0-9]+/)
Expand Down
Loading