[gelöst]HTTPMOD EUR/USD abfragen

Begonnen von sash.sc, 16 September 2022, 14:24:02

Vorheriges Thema - Nächstes Thema

sash.sc

Habe mir was gebaut, klappt aber nicht so wie es soll.


Internals:
   BUSY       0
   CFGFN     
   DEF        https://www.finanzen.net/devisen/dollarkurs
   FUUID      63244fef-f33f-852e-b6fa-7b0cb9dd55a1f09c
   Interval   300
   MainURL    https://www.finanzen.net/devisen/dollarkurs
   ModuleVersion 4.1.12 - 19.4.2022
   NAME       Euro_Dollar
   NOTIFYDEV  global
   NR         23312
   NTFY_ORDER 50-Euro_Dollar
   STATE      EU_Dollar: Euro_Dollar €
   TYPE       HTTPMOD
   eventCount 38
   value     
   CompiledRegexes:
   HTTPCookieHash:
     __cf_bm;/:
       Name       __cf_bm
       Options    path=/; expires=Fri, 16-Sep-22 11:47:47 GMT; domain=.wise.com; HttpOnly; Secure; SameSite=None
       Path       /
       Value      MbjTHDOdfZZgPN1_gekXGaIypYVrtFGnI8n4suATM5I-1663327067-0-AaAbukqDvIm7fJ8HSOLf4bpZR26LXqhRZ+tdjVALkYub8kFCgYxLnH0fCgiEQd6OP9woe9yTNti4HhCrh51XEixziREeR93bOsMLOR+qWvUJ
     gid;:
       Name       gid
       Options    Path=/; Domain=wise.com; Max-Age=31536000; Expires=Sat, 16 Sep 2023 11:17:47 GMT; Secure; SameSite=None; SameSite=None
       Path       
       Value      c640a1aa-901f-4c02-8e0c-e98427ef2553
     localeData;:
       Name       localeData
       Options    Max-Age=31557600; Expires=Sat, 16-Sep-2023 17:17:47 GMT; Path=/; Secure; SameSite=None
       Path       
       Value      de
   HttpUtils:
     NAME       
     addr       https://www.finanzen.net:443
     auth       0
     buf       
     code       200
     compress   1
     conn       
     data       
     displayurl https://www.finanzen.net/devisen/dollarkurs
     header     Cookie: __cf_bm=MbjTHDOdfZZgPN1_gekXGaIypYVrtFGnI8n4suATM5I-1663327067-0-AaAbukqDvIm7fJ8HSOLf4bpZR26LXqhRZ+tdjVALkYub8kFCgYxLnH0fCgiEQd6OP9woe9yTNti4HhCrh51XEixziREeR93bOsMLOR+qWvUJ; gid=c640a1aa-901f-4c02-8e0c-e98427ef2553; localeData=de
     host       www.finanzen.net
     httpheader HTTP/1.0 200 OK
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/10.0
Feature-Policy: geolocation 'none'; midi 'none'; camera 'none'; usb 'none'; magnetometer 'none'; accelerometer 'none'; gyroscope 'none'; microphone 'none'; payment 'none'
Referrer-Policy: same-origin
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Content-Encoding: gzip
Content-Length: 64357
Cache-Control: private, max-age=48
Date: Fri, 16 Sep 2022 12:20:24 GMT
Connection: close
Vary: Accept-Encoding
     httpversion 1.0
     hu_blocking 0
     hu_filecount 1
     hu_port    443
     hu_portSfx
     ignoreredirects 1
     loglevel   4
     path       /devisen/dollarkurs
     protocol   https
     redirects  0
     timeout    2
     url        https://www.finanzen.net/devisen/dollarkurs
     sslargs:
   OLDREADINGS:
   QUEUE:
   READINGS:
   REQUEST:
     context    reading
     data       
     header     
     ignoreredirects 0
     num        unknown
     retryCount 0
     type       update
     url        https://www.finanzen.net/devisen/dollarkurs
   defptr:
     readingBase:
       Euro_Dollar reading
     readingNum:
       Euro_Dollar 01
     readingOutdated:
     requestReadings:
       update:
         Euro_Dollar reading 01
Attributes:
   enableControlSet 1
   reading01Name Euro_Dollar
   reading01OExpr $val =~ s/\,/./g; return $val;
   reading01Regex (\d+\.\d+\,\d+).*USD
   room       HTTPMOD
   stateFormat EU_Dollar: Euro_Dollar €


Wie muß ich die regex abändern. habe es mit regex101 versucht klappt aber auch nicht wirklich.

Danke
Sascha
Raspi 4B+ Bullseye ;LaCrosse; HomeMatic; MapleCUL; ZigBee; Signalduino ESP32 ; Shellys; MQTT2; Grafana mit Influxdb

betateilchen

Zitat von: sash.sc am 16 September 2022, 14:24:02
habe es mit regex101 versucht klappt aber auch nicht wirklich.

klappt wunderbar...


defmod test1 HTTPMOD https://www.finanzen.net/devisen/dollarkurs
attr test1 reading01Name Euro_Dollar
attr test1 reading01OExpr $val=~s/\,/./g;; return $val
attr test1 reading01Regex Euro.{6}(\d+,\d+)
-----------------------
Formuliere die Aufgabe möglichst einfach und
setze die Lösung richtig um - dann wird es auch funktionieren.
-----------------------
Lesen gefährdet die Unwissenheit!

sash.sc

#2
Seit kurzem klappt die Abfrage auf der Seite nicht mehr. Hat jemand eine Idee warum und was ich ändern muss?


BUSY       0
   DEF        https://www.finanzen.net/devisen/dollarkurs
   FUUID      63244fef-f33f-852e-b6fa-7b0cb9dd55a1f09c
   FVERSION   98_HTTPMOD.pm:0.265330/2022-10-13
   Interval   300
   MainURL    https://www.finanzen.net/devisen/dollarkurs
   ModuleVersion 4.1.14 - 19.8.2022
   NAME       Euro_Dollar
   NOTIFYDEV  global
   NR         615
   NTFY_ORDER 50-Euro_Dollar
   STATE      EUR_Dollar: 1.0538 €
   TYPE       HTTPMOD
   eventCount 5
   value     
   CompiledRegexes:
   HttpUtils:
     NAME       
     addr       https://www.finanzen.net:443
     auth       0
     buf       
     code       200
     compress   1
     conn       
     data       
     displayurl https://www.finanzen.net/devisen/dollarkurs
     header     
     host       www.finanzen.net
     httpheader HTTP/1.0 200 OK
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/10.0
Feature-Policy: geolocation 'none'; midi 'none'; camera 'none'; usb 'none'; magnetometer 'none'; accelerometer 'none'; gyroscope 'none'; microphone 'none'; payment 'none'
Referrer-Policy: same-origin
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Content-Encoding: gzip
Cache-Control: private, max-age=1
Date: Wed, 28 Dec 2022 20:11:35 GMT
Content-Length: 59568
Connection: close
Vary: Accept-Encoding
     httpversion 1.0
     hu_blocking 0
     hu_filecount 1
     hu_port    443
     hu_portSfx
     ignoreredirects 1
     loglevel   4
     path       /devisen/dollarkurs
     protocol   https
     redirects  0
     timeout    2
     url        https://www.finanzen.net/devisen/dollarkurs
     sslargs:
   QUEUE:
   READINGS:
     2022-12-08 16:15:42   Euro_Dollar     1.0538
   REQUEST:
     context    reading
     data       
     header     
     ignoreredirects 0
     num        unknown
     retryCount 0
     type       update
     url        https://www.finanzen.net/devisen/dollarkurs
Attributes:
   comment    # Euro.{6}(\d+,\d+)
   reading01Name Euro_Dollar
   reading01OExpr $val=~s/\,/./g;; return $val
   reading01Regex Dollarkurs.[\n\w\W]*?(\d+\,\d+) USD
   room       HTTPMOD
   stateFormat EUR_Dollar: Euro_Dollar €



Gruß
Sascha
Raspi 4B+ Bullseye ;LaCrosse; HomeMatic; MapleCUL; ZigBee; Signalduino ESP32 ; Shellys; MQTT2; Grafana mit Influxdb

OdfFhem

Zitat von: sash.sc am 27 Dezember 2022, 09:35:30
Seit kurzem klappt die Abfrage auf der Seite nicht mehr. Hat jemand eine Idee warum und was ich ändern muss?

Ich verwende derzeit folgenden, regulären Ausdruck:

attr test1 reading01Regex Dollarkurs.*snapshot-value-fst-current-0.*<span>([\d,]*)<\/span>.*USD.*snapshot-value-fst-absolute-0


Reading "Euro_Dollar" wird aktuell mit 1.0661 gefüllt:

setstate test1 2022-12-30 04:14:03 Euro_Dollar 1.0661

sash.sc

Raspi 4B+ Bullseye ;LaCrosse; HomeMatic; MapleCUL; ZigBee; Signalduino ESP32 ; Shellys; MQTT2; Grafana mit Influxdb

sash.sc

Zitat von: OdfFhem am 30 Dezember 2022, 04:16:24
Ich verwende derzeit folgenden, regulären Ausdruck:

attr test1 reading01Regex Dollarkurs.*snapshot-value-fst-current-0.*<span>([\d,]*)<\/span>.*USD.*snapshot-value-fst-absolute-0


Reading "Euro_Dollar" wird aktuell mit 1.0661 gefüllt:

setstate test1 2022-12-30 04:14:03 Euro_Dollar 1.0661



Kannst du mal bitte deine gabe Definition der Abfrage hier posten?
Raspi 4B+ Bullseye ;LaCrosse; HomeMatic; MapleCUL; ZigBee; Signalduino ESP32 ; Shellys; MQTT2; Grafana mit Influxdb

OdfFhem

Zitat von: sash.sc am 30 Dezember 2022, 14:58:35
Kannst du mal bitte deine gabe Definition der Abfrage hier posten?
Kann ich natürlich machen - allerdings erst am Abend ...

sash.sc

Raspi 4B+ Bullseye ;LaCrosse; HomeMatic; MapleCUL; ZigBee; Signalduino ESP32 ; Shellys; MQTT2; Grafana mit Influxdb

OdfFhem

Interessant, es scheint sich schon wieder was geändert zu haben ...


defmod waehrung HTTPMOD none
attr waehrung get01Name Euro2Dollar
attr waehrung get01Poll 1
attr waehrung get01URL https://www.finanzen.net/devisen/dollarkurs
attr waehrung get02Name Dollar2Euro
attr waehrung get02Poll 1
attr waehrung get02URL https://www.finanzen.net/devisen/eurokurs
attr waehrung reading01Name Euro2Dollar
attr waehrung reading01OExpr $val=~s/\,/./g;; return $val
attr waehrung reading01Regex Dollarkurs[\n\w\W]*snapshot-value-fst-current-0[\n\w\W]*<span>([\d,]*)<\/span>[\n\w\W]*USD[\n\w\W]*snapshot-value-fst-absolute-0
attr waehrung reading02Name Dollar2Euro
attr waehrung reading02OExpr $val=~s/\,/./g;; return $val
attr waehrung reading02Regex Eurokurs[\n\w\W]*snapshot-value-fst-current-0[\n\w\W]*<span>([\d,]*)<\/span>[\n\w\W]*EUR[\n\w\W]*snapshot-value-fst-absolute-0
attr waehrung room Test
attr waehrung showBody 0
attr waehrung showError 1
attr waehrung showMatched 1
attr waehrung stateFormat 1€=[$name:Euro2Dollar]$ ... [$name:MATCHED_READINGS:t] ... 1$=[$name:Dollar2Euro]€
attr waehrung webCmd reread

setstate waehrung 1€=1.0697$ ... 2022-12-30 20:18:56 ... 1$=0.9347€
setstate waehrung 2022-12-30 20:18:56 Dollar2Euro 0.9347
setstate waehrung 2022-12-30 20:18:55 Euro2Dollar 1.0697
setstate waehrung 2022-12-30 20:18:56 LAST_REQUEST get02
setstate waehrung 2022-12-30 20:18:56 MATCHED_READINGS Dollar2Euro

sash.sc

Dollar/Euro Abfrage funktioniert wieder.

Was mache ich bei 2 Zeilen, wie Erdgaspreis oder Rohöl ??

Gruß und Danke
Sascha
Raspi 4B+ Bullseye ;LaCrosse; HomeMatic; MapleCUL; ZigBee; Signalduino ESP32 ; Shellys; MQTT2; Grafana mit Influxdb

OdfFhem

Zitat von: sash.sc am 30 Dezember 2022, 23:05:54
Was mache ich bei 2 Zeilen, wie Erdgaspreis oder Rohöl ??

Ich weiss noch nicht genau, was Du meinst?

Ist das Auslesen von Erdgaspreis bzw. Rohölpreis das Problem ? (wenn ja, dann wäre der Link notwendig)
Oder geht es um das Attribut stateFormat ? (wenn ja, bitte Deine Definition zeigen)
Oder einfach Problem näher erläutern ...

sash.sc

#11
Ich meine die 2. Zeile wie im Bild auslesen !
Von Brent den Ölpreis ! In diesem Fall die 80,35€
1. Zeile wird ausgelesen.

Hier die Def

Internals:
   BUSY       0
   DEF        https://www.finanzen.net/rohstoffe/oelpreis/euro
   FUUID      6310e2e4-f33f-852e-ed1e-e74cc46347091eba
   FVERSION   98_HTTPMOD.pm:0.265330/2022-10-13
   Interval   60
   MainURL    https://www.finanzen.net/rohstoffe/oelpreis/euro
   ModuleVersion 4.1.14 - 19.8.2022
   NAME       rohoel
   NOTIFYDEV  global
   NR         612
   NTFY_ORDER 50-rohoel
   STATE      Brentöl: 75.25 €
   TYPE       HTTPMOD
   eventCount 22
   value     
   CompiledRegexes:
   HttpUtils:
     NAME       
     addr       https://www.finanzen.net:443
     auth       0
     buf       
     code       200
     compress   1
     conn       
     data       
     displayurl https://www.finanzen.net/rohstoffe/oelpreis/euro
     header     
     host       www.finanzen.net
     httpheader HTTP/1.0 200 OK
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/10.0
Feature-Policy: geolocation 'none'; midi 'none'; camera 'none'; usb 'none'; magnetometer 'none'; accelerometer 'none'; gyroscope 'none'; microphone 'none'; payment 'none'
Referrer-Policy: same-origin
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Content-Encoding: gzip
Content-Length: 41203
Cache-Control: private, max-age=56
Date: Sat, 31 Dec 2022 10:03:05 GMT
Connection: close
Vary: Accept-Encoding
     httpversion 1.0
     hu_blocking 0
     hu_filecount 1
     hu_port    443
     hu_portSfx
     ignoreredirects 1
     loglevel   4
     path       /rohstoffe/oelpreis/euro
     protocol   https
     redirects  0
     timeout    2
     url        https://www.finanzen.net/rohstoffe/oelpreis/euro
     sslargs:
   QUEUE:
   READINGS:
     2022-09-01 18:52:10   attrTemplateVersion 20201129
     2022-12-31 11:03:05   brent           75.25
   REQUEST:
     context    reading
     data       
     header     
     ignoreredirects 0
     num        unknown
     retryCount 0
     type       update
     url        https://www.finanzen.net/rohstoffe/oelpreis/euro
   defptr:
     readingBase:
       brent      reading
     readingNum:
       brent      01
     readingOutdated:
     requestReadings:
       update:
         brent      reading 01
Attributes:
   comment    Brent:[\w\W\n]*?(\d+\,\d+)
   enableControlSet 1
   reading01Name brent
   reading01OExpr $val =~ s/\,/./g; return $val;
   reading01Regex Ölpreis[\n\n\w\W]*snapshot-value-fst-current-0[\n\w\W]*<span>([\d,]*)<\/span>[\n\w\W]*EUR[\n\w\W]*snapshot-value-fst-absolute-0
   room       HTTPMOD
   stateFormat Brentöl: brent €


Gruß
Sascha
Raspi 4B+ Bullseye ;LaCrosse; HomeMatic; MapleCUL; ZigBee; Signalduino ESP32 ; Shellys; MQTT2; Grafana mit Influxdb

OdfFhem

Hier wird die erste Zeile ausgelesen (index 0 ; 75,25)

Ölpreis[\n\w\W]*snapshot-value-fst-current-0[\n\w\W]*<span>([\d,]*)<\/span>[\n\w\W]*EUR[\n\w\W]*snapshot-value-fst-absolute-0


Hier wird die zweite Zeile ausgelesen (index 1 ; 80,35)

Ölpreis[\n\w\W]*snapshot-value-fst-current-1[\n\w\W]*<span>([\d,]*)<\/span>[\n\w\W]*EUR[\n\w\W]*snapshot-value-fst-absolute-1


sash.sc

Raspi 4B+ Bullseye ;LaCrosse; HomeMatic; MapleCUL; ZigBee; Signalduino ESP32 ; Shellys; MQTT2; Grafana mit Influxdb