Finished first version of search_streets
parent
ab31a5e471
commit
4032800d64
|
@ -134,19 +134,6 @@ version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "chrono"
|
|
||||||
version = "0.4.19"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"num-integer",
|
|
||||||
"num-traits",
|
|
||||||
"time",
|
|
||||||
"winapi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cipher"
|
name = "cipher"
|
||||||
version = "0.2.5"
|
version = "0.2.5"
|
||||||
|
@ -632,25 +619,6 @@ dependencies = [
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "num-integer"
|
|
||||||
version = "0.1.44"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
"num-traits",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "num-traits"
|
|
||||||
version = "0.2.14"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num_cpus"
|
name = "num_cpus"
|
||||||
version = "1.13.0"
|
version = "1.13.0"
|
||||||
|
@ -915,7 +883,6 @@ dependencies = [
|
||||||
name = "rust-api"
|
name = "rust-api"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"rocket",
|
"rocket",
|
||||||
]
|
]
|
||||||
|
|
|
@ -8,7 +8,6 @@ edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rocket = "0.4.7"
|
rocket = "0.4.7"
|
||||||
chrono = "0.4.19"
|
|
||||||
|
|
||||||
[dependencies.reqwest]
|
[dependencies.reqwest]
|
||||||
version = "0.11.2"
|
version = "0.11.2"
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
use reqwest::blocking as reqwest;
|
use reqwest::blocking as reqwest;
|
||||||
use crate::errors::Error;
|
use crate::errors::Error;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
|
mod structs;
|
||||||
use structs::{Street, Date, PickupTime};
|
use structs::{Street, Date, PickupTime};
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,17 +39,16 @@ pub fn search_streets(street_name: String) -> Result<Vec<Street>, Error> {
|
||||||
)),
|
)),
|
||||||
};
|
};
|
||||||
|
|
||||||
let output: Vec<Street> = Vec::new();
|
let mut output: Vec<Street> = Vec::new();
|
||||||
|
|
||||||
// We iterate over every item and extract the needed data
|
// We iterate over every item and extract the needed data
|
||||||
for map in data.iter() {
|
for map in data.iter() {
|
||||||
let value = map.get("value");
|
if let Some(value) = map.get("value") {
|
||||||
let index = value.find("(");
|
match Street::try_from(value) {
|
||||||
|
Ok(street) => output.push(street),
|
||||||
match index {
|
Err(_) => continue,
|
||||||
None
|
}
|
||||||
}
|
}
|
||||||
let street = value[ ..index ].trim();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(output)
|
Ok(output)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::convert::From;
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
|
|
||||||
/// Represents a street
|
/// Represents a street
|
||||||
|
@ -7,8 +7,20 @@ pub struct Street {
|
||||||
city: String,
|
city: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<String> for Street {
|
impl TryFrom<&String> for Street {
|
||||||
|
type Error = ();
|
||||||
|
|
||||||
|
fn try_from(value: &String) -> Result<Self, Self::Error> {
|
||||||
|
if let Some(index) = value.find('(') {
|
||||||
|
Ok(Street {
|
||||||
|
name: (value[0 .. index - 1].trim()).to_string(),
|
||||||
|
city: (value[index + 1 .. value.len() - 1].trim()).to_string(),
|
||||||
|
})
|
||||||
|
|
||||||
|
}else {
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,13 +10,8 @@ pub fn routes() -> Vec<rocket::Route> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// URL: https://www.ivago.be/nl/particulier/autocomplete/garbage/streets?q=Lange
|
// URL: https://www.ivago.be/nl/particulier/autocomplete/garbage/streets?q=Lange
|
||||||
#[get("/search?<street>")]
|
#[get("/search?<street>", format="json")]
|
||||||
pub fn search_streets(street: String) -> String {
|
pub fn search_streets(street: String) -> String {
|
||||||
// // Build the request
|
|
||||||
// let mut request = Request::get(
|
|
||||||
// "https://www.ivago.be/nl/particulier/autocomplete/garbage/streets")
|
|
||||||
// .body(())
|
|
||||||
// .unwrap();
|
|
||||||
|
|
||||||
// let response = send(request.body(()).unwrap());
|
// let response = send(request.body(()).unwrap());
|
||||||
"".to_string()
|
"".to_string()
|
||||||
|
|
Loading…
Reference in New Issue