-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
"You're banned" error scraping and thematic rounded SwiftUI font (#1187)
* Detect and report "you're banned" error page * Cleanup * Round fonts in (SwiftUI) Settings screen when requested by theme
- Loading branch information
Showing
7 changed files
with
145 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
AwfulCore/Sources/AwfulCore/Scraping/BannedScrapeResult.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// BannedScrapeResult.swift | ||
// | ||
// Copyright 2024 Awful Contributors. CC BY-NC-SA 3.0 US https://github.com/Awful/Awful.app | ||
|
||
import HTMLReader | ||
|
||
public struct BannedScrapeResult: ScrapeResult { | ||
public let help: URL? | ||
public let reason: URL? | ||
|
||
public init(_ html: HTMLNode, url: URL?) throws { | ||
guard let body = html.firstNode(matchingSelector: "body.banned") else { | ||
throw ScrapingError.missingExpectedElement("body.banned") | ||
} | ||
|
||
help = body | ||
.firstNode(matchingSelector: "a[href*='showthread.php']") | ||
.flatMap { $0["href"] } | ||
.flatMap { URL(string: $0) } | ||
reason = body | ||
.firstNode(matchingSelector: "a[href*='banlist.php']") | ||
.flatMap { $0["href"] } | ||
.flatMap { URL(string: $0) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "//www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
<html xmlns="//www.w3.org/1999/xhtml"> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> | ||
<title>You've Been Banned!</title> | ||
<style type="text/css"> | ||
body { background-color: #000000; text-align:center; font-family:arial, sans-serif; } | ||
h1 { font-weight: bold; font-size: xx-large; color: #00FF00; } | ||
.style2 { color: #FF0000; } | ||
a:link { color: #FF9900; } | ||
a:visited { color: #FF3300; } | ||
a:active { color: #FFFF00; } | ||
</style> | ||
</head> | ||
<body id="something_awful" class="banned"> | ||
<h1>CONGRATULATIONS pokeyman!!!</h1> | ||
<img src="//i.somethingawful.com/images/banned/banned2.jpg" alt="Banned!" width="800" height="800" border="1"></p> | ||
<p class="style2"><a href="/banlist.php?userid=xxxxxx&actfilt=-1">To check why you were banned, click here.</a></p> | ||
<p class="style2"><a href="//forums.somethingawful.com/showthread.php?threadid=3809308">To contact a mod or admin, click here.</a></p> | ||
<p class="style2"><a href="//www.somethingawful.com/forum-rules/forum-rules/">To read the god damn rules, click here.</a></p> | ||
<p class="style2"><a href="https://store.somethingawful.com/products/unban.php">To reactivate your Something Awful Forums account, please click here.</a></p> | ||
<a href="/account.php?action=logout&ma=xxxxxxxx">To logout of your worthless banned account, click here.</a> | ||
</body> | ||
</html> |
27 changes: 27 additions & 0 deletions
27
AwfulCore/Tests/AwfulCoreTests/Scraping/BannedScrapingTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// BannedScrapingTests.swift | ||
// | ||
// Copyright 2024 Awful Contributors. CC BY-NC-SA 3.0 US https://github.com/Awful/Awful.app | ||
|
||
@testable import AwfulCore | ||
import XCTest | ||
|
||
final class BannedScrapingTests: XCTestCase { | ||
override class func setUp() { | ||
super.setUp() | ||
testInit() | ||
} | ||
|
||
func testBanned() throws { | ||
let scraped = try scrapeHTMLFixture(BannedScrapeResult.self, named: "banned") | ||
|
||
let help = try XCTUnwrap(scraped.help) | ||
XCTAssertTrue(help.path.hasPrefix("/showthread.php")) | ||
|
||
let reason = try XCTUnwrap(scraped.reason) | ||
XCTAssertTrue(reason.path.hasPrefix("/banlist.php")) | ||
} | ||
|
||
func testNotBanned() throws { | ||
XCTAssertThrowsError(try scrapeHTMLFixture(BannedScrapeResult.self, named: "forumdisplay")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters