Finished first version of search_streets

master
Jef Roosens 2021-03-12 00:16:48 +01:00
parent ab31a5e471
commit 4032800d64
Signed by: Jef Roosens
GPG Key ID: 955C0660072F691F
5 changed files with 23 additions and 49 deletions

33
Cargo.lock generated
View File

@ -134,19 +134,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "cipher"
version = "0.2.5"
@ -632,25 +619,6 @@ dependencies = [
"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]]
name = "num_cpus"
version = "1.13.0"
@ -915,7 +883,6 @@ dependencies = [
name = "rust-api"
version = "0.1.0"
dependencies = [
"chrono",
"reqwest",
"rocket",
]

View File

@ -8,7 +8,6 @@ edition = "2018"
[dependencies]
rocket = "0.4.7"
chrono = "0.4.19"
[dependencies.reqwest]
version = "0.11.2"

View File

@ -1,7 +1,9 @@
use reqwest::blocking as reqwest;
use crate::errors::Error;
use std::collections::HashMap;
use std::convert::TryFrom;
mod structs;
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
for map in data.iter() {
let value = map.get("value");
let index = value.find("(");
match index {
None
if let Some(value) = map.get("value") {
match Street::try_from(value) {
Ok(street) => output.push(street),
Err(_) => continue,
}
}
let street = value[ ..index ].trim();
}
Ok(output)

View File

@ -1,4 +1,4 @@
use std::convert::From;
use std::convert::TryFrom;
/// Represents a street
@ -7,8 +7,20 @@ pub struct Street {
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(())
}
}
}

View File

@ -10,13 +10,8 @@ pub fn routes() -> Vec<rocket::Route> {
}
// 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 {
// // 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());
"".to_string()