Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Hilfe bei Skripte von request auf httpGet umbauen

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    Hilfe bei Skripte von request auf httpGet umbauen

    This topic has been deleted. Only users with topic management privileges can see it.
    • Negalein
      Negalein Global Moderator @liv-in-sky last edited by

      @liv-in-sky sagte in Hilfe bei Skripte von request auf httpGet umbauen:

      ersetzen

      Ahh, gecheckt.

      liv-in-sky 1 Reply Last reply Reply Quote 0
      • liv-in-sky
        liv-in-sky @Negalein last edited by

        @negalein sagte in Hilfe bei Skripte von request auf httpGet umbauen:

        @liv-in-sky sagte in Hilfe bei Skripte von request auf httpGet umbauen:

        versuche mal das

        in welche DP schreibt das Script??
        Im Original steht in 3. Zeile noch const dpPrices = "0_userdata.0.IQ_Sprit.IQ_Sprit";. Kann ich das so 1:1 ins Neue übernehmen?

        moment - ich muss noch was bei dem iq script ändern

        1 Reply Last reply Reply Quote 0
        • liv-in-sky
          liv-in-sky @Negalein last edited by

          @negalein

          neuer versuch

          der daten punkt ist ja im script definiert und sollte auch von dir angelegt sein (type text)

          //hier bitte konfigurieren
          //datenpunkt sollte vor skriptstart bereits existieren und mit Typ Text erstellt worden sein
          const dpPrices = "0_userdata.0.IQ_Sprit.IQ_Sprit";
          let user = "xxxxxxxxxx";
          let pass = "xxxxxxxxxx";
          
          //ab hier nix verändern
          const axios = require('axios');
          const cheerio = require("cheerio");
          
          let $;
          async function main() {
          
          const optionsLogin = {
           method: 'POST',
           url: 'https://netservice.iqcard.at/de/login',
           data: `BENUID=${user}&PASSWT=${pass}&login-form-submit=login`,
           headers: {
             'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
             'Accept-Encoding': 'gzip, deflate, br',
             'Accept-Language': 'de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7',
             'Cache-Control': 'no-cache',
             'Content-Type': 'application/x-www-form-urlencoded',
             'DNT': '1',
             'Origin': 'https://netservice.iqcard.at',
             'Pragma': 'no-cache',
             'Sec-CH-UA': '"Not?A_Brand";v="8", "Chromium";v="108", "Google Chrome";v="108"',
             'Sec-CH-UA-Mobile': '?0',
             'Sec-CH-UA-Platform': '"Windows"',
             'Sec-Fetch-Dest': 'empty',
             'Sec-Fetch-Mode': 'cors',
             'Sec-Fetch-Site': 'same-origin',
             'Upgrade-Insecure-Requests': '1',
             'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36',
             'Cookie': 'cAccept=true; NETSERVICE=true; IQCARDPASSWT=; IQCARDBENUID= ',
             'Referer': 'https://netservice.iqcard.at/de/kunden'
           },
           maxRedirects: 5, // Anzahl der zu folgenden Redirects
           withCredentials: true // für das Cookie-Handling
          };
          
          const optionsPriceinfo = {
           method: 'GET',
           url: 'https://netservice.iqcard.at/de/netservice_preisinfo',
           headers: {
             'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
             'Accept-Encoding': 'gzip, deflate, br',
             'Accept-Language': 'de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7',
             'Cache-Control': 'no-cache',
             'DNT': '1',
             'Origin': 'https://netservice.iqcard.at',
             'Pragma': 'no-cache',
             'Sec-CH-UA': '"Not?A_Brand";v="8", "Chromium";v="108", "Google Chrome";v="108"',
             'Sec-CH-UA-Mobile': '?0',
             'Sec-CH-UA-Platform': '"Windows"',
             'Sec-Fetch-Dest': 'empty',
             'Sec-Fetch-Mode': 'cors',
             'Sec-Fetch-Site': 'same-origin',
             'Sec-Fetch-User': '?1',
             'Upgrade-Insecure-Requests': '1',
             'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36',
             'Referer': 'https://netservice.iqcard.at/de/netservice'
           },
           maxRedirects: 5, // Anzahl der zu folgenden Redirects
           withCredentials: true // für das Cookie-Handling
          };
          
          // Anmeldung mit POST-Request
          axios(optionsLogin)
           .then(() => {
             // Erfolgreiche Anmeldung, jetzt GET-Request für Preisinfo
             return axios(optionsPriceinfo);
           })
           .then(response => {
             // Verarbeitung der Antwort
             const data = analyze(response.data);
             log(data);
             writeDatapoint(data);
           })
           .catch(error => {
             console.error('Error making the request:', error);
           });
          function writeDatapoint(data) {
            log("write dpPrices");
            setState(dpPrices,JSON.stringify(data));
          }
          }
          main()
          
          function analyze(body) {
           $ = cheerio.load(body);
           let countrys = $(".row > div > fieldset");
           let data = {}
           for (var i = 1; i < countrys.length; i++) {
             let country = getCountry(countrys[i]);
             data[country.countryname] = country;
           }
           return data;
          }
          function getCountry(country) {
           let data = {};
           data.services = {};
           data.info = "";
           data.countryname = $(country).find("> legend").text().trim();
           let sections = $(country).find(".panel .panel-heading");
           for (var i = 0; i < sections.length; i++) {
             let section = $(sections[i]);
             let title = section.text().trim();
             let fields = $(section.next().find("fieldset"));
             if (fields.length > 0) {
               data.services[title] = getGasPrices(fields);
             } else {
               data.services[title] = getOtherServices(section.next());
             }
           }
           if (sections.length == 0) data.info = $(country).contents().filter((i, el) => el.nodeType == 3).text().trim();
           return data;
          }
          function getGasPrices(fields) {
           let data = [];
           for (var i = 0; i < fields.contents().length; i++) {
             let field = fields.contents()[i];
             if (field.nodeType == 3 && field.data.replace(/\s/gm, "") != "") {
               let date = field.data.replace(/\s/gm, "");
               let price = $(field).next().text();
               data.push({ date: date, price: price });
             }
           }
           return data;
          }
          function getOtherServices(fields) {
           return fields.text().trim();
          }  
          
          
          schedule("59 * * * *", async function () {
            main();   
          });
          
          

          Negalein 1 Reply Last reply Reply Quote 0
          • Latzi
            Latzi last edited by

            weiterer Ansatz zum IQ-Script:
            IQ-Bash-Script

            Negalein 1 Reply Last reply Reply Quote 1
            • Negalein
              Negalein Global Moderator @liv-in-sky last edited by

              @liv-in-sky sagte in Hilfe bei Skripte von request auf httpGet umbauen:

              neuer versuch

              funktioniert leider nicht

              javascript.1
              2024-05-27 19:42:00.907	error	Invalid read function for "alias.0.IQ-Sprit.Diesel.Zeitraum.Zeitraum": "JSON.parse(val)['ÖSTERREICH'].services.Diesel[0].date" => Cannot read properties of undefined (reading 'services')
              
              javascript.1
              2024-05-27 19:42:00.905	error	Invalid read function for "alias.0.IQ-Sprit.Diesel.Preis.IQ_Sprit": "JSON.parse(val)['ÖSTERREICH'].services.Diesel[0].price" => Cannot read properties of undefined (reading 'services')
              
              web.0
              2024-05-27 19:42:00.906	error	Invalid read function for "alias.0.IQ-Sprit.Diesel.Zeitraum.Zeitraum": "JSON.parse(val)['ÖSTERREICH'].services.Diesel[0].date" => Cannot read properties of undefined (reading 'services')
              
              web.0
              2024-05-27 19:42:00.906	error	Invalid read function for "alias.0.IQ-Sprit.Diesel.Preis.IQ_Sprit": "JSON.parse(val)['ÖSTERREICH'].services.Diesel[0].price" => Cannot read properties of undefined (reading 'services')
              
              web.0
              2024-05-27 19:42:00.906	error	Invalid read function for "alias.0.IQ-Sprit.Diesel.Preis.IQ_Sprit": "JSON.parse(val)['ÖSTERREICH'].services.Diesel[0].price" => Cannot read properties of undefined (reading 'services')
              
              web.0
              2024-05-27 19:42:00.905	error	Invalid read function for "alias.0.IQ-Sprit.Diesel.Zeitraum.Zeitraum": "JSON.parse(val)['ÖSTERREICH'].services.Diesel[0].date" => Cannot read properties of undefined (reading 'services')
              
              javascript.0
              2024-05-27 19:42:00.905	error	Invalid read function for "alias.0.IQ-Sprit.Diesel.Zeitraum.Zeitraum": "JSON.parse(val)['ÖSTERREICH'].services.Diesel[0].date" => Cannot read properties of undefined (reading 'services')
              
              javascript.0
              2024-05-27 19:42:00.905	error	Invalid read function for "alias.0.IQ-Sprit.Diesel.Preis.IQ_Sprit": "JSON.parse(val)['ÖSTERREICH'].services.Diesel[0].price" => Cannot read properties of undefined (reading 'services')
              
              history.0
              2024-05-27 19:42:00.904	error	Invalid read function for "alias.0.IQ-Sprit.Diesel.Zeitraum.Zeitraum": "JSON.parse(val)['ÖSTERREICH'].services.Diesel[0].date" => Cannot read properties of undefined (reading 'services')
              
              history.0
              2024-05-27 19:42:00.904	error	Invalid read function for "alias.0.IQ-Sprit.Diesel.Preis.IQ_Sprit": "JSON.parse(val)['ÖSTERREICH'].services.Diesel[0].price" => Cannot read properties of undefined (reading 'services')
              
              influxdb.2
              2024-05-27 19:42:00.904	error	Invalid read function for "alias.0.IQ-Sprit.Diesel.Zeitraum.Zeitraum": "JSON.parse(val)['ÖSTERREICH'].services.Diesel[0].date" => Cannot read properties of undefined (reading 'services')
              
              influxdb.2
              2024-05-27 19:42:00.904	error	Invalid read function for "alias.0.IQ-Sprit.Diesel.Preis.IQ_Sprit": "JSON.parse(val)['ÖSTERREICH'].services.Diesel[0].price" => Cannot read properties of undefined (reading 'services')
              
              influxdb.0
              2024-05-27 19:42:00.904	error	Invalid read function for "alias.0.IQ-Sprit.Diesel.Zeitraum.Zeitraum": "JSON.parse(val)['ÖSTERREICH'].services.Diesel[0].date" => Cannot read properties of undefined (reading 'services')
              
              influxdb.0
              2024-05-27 19:42:00.904	error	Invalid read function for "alias.0.IQ-Sprit.Diesel.Preis.IQ_Sprit": "JSON.parse(val)['ÖSTERREICH'].services.Diesel[0].price" => Cannot read properties of undefined (reading 'services')
              

              dc96e9c4-c535-42e9-a958-0f05c85dc0de-image.png

              liv-in-sky 1 Reply Last reply Reply Quote 0
              • Negalein
                Negalein Global Moderator @Latzi last edited by

                @latzi sagte in Hilfe bei Skripte von request auf httpGet umbauen:

                weiterer Ansatz zum IQ-Script:

                hast du das in Verwendung?

                Ist das ein normales JS?

                Latzi liv-in-sky 2 Replies Last reply Reply Quote 0
                • Latzi
                  Latzi @Negalein last edited by

                  @negalein
                  Ja, das verwende ich.
                  Nein, ist ein Bash-Script (so wie das Wetterstation-Script von SBORG), wird am Server ausgeführt

                  1 Reply Last reply Reply Quote 0
                  • liv-in-sky
                    liv-in-sky @Negalein last edited by

                    @negalein

                    das sind keinen axios fehler - da ist ein problem mit dem datenpunkt

                    du könntest mir deinenaccount geben und ich teste es mal bei mir - wenn ja,dann über chat

                    1 Reply Last reply Reply Quote 0
                    • liv-in-sky
                      liv-in-sky @Negalein last edited by liv-in-sky

                      @negalein

                      also : der zugriff funktioniert, aber das auslesen kann nicht funktionieren - weißt du noch, wo du das script her hast - und lief das schon mal ?

                      das script von @latzi verstehe ich un dkann es auch nachvollziehen - dein script schau ich mir morgen früh nochmal an

                      der unterschied ist der - dein script versucht die linken daten zu bekommen (was nicht wirklich funktioniert, weil das über ein internes script angezeigt wird

                      das von latzi liest die rechten werte aus (schwarzer hintergrund)

                      Image 001.png

                      Latzi 1 Reply Last reply Reply Quote 0
                      • Latzi
                        Latzi @liv-in-sky last edited by

                        @liv-in-sky
                        das Script funktionierte und kommt von hier

                        liv-in-sky 2 Replies Last reply Reply Quote 0
                        • liv-in-sky
                          liv-in-sky @Latzi last edited by

                          @latzi

                          ich kucke morgen nochmal - braucht etwas hirnpower

                          1 Reply Last reply Reply Quote 1
                          • liv-in-sky
                            liv-in-sky @Latzi last edited by

                            @latzi @Negalein @OliverIO

                            vielleicht hat der ersteller lust, da nochmal draufzuschauen

                            https://forum.iobroker.net/post/907470

                            Negalein OliverIO 2 Replies Last reply Reply Quote 0
                            • Negalein
                              Negalein Global Moderator @liv-in-sky last edited by

                              @liv-in-sky sagte in Hilfe bei Skripte von request auf httpGet umbauen:

                              vielleicht hat der ersteller lust, da nochmal draufzuschauen

                              Hab Oliver im Ursprungsthread geschrieben.

                              Ah, seh gerade, dass du ihn eh verlinkt hast.

                              liv-in-sky 1 Reply Last reply Reply Quote 0
                              • liv-in-sky
                                liv-in-sky @Negalein last edited by

                                @negalein

                                wäre cool, wenn er hilft, er hat def mehr ahnung von solchen abfragen 🙂

                                1 Reply Last reply Reply Quote 0
                                • Negalein
                                  Negalein Global Moderator @liv-in-sky last edited by

                                  @liv-in-sky sagte in Hilfe bei Skripte von request auf httpGet umbauen:

                                  dann sudo crontab -e öffnen und folgenden eintrag eingeben: */1 * * * * /usr/local/bin/httptest

                                  muss danach rebootet werden, oder läuft der Cron gleich los?

                                  liv-in-sky 2 Replies Last reply Reply Quote 0
                                  • liv-in-sky
                                    liv-in-sky @Negalein last edited by

                                    @negalein
                                    Läuft sofort los

                                    Negalein 1 Reply Last reply Reply Quote 1
                                    • liv-in-sky
                                      liv-in-sky @Negalein last edited by

                                      @negalein
                                      Ob alles richtig ist stellst du am besten so fest
                                      Gehe ins Verzeichnis und rufe einfach httptest auf, dann siehst du was passiert

                                      Negalein 1 Reply Last reply Reply Quote 1
                                      • Negalein
                                        Negalein Global Moderator @liv-in-sky last edited by

                                        @liv-in-sky sagte in Hilfe bei Skripte von request auf httpGet umbauen:

                                        Läuft sofort los

                                        Ok, DP ändert sich nicht.

                                        der Port bei der ioB-IP ist eh der normale (8081 in meinem Fall)?

                                        1 Reply Last reply Reply Quote 0
                                        • Negalein
                                          Negalein Global Moderator @liv-in-sky last edited by Negalein

                                          @liv-in-sky sagte in Hilfe bei Skripte von request auf httpGet umbauen:

                                          Gehe ins Verzeichnis und rufe einfach httptest auf, dann siehst du was passiert

                                          pi@raspberrypi:~ $ cd /usr/local/bin/
                                          pi@raspberrypi:/usr/local/bin $ httptest
                                          Warning: Failed to read curl-format.txt/usr/local/bin/httptest: command substitution: Zeile 4: Syntaxfehler beim unerwarteten Wort `|'
                                          /usr/local/bin/httptest: command substitution: Zeile 4: `| awk '{print $2}' | sed -e 's/s//''
                                          Warning: Failed to read curl-format.txtcurl: no URL specified!
                                          curl: try 'curl --help' or 'curl --manual' for more information
                                          /usr/local/bin/httptest: Zeile 6: http://10.0.1.93/middleware.php/data.json?from=now&uuid[]=bc3edcd0-24c4-11ea-b257-bdbd9553c516&uuid[]=deda8550-24c4-11ea-b402-275ee0956365: Datei oder Verzeichnis nicht gefunden
                                          /usr/local/bin/httptest: Zeile 5: iobroker: Kommando nicht gefunden.
                                          Warning: Failed to read curl-format.txtcurl: no URL specified!
                                          curl: try 'curl --help' or 'curl --manual' for more information
                                          /usr/local/bin/httptest: Zeile 8: http://10.0.1.93/middleware.php/data.json?from=now&uuid[]=bc3edcd0-24c4-11ea-b257-bdbd9553c516&uuid[]=deda8550-24c4-11ea-b402-275ee0956365: Datei oder Verzeichnis nicht gefunden
                                          /usr/local/bin/httptest: Zeile 7: iobroker: Kommando nicht gefunden.
                                          Warning: Failed to read curl-format.txtcurl: no URL specified!
                                          curl: try 'curl --help' or 'curl --manual' for more information
                                          /usr/local/bin/httptest: Zeile 10: http://10.0.1.93/middleware.php/data.json?from=now&uuid[]=bc3edcd0-24c4-11ea-b257-bdbd9553c516&uuid[]=deda8550-24c4-11ea-b402-275ee0956365: Datei oder Verzeichnis nicht gefunden
                                          /usr/local/bin/httptest: Zeile 9: iobroker: Kommando nicht gefunden.
                                          /usr/local/bin/httptest: Zeile 11: iobroker: Kommando nicht gefunden.
                                          pi@raspberrypi:/usr/local/bin $
                                          
                                          
                                          liv-in-sky 1 Reply Last reply Reply Quote 0
                                          • OliverIO
                                            OliverIO @liv-in-sky last edited by

                                            @liv-in-sky

                                            Ich schau einmal.
                                            Allerdings gelten die erwähnten Herausforderungen im Post
                                            https://forum.iobroker.net/topic/60747/daten-aus-pw-geschützte-website/20?_=1716846281603

                                            Request kann das alles in der vorliegenden Form.
                                            Axios nur mit diversen zusatzbibliotheken. (Stichwort cookie jar und automatischer redirect), bzw mit relativ viel zusätzlichem code.

                                            Request ist immer noch keine schlechte Bibliothek
                                            Sie ist depecated, da der maintainer keine neuen Features mehr hinzufügen möchte.
                                            Vgl. auch diesen post

                                            https://github.com/request/request/issues/3142

                                            mikeal created this issue in request/request

                                            open Request’s Past, Present and Future #3142

                                            liv-in-sky 1 Reply Last reply Reply Quote 1
                                            • First post
                                              Last post

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            896
                                            Online

                                            31.9k
                                            Users

                                            80.1k
                                            Topics

                                            1.3m
                                            Posts

                                            16
                                            132
                                            9452
                                            Loading More Posts
                                            • Oldest to Newest
                                            • Newest to Oldest
                                            • Most Votes
                                            Reply
                                            • Reply as topic
                                            Log in to reply
                                            Community
                                            Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                                            The ioBroker Community 2014-2023
                                            logo