reverse ordering, fix duplicate output
This commit is contained in:
+8
-3
@@ -1,5 +1,5 @@
|
|||||||
use anyhow::{bail, Context, Result};
|
use anyhow::{bail, Context, Result};
|
||||||
use scraper::{Html, Selector};
|
use scraper::{ElementRef, Html, Selector};
|
||||||
|
|
||||||
pub(crate) struct Extractor {
|
pub(crate) struct Extractor {
|
||||||
pub time: Selector,
|
pub time: Selector,
|
||||||
@@ -28,8 +28,13 @@ impl Extractor {
|
|||||||
Selector::parse("span.late").unwrap()
|
Selector::parse("span.late").unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_departures<'a>(&'a self, html: &'a Html) -> scraper::html::Select<'a, 'a> {
|
pub(crate) fn get_departures<'a>(&'a self, html: &'a Html) -> impl Iterator<Item = ElementRef> {
|
||||||
html.select(&self.departure)
|
// `Select` does not implement DoubleEndedIterator, so we need to collect it first
|
||||||
|
let mut result = html.select(&self.departure).collect::<Vec<_>>();
|
||||||
|
result.reverse();
|
||||||
|
// we seem to extract the blocks twice with slightly different layout, so we discard half of them
|
||||||
|
result.truncate(result.len() / 2);
|
||||||
|
result.into_iter()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_transport_line(departure_block: scraper::ElementRef) -> Result<&str> {
|
pub(crate) fn get_transport_line(departure_block: scraper::ElementRef) -> Result<&str> {
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
|
|
||||||
pub(crate) const SIEDLUNG: &str =
|
pub(crate) const SIEDLUNG: &str =
|
||||||
"https://www.vvo-online.de/de/fahrplan/aktuelle-abfahrten-ankuenfte/abfahrten?stopid=33006764";
|
"https://www.vvo-online.de/de/fahrplan/aktuelle-abfahrten-ankuenfte/abfahrten?stopid=33006765";
|
||||||
|
|
||||||
pub(crate) fn query_server() -> Result<String> {
|
pub(crate) fn query_server() -> Result<String> {
|
||||||
match ureq::get(SIEDLUNG).call() {
|
match ureq::get(SIEDLUNG).call() {
|
||||||
|
|||||||
Reference in New Issue
Block a user