Verified Commit 250f4b95 authored by Ole Martin Ruud's avatar Ole Martin Ruud
Browse files

Start migration to unhtml

parent 55389c2c
......@@ -260,6 +260,19 @@ dependencies = [
"syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "derive_more"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "dtoa"
version = "0.4.4"
......@@ -432,8 +445,8 @@ dependencies = [
"fern 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.9.20 (registry+https://github.com/rust-lang/crates.io-index)",
"scraper 0.10.1 (git+https://github.com/barskern/scraper.git?branch=feature-simple-select)",
"structopt 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unhtml 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
......@@ -1189,7 +1202,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "scraper"
version = "0.10.1"
source = "git+https://github.com/barskern/scraper.git?branch=feature-simple-select#cffc8f7193e1eb995b13a8184b2f809638aee2d8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cssparser 0.25.9 (registry+https://github.com/rust-lang/crates.io-index)",
"ego-tree 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -1605,6 +1618,27 @@ dependencies = [
"cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "unhtml"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"scraper 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"unhtml_derive 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "unhtml_derive"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"scraper 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "unicase"
version = "2.4.0"
......@@ -1788,6 +1822,7 @@ dependencies = [
"checksum crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6"
"checksum cssparser 0.25.9 (registry+https://github.com/rust-lang/crates.io-index)" = "fbe18ca4efb9ba3716c6da66cc3d7e673bf59fa576353011f48c4cfddbdd740e"
"checksum cssparser-macros 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "5bb1c84e87c717666564ec056105052331431803d606bd45529b28547b611eef"
"checksum derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a141330240c921ec6d074a3e188a7c7ef95668bb95e7d44fa0e5778ec2a7afe"
"checksum dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ea57b42383d091c85abcc2706240b94ab2a8fa1fc81c10ff23c4de06e2a90b5e"
"checksum dtoa-short 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "59020b8513b76630c49d918c33db9f4c91638e7d3404a28084083b87e33f76f2"
"checksum ego-tree 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9733f6ada1734cb25b4033b2855ec78feb267971a2dd76012974906ba8780074"
......@@ -1893,7 +1928,7 @@ dependencies = [
"checksum schannel 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "f2f6abf258d99c3c1c5c2131d99d064e94b7b3dd5f416483057f308fea253339"
"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
"checksum scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b42e15e59b18a828bbf5c58ea01debb36b9b096346de35d941dcb89009f24a0d"
"checksum scraper 0.10.1 (git+https://github.com/barskern/scraper.git?branch=feature-simple-select)" = "<none>"
"checksum scraper 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "51be82984aed4ce8639d23eaf42b001e7cc630e6125a54ecab77bf7a3e9ee711"
"checksum security-framework 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eee63d0f4a9ec776eeb30e220f0bc1e092c3ad744b2a379e3993070364d3adc2"
"checksum security-framework-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9636f8989cbf61385ae4824b98c1aaa54c994d7d8b41f11c601ed799f0549a56"
"checksum selectors 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1b86b100bede4f651059740afc3b6cb83458d7401cb7c1ad96d8a11e91742c86"
......@@ -1936,6 +1971,8 @@ dependencies = [
"checksum tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "f2106812d500ed25a4f38235b9cae8f78a09edf43203e16e59c3b769a342a60e"
"checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382"
"checksum try_from 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "283d3b89e1368717881a9d51dad843cc435380d8109c9e47d38780a324698d8b"
"checksum unhtml 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9282663a7fc84a0b3f3e64726f8f9da6aeaeeb4de0c57dd3f66b0ba5b329dff8"
"checksum unhtml_derive 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1d32d5c6540200bea4e94c1d734114635f86855d64a49a27366f1994f5f02431"
"checksum unicase 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a84e5511b2a947f3ae965dcb29b13b7b1691b6e7332cf5dbc1744138d5acb7f6"
"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
"checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426"
......
......@@ -8,10 +8,9 @@ description = "A CLI application to query and order rooms from tp.uio.no"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
#scraper = "0.10.1"
scraper = { git = "https://github.com/barskern/scraper.git", branch = "feature-simple-select" }
reqwest = "0.9.20"
structopt = "0.3.0"
log = "0.4.8"
fern = "0.5.8"
chrono = "0.4.7"
unhtml = { version = "0.7.2", features = ["derive"] }
use log::*;
use reqwest::{Client, Request, Response};
use scraper::Html;
use unhtml::scraper::{Html, Selector};
use crate::{fmt_dbg, Config, Result, ROM_URL};
......@@ -28,14 +28,12 @@ impl App {
// TODO reduce boilerplate from html scraping
let html = Html::parse_document(&res.text()?);
let main_form = html
.try_select("form[name=f]")
.map_err(fmt_dbg)?
.select(&Selector::parse("form[name=f]").map_err(fmt_dbg)?)
.next()
.ok_or("Did not find main form")?;
let auth_state = main_form
.try_select("input[name=AuthState]")
.map_err(fmt_dbg)?
.select(&Selector::parse("input[name=AuthState]").map_err(fmt_dbg)?)
.next()
.ok_or("Did not find auth state")
.and_then(|e| {
......@@ -44,8 +42,7 @@ impl App {
.ok_or("Did not find 'value' attr in auth state")
})?;
let auth_len = main_form
.try_select("input[name=asLen]")
.map_err(fmt_dbg)?
.select(&Selector::parse("input[name=asLen]").map_err(fmt_dbg)?)
.next()
.ok_or("Did not find auth state len")
.and_then(|e| {
......@@ -90,8 +87,7 @@ impl App {
// TODO reduce boilerplate from html scraping
let html = Html::parse_document(&res.text()?);
let main_form = html
.try_select("form[method=post]")
.map_err(fmt_dbg)?
.select(&Selector::parse("form[method=post]").map_err(fmt_dbg)?)
.next()
.ok_or("Did not find main form")?;
let form_url = main_form
......@@ -99,8 +95,7 @@ impl App {
.attr("action")
.ok_or("Did not find 'action' in main form")?;
let saml_response = main_form
.try_select("input[name=SAMLResponse]")
.map_err(fmt_dbg)?
.select(&Selector::parse("input[name=SAMLResponse]").map_err(fmt_dbg)?)
.next()
.ok_or("Did not find SAMLResponse")
.and_then(|n| {
......@@ -109,8 +104,7 @@ impl App {
.ok_or("Did not find 'value' attr in SAMLResponse")
})?;
let relay_state = main_form
.try_select("input[name=RelayState]")
.map_err(fmt_dbg)?
.select(&Selector::parse("input[name=RelayState]").map_err(fmt_dbg)?)
.next()
.ok_or("Did not find RelayState")
.and_then(|n| {
......@@ -185,13 +179,11 @@ impl App {
info!("Parsing room order confirmation page");
let html = Html::parse_document(&res.text()?);
let form = html
.try_select("form[name=origform]")
.map_err(fmt_dbg)?
.select(&Selector::parse("form[name=origform]").map_err(fmt_dbg)?)
.next()
.ok_or("Did not find origform")?;
let token = form
.try_select("[name=tokenrb]")
.map_err(fmt_dbg)?
.select(&Selector::parse("[name=tokenrb]").map_err(fmt_dbg)?)
.next()
.ok_or("Did not find tokenrb input")
.and_then(|e| {
......@@ -228,13 +220,11 @@ impl App {
info!("Parsing room order receipt");
let html = Html::parse_document(&res.text()?);
let form = html
.try_select("form[name=origform]")
.map_err(fmt_dbg)?
.select(&Selector::parse("form[name=origform]").map_err(fmt_dbg)?)
.next()
.ok_or("Did not find origform")?;
let first_h3 = form
.try_select("h3")
.map_err(fmt_dbg)?
.select(&Selector::parse("h3").map_err(fmt_dbg)?)
.next()
.ok_or("Did not find section in origform")?;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment