From ce3cf003ffb5c2b0806e4cc548b80b0f0100b4af Mon Sep 17 00:00:00 2001 From: Stefan Menner Date: Tue, 27 May 2025 15:43:44 +0200 Subject: [PATCH] Change metadata --- .vscode/launch.json | 45 + Cargo.toml | 16 + snipped.html | 76 ++ src/main.rs | 155 +++ src/test.html | 8 + src/types/mod.rs | 2 + src/types/types.rs | 0 src/util/cmd.rs | 3 + src/util/mod.rs | 2 + test.html | 2212 +++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 2519 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 Cargo.toml create mode 100644 snipped.html create mode 100644 src/main.rs create mode 100644 src/test.html create mode 100644 src/types/mod.rs create mode 100644 src/types/types.rs create mode 100644 src/util/cmd.rs create mode 100644 src/util/mod.rs create mode 100644 test.html diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..0913323 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,45 @@ +{ + // Verwendet IntelliSense zum Ermitteln möglicher Attribute. + // Zeigen Sie auf vorhandene Attribute, um die zugehörigen Beschreibungen anzuzeigen. + // Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "lldb", + "request": "launch", + "name": "Debug executable 'no-man-sky'", + "cargo": { + "args": [ + "build", + "--bin=no-man-sky", + "--package=no-man-sky" + ], + "filter": { + "name": "no-man-sky", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in executable 'no-man-sky'", + "cargo": { + "args": [ + "test", + "--no-run", + "--bin=no-man-sky", + "--package=no-man-sky" + ], + "filter": { + "name": "no-man-sky", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..f717115 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "no-man-sky" +version = "0.1.0" +edition = "2024" +publish = ["merlin"] +description = "Utility functions to read environment with fallback and values from a file" +license = "MIT" +repository = "ssh://git@gitea.merlinserver.de:2222/Stefan/merlin_env_helper.git" + +[dependencies] +ego-tree = "0.10.0" +env_logger = "0.11.8" +log = "0.4.27" +merlin_env_helper = { version = "0.2.0", registry = "merlin" } +reqwest = {version="0.12.15", features=["blocking"]} +scraper = "0.23.1" diff --git a/snipped.html b/snipped.html new file mode 100644 index 0000000..bd0aa35 --- /dev/null +++ b/snipped.html @@ -0,0 +1,76 @@ + + + + + + + + + Diwasserstoff + +x1  +   + + + + + + + + + Sauerstoff + +x1  →   + + + + + + + + + Salz + +x1   +( "Schnelle Formation/Verdunstung", 0,08 sek./Stück) diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..f473b14 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,155 @@ +use std::{fs::File, io::{Read}}; + +use scraper::{ElementRef, Node}; +use ego_tree::NodeRef; + +fn main() -> Result<(), Box> { + env_logger::init(); + let html = read("test.html")?; + parse(&html)?; + Ok(()) +} + + +fn _download_file(url: &str, _path: &str) -> Result> { + // Some simple CLI args requirements... + + eprintln!("Fetching {url:?}..."); + + // reqwest::blocking::get() is a convenience function. + // + // In most cases, you should create/build a reqwest::Client and reuse + // it for all requests. + let res = reqwest::blocking::get(url)?; + + + let body = res.text()?; + Ok(body) +} + +fn read(path: &str) -> Result { + let mut file = File::open(path)?; + let mut contents = String::new(); + file.read_to_string(&mut contents)?; + Ok(contents) +} + +fn parse(html: &str) -> Result> { + // Parse the HTML content + let document = scraper::Html::parse_document(html); + let selector_quelle = scraper::Selector::parse("#Quelle").unwrap(); + let selector_verwendung = scraper::Selector::parse("#Verwendung").unwrap(); + let selector_li = scraper::Selector::parse("li").unwrap(); + + let elt_quelle= document.select(&selector_quelle).next(); + + if elt_quelle.is_none() { + eprintln!("No element found with the selector '#Quelle'"); + return Ok(false); + } + + let elt_quelle = elt_quelle.unwrap(); + + let mut elt_quelle = elt_quelle.parent().unwrap(); + + let mut c = 0; + let mut elt_ul = None; + + while elt_quelle. next_sibling().is_some() { + + elt_quelle = elt_quelle.next_sibling().unwrap(); + + if !elt_quelle.value().is_element(){ + continue; + } + + let elt = elt_quelle.value().as_element().unwrap(); + if elt.name() == "ul" { + c += 1; + + if c > 1 { + elt_ul = Some(elt_quelle); + break; + } + } + + if elt.name() == "h2" { + eprintln!("Found 'h2' element, stopping search for 'ul'"); + break; + } + } + + if elt_ul.is_none() { + eprintln!("No second 'ul' element found after '#Quelle'"); + return Ok(false); + } + let elt_ul = ElementRef::wrap(elt_ul.unwrap()).unwrap(); + let li = elt_ul.select(&selector_li); + + for item in li + { + parse_li_to_resource(item); + } + + let elt_verwendung= document.select(&selector_verwendung).next(); + + if elt_verwendung.is_none() { + eprintln!("No element found with the selector '#Verwendung'"); + return Ok(false); + } + + let elt_verwendung = elt_verwendung.unwrap(); + + Ok(true) +} + +fn parse_li_to_resource(item: ElementRef<'_>) { + if !item.has_children() { + println!("Item has no children, skipping."); + return; + } + + let mut resource_items = Vec::new(); + + let first_child = item.first_child().unwrap(); + + resource_items.push(first_child); + + let iter = first_child.next_siblings(); + + for next in iter { + if next.value().is_text() { + resource_items.push(next); + } + else if next.value().is_element() { + if next.value().as_element().unwrap().name() == "span" { + parse_resource (resource_items); + resource_items = Vec::new(); + } + + resource_items.push(next); + } + } + + println!("======================"); +} + +fn parse_resource(resource_items: Vec>) { + if resource_items.is_empty() { + println!("No resource items to parse."); + return; + } + + println!("Parsing resource items..."); + + for item in resource_items { + if item.value().is_text() { + println!("Text: {}", item.value().as_text().unwrap().text.trim_ascii()); + continue; + } + println!("Resource: {:?}", item.value()); + } + + println!("------------------"); + +} \ No newline at end of file diff --git a/src/test.html b/src/test.html new file mode 100644 index 0000000..c85b448 --- /dev/null +++ b/src/test.html @@ -0,0 +1,8 @@ + + + + + diff --git a/src/types/mod.rs b/src/types/mod.rs new file mode 100644 index 0000000..3623f41 --- /dev/null +++ b/src/types/mod.rs @@ -0,0 +1,2 @@ +pub mod types; +pub use types::*; \ No newline at end of file diff --git a/src/types/types.rs b/src/types/types.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/util/cmd.rs b/src/util/cmd.rs new file mode 100644 index 0000000..c906655 --- /dev/null +++ b/src/util/cmd.rs @@ -0,0 +1,3 @@ +pub fn parse_command_line_args() -> Vec { + std::env::args().skip(1).collect() +} \ No newline at end of file diff --git a/src/util/mod.rs b/src/util/mod.rs new file mode 100644 index 0000000..aeab241 --- /dev/null +++ b/src/util/mod.rs @@ -0,0 +1,2 @@ +pub mod cmd; +pub use cmd::*; \ No newline at end of file diff --git a/test.html b/test.html new file mode 100644 index 0000000..019348a --- /dev/null +++ b/test.html @@ -0,0 +1,2212 @@ + + + + +Salz – No Man's Sky Wiki + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+
+ + +
+ + + No Man's Sky Wiki + + +
+
+ + +
+ +
+
+
+ +
+
+
+
+ +
+
+
Advertisement
+
+
+
+ + +
+
+
+
+ + + +
+
+ + +
+ +
+ + + + + + + +
+
+ + +
+ + +
Das Thema dieses Artikels ist aus dem Waypoint Update.
Die Informationen aus diesem Artikel sind auf dem Stand vom 21. Februar 2023.
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Salz +
Salz +
Kategorie +Erde +
Typ +Aquatisches Mineral-Extrakt +
Seltenheit +Häufig +
Bauplan Wert +101,0 +
Verwendet für +Bauen, Herstellen, Aufladung +
Symbol +NaCl +
Aktualisiert +Waypoint +
+ +

Salz ist eine Ressource. +

+ + +

Zusammenfassung[]

+

Salz (NaCl) ist eine Ressource und eines der Erdelemente. +

+

Spielbeschreibung[]

+

Ein natürlich vorkommendes Salz, das man in großen Mengen in Unterwassermineralien findet. +

Kann in einer Raffinerie zur Herstellung von Chlor verarbeitet werden. Diese veredelte Form wird zur Herstellung hochentwickelter Produkte und Technologien verwendet. +

+

Quelle[]

+ +

Salz kann mit den folgenden Bestandteilen in einer Raffinerie raffiniert werden: +

+
    +
  • Chlor x1  →   Salz x2  ("Salzproduktion", 0,24 sek./Stück)
  • Diwasserstoff x1  +   Sauerstoff x1  →   Salz x1  ("Schnelle Formation/Verdunstung", 0,08 sek./Stück)
+

Verwendung[]

+

Herstellung[]

+

Salz wird nicht als Bestandteil für die Herstellung verwendet. +

+

Raffination[]

+

Salz wird als Bestandteil in einer Raffinerie zur Raffination der folgenden Produkte verwendet: +

+ +

Kochen[]

+

Salz wird nicht als Zutat in einem Nährstoffprozessor zum Kochen verwendet. +

+

Zusätzliche Informationen[]

+

Salz ist ein sehr wertvolles Mineral, und der Abbau von unterirdischen Mineralablagerungen kann zu einer äußerst lukrativen Farm führen. +

+

Versionsgeschichte[]

+
  • NEXT - Als Ressource hinzugefügt.
  • +
  • Visions - Versteckte Änderungen: Die Informationstafel verfügt über ein zusätzliches Symbol, das die Verwendung angibt.
  • +
  • Waypoint - Wert geändert, war vorher 299,0.
+

Galerie[]

+ + + + + + +
+ +
+ + + +
+ +
+
+
Advertisement
+
+
+ +
+ + + + + + + + + \ No newline at end of file