reverse ordering, fix duplicate output

This commit is contained in:
Dr. Matthias Ratajczak
2022-12-15 17:09:53 +01:00
parent 8071319571
commit 2fb19f497b
2 changed files with 9 additions and 4 deletions
+8 -3
View File
@@ -1,5 +1,5 @@
use anyhow::{bail, Context, Result};
use scraper::{Html, Selector};
use scraper::{ElementRef, Html, Selector};
pub(crate) struct Extractor {
pub time: Selector,
@@ -28,8 +28,13 @@ impl Extractor {
Selector::parse("span.late").unwrap()
}
pub(crate) fn get_departures<'a>(&'a self, html: &'a Html) -> scraper::html::Select<'a, 'a> {
html.select(&self.departure)
pub(crate) fn get_departures<'a>(&'a self, html: &'a Html) -> impl Iterator<Item = ElementRef> {
// `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> {
+1 -1
View File
@@ -1,7 +1,7 @@
use anyhow::{anyhow, Result};
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> {
match ureq::get(SIEDLUNG).call() {