-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
130 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Build and Test | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Build | ||
run: cargo build --verbose | ||
- name: Run tests | ||
run: cargo test --verbose |
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,72 @@ | ||
use std::{ | ||
fs::{create_dir_all, File}, | ||
io::Write, | ||
}; | ||
|
||
use aero2solver::{ | ||
constants::{BASE_URL, USER_AGENT}, | ||
portal::PortalClient, | ||
solver::Aero2Solver, | ||
}; | ||
use anyhow::{anyhow, Result}; | ||
|
||
fn run(solver: &mut Aero2Solver) -> Result<()> { | ||
let client = PortalClient::new(BASE_URL, USER_AGENT)?; | ||
|
||
let state = client.get_state()?; | ||
|
||
let mut tries = 0; | ||
let (solution, captcha) = loop { | ||
tries += 1; | ||
println!("Trying to solve captcha (try {})", tries); | ||
let captcha = client.get_captcha(&state.session_id)?; | ||
match solver.solve(&captcha, 0.9, 8) { | ||
Ok(solution) => { | ||
println!("Captcha solved as {} after {}", solution, tries); | ||
break (solution, captcha); | ||
} | ||
Err(e) => println!("Error while solving captcha: {}", e), | ||
} | ||
}; | ||
|
||
let state = client.submit_captcha(&state.session_id, &solution)?; | ||
match state.message { | ||
Some(ref message) if message.eq("Rozłącz i ponownie połącz się z Internetem.") => { | ||
println!("Captcha solved, code: {}", solution); | ||
} | ||
_ => Err(anyhow!( | ||
"Captcha solved with message: {}", | ||
state.message.unwrap_or_default() | ||
))?, | ||
} | ||
|
||
let mut file = File::create(format!("./tests/data/captcha_{}.jpg", solution))?; | ||
file.write_all(&captcha)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn main() -> Result<()> { | ||
let mut solver = Aero2Solver::new( | ||
"./model/captcha.names", | ||
"./model/captcha.cfg", | ||
"./model/captcha.weights", | ||
)?; | ||
|
||
create_dir_all("./tests/data")?; | ||
|
||
// loop until we have 10 successful solves | ||
let mut success_count = 0; | ||
loop { | ||
if success_count >= 10 { | ||
break; | ||
} | ||
|
||
match run(&mut solver) { | ||
Ok(_) => success_count += 1, | ||
Err(e) => println!("Error: {}", e), | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,38 @@ | ||
use aero2solver::solver::Aero2Solver; | ||
use std::fs; | ||
|
||
#[test] | ||
fn test_solve() { | ||
let mut solver = Aero2Solver::new( | ||
"./model/captcha.names", | ||
"./model/captcha.cfg", | ||
"./model/captcha.weights", | ||
) | ||
.unwrap(); | ||
|
||
// solve all captchas that match the pattern captcha_*.jpg | ||
let files = fs::read_dir("./tests/data") | ||
.unwrap() | ||
.map(|x| x.unwrap().path()) | ||
.filter(|x| { | ||
x.to_str().unwrap().contains("captcha_") && x.to_str().unwrap().ends_with(".jpg") | ||
}) | ||
.collect::<Vec<_>>(); | ||
|
||
for ref file in files { | ||
// extract text between captcha_ and .jpg | ||
let correct_solution = file | ||
.file_stem() | ||
.unwrap() | ||
.to_str() | ||
.unwrap() | ||
.split('_') | ||
.last() | ||
.unwrap(); | ||
|
||
let captcha = fs::read(file).unwrap(); | ||
let solution = solver.solve(&captcha, 0.9, 8).unwrap(); | ||
assert_eq!(solution, correct_solution); | ||
println!("solved test captcha: {}", solution); | ||
} | ||
} |