Skip to content
  • Home
  • Recent
  • Tags
  • 0 Unread 0
  • Categories
  • Unreplied
  • Popular
  • GitHub
  • Docu
  • Hilfe
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
ioBroker Logo

Community Forum

donate donate
  1. ioBroker Community Home
  2. Deutsch
  3. Skripten / Logik
  4. Frage: function array zurückgeben, bzw. request(

NEWS

  • Jahresrückblick 2025 – unser neuer Blogbeitrag ist online! ✨
    BluefoxB
    Bluefox
    16
    1
    1.6k

  • Neuer Blogbeitrag: Monatsrückblick - Dezember 2025 🎄
    BluefoxB
    Bluefox
    13
    1
    853

  • Weihnachtsangebot 2025! 🎄
    BluefoxB
    Bluefox
    25
    1
    2.1k

Frage: function array zurückgeben, bzw. request(

Scheduled Pinned Locked Moved Skripten / Logik
20 Posts 7 Posters 5.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • BluefoxB Offline
    BluefoxB Offline
    Bluefox
    wrote on last edited by
    #11
    function getColor(tendenz) {
    	//tendenz von -1 zu 1
    	var farbe;
    
    	if (tendenz > 0) {
    		// green
    		if (tendenz > 1) tendenz = 1;
    
    		// damit man überchaupt farbe sieht schieben wir tendenz von 0-1 Bereich auf 0.3-1 Bereich
    		tendenz = tendenz * 0.7 + 0.3; 
    
    		farbe = Math.round(0xFF * tendenz) << 8; // RGB, wir brauchen GG von #RRGGBB
            farbe = farbe.toString(16);
            if (farbe.length < 4) farbe = '0' + farbe;
            farbe = '#00' + farbe;
    	} else {
    		// Rot
    		if (tendenz < -1) tendenz = -1;
    		tendenz *= -1; // mach aus -0.7 ein 0.7
    
    		// damit man überchaupt farbe sieht schieben wir tendenz von 0-1 Bereich auf 0.3-1 Bereich
    		tendenz = tendenz * 0.7 + 0.3; 
    
    		farbe = Math.round(255 * tendenz) << 16; // RGB, wir brauchen RR von 0xRRGGBB
            farbe = farbe.toString(16);
            if (farbe.length < 6) farbe = '0' + farbe;
            farbe = '#' + farbe;
    	}
    	return farbe;
    }
    
    function getTransparentColor(tendenz) {
    	var farbe;
       	if (tendenz > 0) {
    		// green
    		if (tendenz > 1) tendenz = 1;
    
    		// damit man überchaupt farbe sieht schieben wir tendenz von 0-1 Bereich auf 0.3-1 Bereich
    		tendenz = tendenz * 0.7 + 0.3; 
    
            return 'rgba(0,255,0,' +  tendenz.toFixed(2) + ')';
        } else {
    		// Rot
    		if (tendenz < -1) tendenz = -1;
    		tendenz *= -1; // mach aus -0.7 ein 0.7
    
    		// damit man überchaupt farbe sieht schieben wir tendenz von 0-1 Bereich auf 0.3-1 Bereich
    		tendenz = tendenz * 0.7 + 0.3;
    
            return 'rgba(255,0,0,' + tendenz.toFixed(2) + ')';
        }
    }
    
    log(getTransparentColor(0.5));
    
    1 Reply Last reply
    0
    • P Offline
      P Offline
      pix
      wrote on last edited by
      #12

      Hallo Bluefox,

      das funktioniert hervorragend. Genauso hatte ich mir das vorgestellt.

      Folgende Objekte werden erstellt:

      DAX (Dax in Punkten)

      DAX.Tendenz (Tendenz in Prozent)

      DAX.Tendenz.Farbe (Farbe rot/grün je nach Tendenzrichtung und Ausschlag)

      DAX.Tendenz.Transparenz (Farbe rot/grün + Transparenz je nach Tendenzrichtung und Ausschlag)

      DAX.Tendenz.boolean (Zustand je Tendenzrichtung (negativ/positiv), nur nötig für ZustandID in Metro Tile String Widget [zB true = Bulle anzeigen, false = Bär])
      261_bildschirmfoto_2015-08-01_um_10.29.33.jpg

      Vielen Dank dafür! :D

      Gruß

      Pix

      ioBroker auf Ubuntu in Proxmox (früher Mac mini (bis OS X 10.12.6 Sierra), VIS via iOS; angeschlossen: Homematic CCU2, Homepilot 1, ConBee II, einige Wemos, Sonos, Unifi CK+Protect, Homekit, Homebridge; KEIN blockly! Github-Profil

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hofi77
        wrote on last edited by
        #13

        Hallo!

        Ich suche ebenfalls na einer Möglichkeit einige Kurse abzurufen.

        Diese Script von pix (Danke :-) )gefällt mir absolut:

        `// ########### Kurse abfragen (mehrere Aktien im Array (Test)) ###############
        createState('Aktien.DAX', {val: 0, ack: true, name: 'Deutscher Aktien Index DAX'/*, unit: 'Punkte'*/});
        createState('Aktien.DAX.Tendenz', {val: 0, ack: true, name: 'DAX Tendenz', unit: '%'});
        
        var aktien = ["AAPL","^GDAXI","PSM.DE","ALV.DE"]; // Apple, Dax, ProSieben, Allianz weitere (https://de.finance.yahoo.com/q/cp?s=%5EGDAXI)
        
        function KursEinlesen (aktie, callback) {
            var arr = [];
            var url = "http://de.finance.yahoo.com/d/quotes.csv?s=" + aktie + "&f=snl1t1p2x";
            request(url, function (err, state, body){
                if (body) {
                    //body.replace(/\n|\r/g, "");
                    body = body.substring(0,body.length-2);                             // Zeilenumbruch am Ende entfernen
                    body = body + "," + '"' + formatDate(new Date()/*, dateFormat*/) + '"' ; // und den String um das aktuelle Abfragedatum ergänzen
                    arr = body.split(",");
                    log("Aktie: " + arr,"info");    
                 callback(null, aktie, arr);
                } else {
                    log("Keine Aktienkurse gelesen", "error");  
                 callback("Keine Aktienkurse gelesen", aktie);
                }
            });
        }
        
        function leseAktienkursEnde(err, arr, aktie) {
            if (aktie) {
                for (var a = 0; a < aktie.length; a++) {
                   aktie[a] = aktie[a].replace(/"/g, ''); // oder aktie[a].substring(1, aktie[a].length - 1);
                }
                // log(JSON.stringify(aktie));
                // eingeschoben: Dax rausfiltern und speichern
                if (aktie.toString().match('DAX')) { // wenn der Wert DAX enthält
                    var dax = aktie.toString().split(","); // dann Teilen
                    setState('javascript.0.Aktien.DAX', dax[2]); // Wert nach drittem Komma abspeichern
                    setState('javascript.0.Aktien.DAX.Tendenz', dax[4].slice(0,dax[4].indexOf('%')) ); // Pos 0- Prozentzeichen
                    log('Dax ' + dax[2] + ' [' + dax[4] + '] gespeichert');
                } else {
                    // log('Aktie/Index eingelesen, aber nicht gespeichert');
                }
        
            }
        }
        
        function leseAktienkurse () {
            for (i = 0; i < aktien.length; i++) {
                KursEinlesen(aktien[i], leseAktienkursEnde);
            }
        }
        
        leseAktienkurse(); // weiter unten auch per Cron`
        
        nur schaffe ich es nicht, dass es mir die Kurse jede Minute aktualisiert.
        
        Kann mir da bitte jemand Helfen?
        
        DANKE!
        
        lg
        
        Manuel[/i]
        

        LG

        Manuel

        1 Reply Last reply
        0
        • AlCalzoneA Offline
          AlCalzoneA Offline
          AlCalzone
          Developer
          wrote on last edited by
          #14

          @hofi77:

          leseAktienkurse(); // weiter unten auch per Cron
          

          nur schaffe ich es nicht, dass es mir die Kurse jede Minute aktualisiert. `
          Ich sehe bei dir keinen Code der das tun würde. Nur den Kommentar, dass es weiter unten kommt. Hast du alles kopiert?

          Ansonsten müsste am Ende noch ein

          schedule("* * * * *", leseAktienkurse);
          

          kommen, um jede Minute zu triggern.

          Warum `sudo` böse ist: https://forum.iobroker.net/post/17109

          1 Reply Last reply
          0
          • H Offline
            H Offline
            hofi77
            wrote on last edited by
            #15

            leider ist

            leseAktienkurse(); // weiter unten auch per Cron
            

            das letzte was da steht. Da ich mich mit Scripten nicht so auskenne, dachte ich mir ich frag gleich mal nach bevor ich hier herumdocktere.

            Danke AlCalzone so klappts :-)

            Jedoch erscheint nur der DAX mit der Tendenz in den Objekten (Die Aktien sehe ich nirgends). Kannst du mir sagen warum?

            Das LOG sieht so aus:

            14:25:31.176	[info]	javascript.0 script.js.BOERSE: Aktie: "AHLA.DE","ALIBABA GR.HLDG SP.ADR 1",148.95,"2:09pm","-0.60%","GER,"14.09.2017"
            14:25:31.178	[info]	javascript.0 script.js.BOERSE: Aktie: "AAPL","Apple Inc.",159.65,"4:15pm","-0.75%","NMS,"14.09.2017"
            14:25:31.184	[info]	javascript.0 script.js.BOERSE: Aktie: "^GDAXI","DAX",12520.54,"2:10pm","-0.26%","GER,"14.09.2017"
            14:25:31.184	[info]	javascript.0 script.js.BOERSE: Dax 12520.54 [-0.26%] gespeichert
            

            Danke für deine Hilfe :-)

            LG

            Manuel

            1 Reply Last reply
            0
            • AlCalzoneA Offline
              AlCalzoneA Offline
              AlCalzone
              Developer
              wrote on last edited by
              #16

              @hofi77:

              Jedoch erscheint nur der DAX mit der Tendenz in den Objekten (Die Aktien sehe ich nirgends). Kannst du mir sagen warum? `
              Weil das genau so im Skript steht ;)

              createState('Aktien.DAX', {val: 0, ack: true, name: 'Deutscher Aktien Index DAX'/*, unit: 'Punkte'*/});
              createState('Aktien.DAX.Tendenz', {val: 0, ack: true, name: 'DAX Tendenz', unit: '%'});
              
              ...
              
              // eingeschoben: Dax rausfiltern und speichern
                      if (aktie.toString().match('DAX')) { // wenn der Wert DAX enthält
                          var dax = aktie.toString().split(","); // dann Teilen
                          setState('javascript.0.Aktien.DAX', dax[2]); // Wert nach drittem Komma abspeichern
                          setState('javascript.0.Aktien.DAX.Tendenz', dax[4].slice(0,dax[4].indexOf('%')) ); // Pos 0- Prozentzeichen
                          log('Dax ' + dax[2] + ' [' + dax[4] + '] gespeichert');
                      }
              

              Das kann man natürlich etwas verallgemeinern, aber da hab ich gerade leider keine Zeit für.

              Warum `sudo` böse ist: https://forum.iobroker.net/post/17109

              1 Reply Last reply
              0
              • B Offline
                B Offline
                brokowsky
                wrote on last edited by
                #17

                Hallo Zusammen, leider funktioniert seit einigen Tagen das Script zur Abfrage von Aktienkursen über Yahoo nicht mehr. Das Script meldet Fehler, der darauf hindeutet, dass über die Url http://de.finance.yahoo.com/d/quotes.csv?s=xxxxx keine Abfrage mehr möglich ist, anscheinend ist der Dienst eingestellt worden. Kann das jemand bestätigen und kennt jemand eine Alternative, wo/wie ich Aktien - und Währungskurse einlesen kann?

                Danke und Gruß

                Ed

                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  hofi77
                  wrote on last edited by
                  #18

                  Hallo!

                  Kann das absolut bestätigen. Anscheinend verbieten dass ihre „therms of services“. Sowas steht zumindest in der Fehlermeldung.

                  Suche auch nach einer alternative :-(

                  Lg

                  Manuel

                  LG

                  Manuel

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    pix
                    wrote on last edited by
                    #19

                    Hier gehts mit dem Parser Adapter

                    http://forum.iobroker.net/viewtopic.php … 107#p95532

                    Allerdings für den Dax-Wert. Einzelne Aktienwerte muss man sich dann selbst nach der Anleitung rausfischen. Falls man den Parser-Adapter schon für andere Dinge verwendet, empfehle ich, ein weitere Instanz nur für die Aktienkurse zu installieren.

                    Gruß

                    Pix

                    ioBroker auf Ubuntu in Proxmox (früher Mac mini (bis OS X 10.12.6 Sierra), VIS via iOS; angeschlossen: Homematic CCU2, Homepilot 1, ConBee II, einige Wemos, Sonos, Unifi CK+Protect, Homekit, Homebridge; KEIN blockly! Github-Profil

                    1 Reply Last reply
                    0
                    • HomoranH Do not disturb
                      HomoranH Do not disturb
                      Homoran
                      Global Moderator Administrators
                      wrote on last edited by
                      #20

                      @hofi77:

                      Kann das absolut bestätigen. Anscheinend verbieten dass ihre „therms of services“. Sowas steht zumindest in der Fehlermeldung. `

                      @Fehlermeldung:

                      It has come to our attention that this service is being used in violation of the Yahoo Terms of Service. As such, the service is being discontinued. For all future markets and equities data research, please refer to finance.yahoo.com. `

                      @Terms:

                      You agree to not use the Yahoo Services to:

                      upload, post, email, transmit, or otherwise make available any Content that is unlawful, harmful, threatening, abusive, harassing, tortious, defamatory, vulgar, obscene, libelous, invasive of another's privacy, hateful, or racially, ethnically, or otherwise objectionable;

                      harm minors in any way;

                      impersonate any person or entity, including, but not limited to, a Yahoo official, forum leader, guide or host, or falsely state or otherwise misrepresent your affiliation with a person or entity;

                      forge headers or otherwise manipulate identifiers in order to disguise the origin of any Content transmitted through the Yahoo Service;

                      upload, post, email, transmit, or otherwise make available any Content that you do not have a right to make available under any law or under contractual or fiduciary relationships (such as inside information, proprietary and confidential information learned or disclosed as part of employment relationships or under nondisclosure agreements);

                      upload, post, email, transmit or otherwise make available any Content that infringes any patent, trademark, trade secret, copyright or other proprietary rights ("Rights") of any party;

                      upload, post, email, transmit, or otherwise make available any unsolicited or unauthorized advertising, promotional materials, "junk mail," "spam," "chain letters," "pyramid schemes," or any other form of solicitation, except in those areas (such as shopping) that are designated for such purpose (please read our complete Spam Policy);

                      upload, post, email, transmit, or otherwise make available any material that contains software viruses or any other computer code, files or programs designed to interrupt, destroy or limit the functionality of any computer software or hardware or telecommunications equipment;

                      disrupt the normal flow of dialogue, cause a screen to "scroll" faster than other users of the Yahoo Services are able to type, or otherwise act in a manner that negatively affects other users' ability to engage in real time exchanges;

                      interfere with or disrupt the Yahoo Services or servers or networks connected to the Yahoo Services, or disobey any requirements, procedures, policies or regulations of networks connected to the Yahoo Services, including using any device, software or routine to bypass our robot exclusion headers;

                      intentionally or unintentionally violate any applicable local, state, national or international law, including, but not limited to, regulations promulgated by the U.S. Securities and Exchange Commission, any rules of any national or other securities exchange, including, without limitation, the New York Stock Exchange, the American Stock Exchange, or the NASDAQ, and any regulations having the force of law;

                      provide material support or resources (or to conceal or disguise the nature, location, source, or ownership of material support or resources) to any organization(s) designated by the United States government as a foreign terrorist organization pursuant to section 219 of the Immigration and Nationality Act;

                      "stalk" or otherwise harass another; and/or

                      collect or store personal data about other users in connection with the prohibited conduct and activities set forth in paragraphs 6.1 through 6.13 above. `

                      Habe beim querlesen da jetzt nichts gefunden, außer dem Markierten, aber z.B. beim Kachelmannwetter steht explizit, dass ein maschinelles auslesen verboten ist.

                      Bevor man anfängt Seiten automatisiert zu parsen sollte man auf jeden Fall zuerst die Terms lesen und noch besser den Betreiber fragen.

                      Gruß

                      Rainer

                      kein Support per PN! - Fragen im Forum stellen - es gibt fast nichts, was nicht auch für andere interessant ist.

                      Benutzt das Voting rechts unten im Beitrag wenn er euch geholfen hat.

                      der Installationsfixer: curl -fsL https://iobroker.net/fix.sh | bash -

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      Support us

                      ioBroker
                      Community Adapters
                      Donate

                      493

                      Online

                      32.6k

                      Users

                      82.1k

                      Topics

                      1.3m

                      Posts
                      Community
                      Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen | Einwilligungseinstellungen
                      ioBroker Community 2014-2025
                      logo
                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Home
                      • Recent
                      • Tags
                      • Unread 0
                      • Categories
                      • Unreplied
                      • Popular
                      • GitHub
                      • Docu
                      • Hilfe