Frage zu Regex - Punkt-Komma / löschen umwandeln

Begonnen von rasti, 13 August 2020, 16:09:18

Vorheriges Thema - Nächstes Thema

rasti



Hallo,

ich lade mit folgender Definition eine Website ein:


define GOLD HTTPMOD https://www.godmode-trader.de/rohstoffe/gold-xaueur-spot-rate-preis,10414724 900
attr GOLD userattr reading01Format reading01Name reading01OExpr reading01RegOpt reading01Regex
attr GOLD enableControlSet 1
attr GOLD group Edelmetalle
attr GOLD reading01Name gold
attr GOLD reading01OExpr $val =~ s/,/\./g;; ;;$val;;
attr GOLD reading01RegOpt s
attr GOLD reading01Regex data-precision="2">([\s\S]*?)<\/td>
attr GOLD room Krypto
attr GOLD stateFormat gold €
attr GOLD timeout 10


und mit dem hier:

attr GOLD reading01OExpr $val =~ s/,/\./g;; ;;$val;;


wird dann in z.B. 1.638,48 das Komma durch einen Punkt ersetzt.

Ergebnis ist also 1.638.48

Ich hätte aber gerne 1638.48, die obige Zeile soll also so umgeändert werden,
dass der erste Punkt gelöscht und das Komma in einen Punkt umgewandelt wird.

Wie muss der Ausdruck geändert werden, damit auch noch der Punkt verschwindet?

Viele Grüße

Ralf


TomLee

attr GOLD reading01OExpr $val =~ s/[.]//g;;$val =~ s/,/\./g;;$val;;

Mein Bauchgefühl sagt mir aber das das Gebastel ist und es mit Sicherheit anders angegegangen wird.

Gruß

Thomas

rasti

Super vielen Dank das funktioniert
(Gebastel hin oder her ;D)

Christian72D

Funktioniert das so bei euch noch?
Ich bekomme nur "gold €" angezeigt.

Der Link an sich ist ja noch gültig, ansonsten kapiere ich httpmod nicht. :)

Kaufe

Hi,

zum einen wurde wohl der LINK geändert,
curl "https://www.godmode-trader.de/rohstoffe/gold-xaueur-spot-rate-preis,10414724"
Redirecting to <a href="/rohstoffe/xaueur-preis,10414724">/rohstoffe/xaueur-preis,10414724


zum anderen ist wohl auch der Regex nicht mehr Gültig.
data-precision gibt es nicht mehr im HTML. Ich bin auch gerade am testen wie ich das wieder ans laufen bekomme.

Gruß Kaufe
FHEM 6.0 Raspberry PI-3B-Bullseye| HauptFHEM Server (Graphana,MariaDB)
FHEM 6.0 Raspberry PI-3B-Bullseye| FHEM2FHEM, 1-Wire (Ds9490R  + 50 DS18B20)
FHEM 6.0 Raspberry PI-3B-Bullseye| FHEM2FHEM, 1-Wire (Ds9490R  + 5 DS18B20)
RaspberrMatic 3.61.7.20211218 (ca 65 HM Devices)

Kaufe

Ah, nun läuft es @Christian72D

define GOLD HTTPMOD https://www.godmode-trader.de/rohstoffe/xaueur-preis,10414724 600
attr GOLD userattr reading01Format reading01Name reading01RegOpt
attr GOLD group Edelmetalle
attr GOLD reading01Name gold
attr GOLD reading01OExpr $val =~ s/[,]//g;;$val;;
attr GOLD reading01RegOpt s
attr GOLD reading01Regex <title>([\s\S]*?)[ ]
attr GOLD room 12 Finance
attr GOLD stateFormat gold €
attr GOLD timeout 10
attr GOLD webCmd reread


Ich hole mir den Wert nun vom title.
FHEM 6.0 Raspberry PI-3B-Bullseye| HauptFHEM Server (Graphana,MariaDB)
FHEM 6.0 Raspberry PI-3B-Bullseye| FHEM2FHEM, 1-Wire (Ds9490R  + 50 DS18B20)
FHEM 6.0 Raspberry PI-3B-Bullseye| FHEM2FHEM, 1-Wire (Ds9490R  + 5 DS18B20)
RaspberrMatic 3.61.7.20211218 (ca 65 HM Devices)

betateilchen

alternativ:


defmod goldpreis HTTPMOD https://www.godmode-trader.de/rohstoffe/xaueur-preis,10414724 3600
attr goldpreis reading01Name state
attr goldpreis reading01OExpr $val=~s/,//g;;$val=~s/\./,/;;"$val €";;
attr goldpreis reading01Regex <title>(.*).\(


Bevor jemand fragt: nein, ich habe stateFormat nicht vergessen :)
-----------------------
Formuliere die Aufgabe möglichst einfach und
setze die Lösung richtig um - dann wird es auch funktionieren.
-----------------------
Lesen gefährdet die Unwissenheit!