-
Notifications
You must be signed in to change notification settings - Fork 0
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
6 changed files
with
161 additions
and
6 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,10 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: weekly | ||
- package-ecosystem: "cargo" | ||
directory: "/" | ||
schedule: | ||
interval: weekly |
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,37 @@ | ||
name: ci | ||
|
||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
CARGO_TERM_COLOR: always | ||
CARGO_LOCA: "Cargo.toml" | ||
CARGO_BIN: "ksc" | ||
|
||
permissions: | ||
contents: write | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- "main" | ||
paths: | ||
- "Cargo.toml" | ||
- ".github/workflows/ci.yml" | ||
|
||
jobs: | ||
pre: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
cargo_loc: ${{ env.CARGO_LOCA }} | ||
cargo_bin: ${{ env.CARGO_BIN }} | ||
steps: | ||
- run: echo "Bypass GitHub Action Restriction" | ||
|
||
call: | ||
needs: | ||
- pre | ||
uses: AUTOM77/Rust-Actions/.github/workflows/ci.yml@main | ||
with: | ||
cargo_loc: ${{ needs.pre.outputs.cargo_loc }} | ||
cargo_bin: ${{ needs.pre.outputs.cargo_bin }} | ||
secrets: inherit |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,13 @@ | ||
# KingsChip | ||
|
||
## Compile | ||
|
||
```dash | ||
sudo apt install firefox-esr | ||
geckodriver --log debug | ||
geckodriver -b /usr/bin/firefox-developer-edition --log debug | ||
``` | ||
## Run | ||
`./kc $code` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
use fantoccini::{ClientBuilder, Client, Locator}; | ||
use serde_json::{json, Value}; | ||
|
||
async fn _answer(client: &Client, questions: Vec<String>) -> Result<(), Box<dyn std::error::Error>> { | ||
client.wait().for_element(Locator::Css(".QuestionBody")).await?; | ||
for q in questions{ | ||
let qid = &format!("#QID{}-label", q); | ||
// println!("{:?}", qid); | ||
client.wait().for_element(Locator::Css(qid)).await?; | ||
if let Ok(elem) = client.find(Locator::Css(qid)).await { | ||
let _ = client.execute( | ||
"arguments[0].click();", | ||
vec![serde_json::to_value(elem)?], | ||
).await; | ||
} | ||
} | ||
|
||
client.wait().for_element(Locator::Css("#NextButton")).await?; | ||
client.find(Locator::Css("#NextButton")).await?.click().await?; | ||
Ok(()) | ||
} | ||
|
||
async fn call(drive: &str, url: &str, _code: &str) -> Result<(), Box<dyn std::error::Error>> { | ||
let client = ClientBuilder::rustls() | ||
.capabilities( | ||
serde_json::json!({ | ||
"moz:firefoxOptions": { | ||
"args": ["--headless"] | ||
} | ||
}) | ||
.as_object() | ||
.unwrap() | ||
.clone(), | ||
) | ||
.connect(drive).await.expect("failed to connect to WebDriver"); | ||
client.goto(url).await?; | ||
client.find(Locator::Css(".Home_iframe__T3nfU")).await?.enter_frame().await?; | ||
|
||
client.wait().for_element(Locator::Css("#Questions")).await?; | ||
let f = client.form(Locator::Css("#Questions")).await?; | ||
f.set_by_name("QR~QID65~6~TEXT", _code).await?; | ||
|
||
if let Ok(elem) = client.find(Locator::Css("#NextButton")).await { | ||
let _ = client.execute( | ||
"arguments[0].click();", | ||
vec![serde_json::to_value(elem)?], | ||
).await; | ||
} | ||
|
||
let data: Value = json!( | ||
[ | ||
["5-2"], | ||
["7-2"], | ||
["10-2"], | ||
["60-1-2-col", "60-2-2-col", "60-3-2-col"], | ||
["62-1-2-col", "62-2-2-col", "62-4-2-col"], | ||
["63-2", "64-2"], | ||
["30-2"], | ||
["36-2"], | ||
["71-1"], | ||
["38-390"], | ||
] | ||
); | ||
|
||
if let Some(array) = data.as_array() { | ||
for item in array.iter() { | ||
if let Some(inner_array) = item.as_array() { | ||
let items: Vec<String> = inner_array.iter() | ||
.map(|x| x.as_str().unwrap_or("Invalid item").to_string()) | ||
.collect(); | ||
_answer(&client, items).await?; | ||
} | ||
} | ||
} | ||
|
||
client.wait().for_element(Locator::Css("#QID45")).await?; | ||
client.wait().for_element(Locator::Css("#NextButton")).await?; | ||
if let Ok(elem) = client.find(Locator::Css("#NextButton")).await { | ||
let _ = client.execute( | ||
"arguments[0].click();", | ||
vec![serde_json::to_value(elem)?], | ||
).await?; | ||
} | ||
|
||
client.wait().for_element(Locator::Css("#EndOfSurvey")).await?; | ||
let code = client.find(Locator::Css("strong")).await?.text().await?; | ||
|
||
println!("{:#?}", code); | ||
|
||
client.close().await?; | ||
Ok(()) | ||
} | ||
|
||
pub fn interface(drive: &str, url: &str, code: &str) -> Result<(), Box<dyn std::error::Error>> { | ||
let rt = tokio::runtime::Builder::new_multi_thread().enable_all().build()?; | ||
let _ = rt.block_on(call(drive, url, code)); | ||
Ok(()) | ||
} |