Notdienst Apotheke

Begonnen von Vaddi, 24 April 2018, 01:39:35

Vorheriges Thema - Nächstes Thema

Vaddi

Hey, folgendes sollte funktionieren.
attr NotdienstApotheke reading06Name DatumVon
attr NotdienstApotheke reading06Regex <p>Notdienst\n.*vom([ 0-9.:&#;;_-]+)
attr NotdienstApotheke reading07Name UhrzeitVon
attr NotdienstApotheke reading07Regex <p>Notdienst\n.*vom.*um([ 0-9.:&#;;_-]+)
attr NotdienstApotheke reading08Name DatumBis
attr NotdienstApotheke reading08Regex <span>([ a-zA-Z0-9.:&#;;_-]+)um
attr NotdienstApotheke reading09Name UhrzeitBis
attr NotdienstApotheke reading09Regex <span>.*um([ 0-9:&#;;_-]+)

attr NotdienstApotheke userReadings NotName NotdienstVon NotdienstBis NotdienstTelefon NotdienstAdresse DatumVon UhrzeitVon DatumBis UhrzeitBis


Wie ich bereits erwähnt habe, bin ich absolut kein Profi in Sachen Regex, der von mir gepostete
Code darf also gerne verbessert werden ;)
fhem auf RPi 3
HM-MOD-RPI-PCB sowie 433mhz Sender
Mehrere HM und 433mhz Produkte

stefanpf

Zitat von: Christoph Morrison am 29 April 2018, 00:39:05

Und man bekommt eine JSON-kodierte Liste aller gerade aktuellen Notdienstapotheken um 33330 Gütersloh (durch eigene Daten ersetzen), ganz ohne nervige tag soup.
Besserwisser  ;)
Finde ich gut...Motivation hat ausgereicht sich tiefergehend mit Httpmod zu beschäftigen.

defmod NotdienstApotheke2 HTTPMOD http://apothekenfinder.mobi/interface/json.php?device=web&source=not&search=32361 0
attr NotdienstApotheke2 userattr get01Encode get01JSON get01Name get02ExtractAllJSON:0,1 getURL reading01Encode reading01JSON reading01Name reading02JSON reading02Name reading03JSON reading03Name reading04JSON reading04Name reading05JSON reading05Name reading06JSON reading06Name reading07JSON reading07Name reading07OExpr reading08JSON reading08Name reading08OExpr reading09JSON reading09Name reading10JSON reading10Name reading11JSON reading11Name readingEncode requestHeader requestHeader1 requestHeader2 requestHeader3 requestHeader4 requestHeader5 requestHeader6 requestHeader7
attr NotdienstApotheke2 enableControlSet 1
attr NotdienstApotheke2 reading01Encode UTF-8
attr NotdienstApotheke2 reading01JSON result_01_name
attr NotdienstApotheke2 reading01Name Name
attr NotdienstApotheke2 reading02JSON result_01_street
attr NotdienstApotheke2 reading02Name Strasse
attr NotdienstApotheke2 reading03JSON result_01_plz
attr NotdienstApotheke2 reading03Name Plz
attr NotdienstApotheke2 reading04JSON result_01_place
attr NotdienstApotheke2 reading04Name Ort
attr NotdienstApotheke2 reading05JSON result_01_number
attr NotdienstApotheke2 reading05Name Telefon
attr NotdienstApotheke2 reading06JSON result_01_fax
attr NotdienstApotheke2 reading06Name Telefax
attr NotdienstApotheke2 reading07JSON result_01_start
attr NotdienstApotheke2 reading07Name Beginn
attr NotdienstApotheke2 reading07OExpr strftime "%a %e.%m.%Y %H:%M", localtime($val)
attr NotdienstApotheke2 reading08JSON result_01_end
attr NotdienstApotheke2 reading08Name Ende
attr NotdienstApotheke2 reading08OExpr strftime "%a %e.%m.%Y %H:%M", localtime($val)
attr NotdienstApotheke2 reading09JSON result_01_lng
attr NotdienstApotheke2 reading09Name Längengrad
attr NotdienstApotheke2 reading10JSON result_01_lat
attr NotdienstApotheke2 reading10Name Breitengrad
attr NotdienstApotheke2 reading11JSON result_01_distance
attr NotdienstApotheke2 reading11Name Entfernung
attr NotdienstApotheke2 readingEncode UTF-8
attr NotdienstApotheke2 requestHeader2 Accept-Encoding: gzip, deflate
attr NotdienstApotheke2 requestHeader3 Accept-Language: de-DE,de;;q=0.9,en-US;;q=0.8,en;;q=0.7,fr;;q=0.6
attr NotdienstApotheke2 requestHeader4 User-Agent: Lynx/2.8.8dev.3 libwww-FM/2.14 SSL-MM/1.4.1
attr NotdienstApotheke2 requestHeader5 Referer: http://apothekenfinder.mobi/
attr NotdienstApotheke2 requestHeader6 X-Requested-With: XMLHttpRequest
attr NotdienstApotheke2 requestHeader7 Connection: keep-alive
attr NotdienstApotheke2 showBody 0
attr NotdienstApotheke2 stateFormat Name, Telefon, Strasse in Plz Ort
attr NotdienstApotheke2 verbose 0



Macht doch mit JSON mehr Spaß. 

MoneyBox76

Bin Aufruf der URL: http://apothekenfinder.mobi/interface/json.php?device=web&source=not&search=32361 bekomme ich keine Daten zurück. ich gehe mal davon  aus, dass 32361 eine PLZ ist.

Ausgabe:
{"result":"","status":"0"}

Wie hast Du die URL herausgefunden?

Christoph Morrison

Zitat von: MoneyBox76 am 03 Mai 2018, 17:08:12
Bin Aufruf der URL: http://apothekenfinder.mobi/interface/json.php?device=web&source=not&search=32361 bekomme ich keine Daten zurück. ich gehe mal davon  aus, dass 32361 eine PLZ ist.

Ausgabe:
{"result":"","status":"0"}

Wie hast Du die URL herausgefunden?

Über die Chrome Entwicklertools. Für apothekenfinder muss das so aussehen, als würde man einen XHR-Request machen, deshalb auch die anderen Header.

Wolle02

Hallo,

vielen Dank für den Codeschnipsel. Ich habe ihn bei mir erfolgreich eingebaut. Naja, erfolgreich heißt von der grundsätzlichen Funktionalität her; jedoch habe ich bei der Darstellung ein kleines Problem.

Wenn ich die eigentliche Website aufrufe bekomme ich für heute die Notdienstapotheken angezeigt, die ich als Apo_Bild1 angefügt habe.

In FHEM wird mir das Ergebnis aber wie im angefügten Apo_Bild2 angezeigt.

Das heißt die erste Notdienstapotheke wird mir als Name und Telefonnummer angezeigt, die Adresse stammt aber von der zweiten Notdienstapotheke

Ich habe schon versucht im Quelltext der Seite etwas zu finden, an dem ich einen Unterschied feststellen kann. Aber die HTML-Tags sind beides mal die gleichen:
<div class="search_results"><div class="box_search_pharmacy"><div class="box_result_abstract"><h2>Wir haben 19 Notdienstapotheken im Umkreis gefunden.</h2><form method="post" action="/service/notdienstapotheke-finden/suchergebnis/0/Stuttgart/Friedrich-Ebert-Str%2B19.html"><fieldset><label>Suche verfeinern:</label><select name="location_alternative"><option value="32f89a4d89b275a673b0a99119e4fc28">70191, Stuttgart&nbsp;Mönchhalde&nbsp;Friedrich-Ebert-Straße</option><option value="c64350a1790d48d34a25aa8afc818453">70191, Stuttgart&nbsp;Stuttgart-Nord&nbsp;Friedrich-Ebert-Straße</option><option value="b86126f34351bc81dc4a5a33e8a059ab">70191, Stuttgart&nbsp;Weißenhof&nbsp;Friedrich-Ebert-Straße</option></select><input class="refresh" type="submit" value="" id="submit_refresh_data"/></fieldset></form><ul class="search_date"><li class="enhanced"><a href="/service/notdienstapotheke-finden/erweiterte_suche.html">erweiterte Suche</a></li><li class="date"><span style="color:#E2001A;">Jetzt</span><a class="tomorrow" href="/service/notdienstapotheke-finden/suchergebnis/26.05.2018/Stuttgart/Friedrich-Ebert-Str%2B19.html" title="Notdienstbeginn am 26.05.2018">26.05.2018</a></li><li class="new_search"><a href="/service/notdienstapotheke-finden/neue_suche.html">neue Suche</a></li></ul><div class="clearer"></div></div><div class="box_result_list teaser_list"><div id="map_canvas"><p style="text-align: center; padding-top: 160px;">Damit die Übersichtskarte angezeigt werden kann, aktivieren Sie bitte Javascript in Ihrem Browser!</p></div><div class="box_category_switcher"><div class="line"></div><div class="clearer"></div></div><div class="box_adress"><h2>Anemonen-Apotheke</h2><p class="distance">Entfernung:
                    2,40 km
                </p><p>Notdienst
                    vom 26.05.2018 um 08:30 Uhr
                   
                    bis <span>27.05.2018 um 08:30 Uhr.</span></p><h3>Kontakt</h3><p class="adress">Haußmannstr. 136<br/>70188 Stuttgart<br/><a href="                            http://reiseauskunft.bahn.de/bin/query.exe/dn?Z=70188+Stuttgart+Hau%C3%9Fmannstr.+136&amp;ZADR=1&amp;dbkanal_004=L01_S01_D001_KPK0097_LZ01                    " target="_blank" title="mit Bus / Bahn erreichen"><img style="vertical-align: middle;width: 18px;display: inline;margin-right: 5px;" alt="mit Bus / Bahn erreichen" src="https://cd6.aponet.de/fileadmin/aponet/mobile/img/layout/DB_Logobox_4c_50.jpg"/>
                    mit Bus / Bahn erreichen
                    </a></p><p class="contact">Tel.:
                        0711 2623814<br/>Fax:
                        0711 2868337</p><div class="line"></div></div><div class="box_adress"><h2>Apotheke am Berliner Platz</h2><p class="distance">Entfernung:
                    2,55 km
                </p><p>Notdienst
                    vom 26.05.2018 um 08:30 Uhr
                   
                    bis <span>27.05.2018 um 08:30 Uhr.</span></p><h3>Kontakt</h3><p class="adress">Fritz-Elsas-Str. 51<br/>70174 Stuttgart<br/><a href="                            http://reiseauskunft.bahn.de/bin/query.exe/dn?Z=70174+Stuttgart+Fritz-Elsas-Str.+51&amp;ZADR=1&amp;dbkanal_004=L01_S01_D001_KPK0097_LZ01                    " target="_blank" title="mit Bus / Bahn erreichen"><img style="vertical-align: middle;width: 18px;display: inline;margin-right: 5px;" alt="mit Bus / Bahn erreichen" src="https://cd6.aponet.de/fileadmin/aponet/mobile/img/layout/DB_Logobox_4c_50.jpg"/>
                    mit Bus / Bahn erreichen
                    </a></p><p class="contact">Tel.:
                        0711 6153707<br/>Fax:
                        0711 6153762</p><div class="line"></div></div><div class="box_adress"><h2>Freiberg-Apotheke</h2><p class="distance">Entfernung:
                    5,13 km


Kann mir das eventuell jemand erklären und mir einen Tip geben, wie ich die Daten der ersten (mit der kürzesten Entfernung) Apotheke angezeigt bekomme?

Danke und Gruß
Wolle


pwlr

Moin,

eine gute Anwendung, habe ich sofort in den Test genommen ! Danke !

ZitatDas heißt die erste Notdienstapotheke wird mir als Name und Telefonnummer angezeigt, die Adresse stammt aber von der zweiten Notdienstapotheke

Das Problem hatte ich gestern auch, allerdings war die Adresse von der 3. Apotheke aus der Liste. Heute ist wieder alles ok !
Komisch - was kann das sein ? Es gab ja ein paar Code-Updates und ich habe vielleicht etwas übersehen ???

Die Version mit JSON hat keine Probleme gehabt.

Moin
Bernd

Vaddi

Hallo zusammen.
Das er bei dir, Wolle02, die Adresse von der zweiten Apotheke nimmt, liegt an dem ß
im Straßennamen. Hatte ich wohl im meinem Codeschnipsel nicht berücksichtigt.
Um den Fehler zu beheben, bitte attr NotdienstApotheke reading05Regex ändern in:

attr NotdienstApotheke reading05Regex <p class="adress">([\sa-zA-Z0-9äöüÄÖÜß.&#;;_-]+)<br\/>([\s0-9a-zA-ZäöüÄÖÜ]+)

Dann sollte es funktionieren.
fhem auf RPi 3
HM-MOD-RPI-PCB sowie 433mhz Sender
Mehrere HM und 433mhz Produkte

Wolle02

Hach, wenn man weiß wonach man suchen muss, kann es ja so einfach sein. Rückblickend betrachtet hätte ich da auch selber drauf kommen können.  ;D

Vielen Dank Vaddi. Der Vaddi ist halt der Beste  ;)

Gruß
Wolle

Christoph Morrison

Nehmt wirklich lieber die JSON-Variante. Das Tag-Soup-Geparse ist doch nichts ordentliches.

Kusselin

Servus Zusammen,

habe mal ein bissl rumgespielt und das auf meinem Testsystem installiert- funzt aber nicht so.
habe hier siesen Code von User stenapf genommen....die http adresse gegen meine getauscht:
defmod NotdienstApotheke2 HTTPMOD http://meine PLZ

attr NotdienstApotheke2 userattr get01Encode get01JSON get01Name get02ExtractAllJSON:0,1 getURL reading01Encode reading01JSON reading01Name reading02JSON reading02Name reading03JSON reading03Name reading04JSON reading04Name reading05JSON reading05Name reading06JSON reading06Name reading07JSON reading07Name reading07OExpr reading08JSON reading08Name reading08OExpr reading09JSON reading09Name reading10JSON reading10Name reading11JSON reading11Name readingEncode requestHeader requestHeader1 requestHeader2 requestHeader3 requestHeader4 requestHeader5 requestHeader6 requestHeader7
attr NotdienstApotheke2 enableControlSet 1
attr NotdienstApotheke2 reading01Encode UTF-8
attr NotdienstApotheke2 reading01JSON result_01_name
attr NotdienstApotheke2 reading01Name Name
attr NotdienstApotheke2 reading02JSON result_01_street
attr NotdienstApotheke2 reading02Name Strasse
attr NotdienstApotheke2 reading03JSON result_01_plz
attr NotdienstApotheke2 reading03Name Plz
attr NotdienstApotheke2 reading04JSON result_01_place
attr NotdienstApotheke2 reading04Name Ort
attr NotdienstApotheke2 reading05JSON result_01_number
attr NotdienstApotheke2 reading05Name Telefon
attr NotdienstApotheke2 reading06JSON result_01_fax
attr NotdienstApotheke2 reading06Name Telefax
attr NotdienstApotheke2 reading07JSON result_01_start
attr NotdienstApotheke2 reading07Name Beginn
attr NotdienstApotheke2 reading07OExpr strftime "%a %e.%m.%Y %H:%M", localtime($val)
attr NotdienstApotheke2 reading08JSON result_01_end
attr NotdienstApotheke2 reading08Name Ende
attr NotdienstApotheke2 reading08OExpr strftime "%a %e.%m.%Y %H:%M", localtime($val)
attr NotdienstApotheke2 reading09JSON result_01_lng
attr NotdienstApotheke2 reading09Name Längengrad
attr NotdienstApotheke2 reading10JSON result_01_lat
attr NotdienstApotheke2 reading10Name Breitengrad
attr NotdienstApotheke2 reading11JSON result_01_distance
attr NotdienstApotheke2 reading11Name Entfernung
attr NotdienstApotheke2 readingEncode UTF-8
attr NotdienstApotheke2 requestHeader2 Accept-Encoding: gzip, deflate
attr NotdienstApotheke2 requestHeader3 Accept-Language: de-DE,de;;q=0.9,en-US;;q=0.8,en;;q=0.7,fr;;q=0.6
attr NotdienstApotheke2 requestHeader4 User-Agent: Lynx/2.8.8dev.3 libwww-FM/2.14 SSL-MM/1.4.1
attr NotdienstApotheke2 requestHeader5 Referer: http://apothekenfinder.mobi/
attr NotdienstApotheke2 requestHeader6 X-Requested-With: XMLHttpRequest
attr NotdienstApotheke2 requestHeader7 Connection: keep-alive
attr NotdienstApotheke2 showBody 0
attr NotdienstApotheke2 stateFormat Name, Telefon, Strasse in Plz Ort
attr NotdienstApotheke2 verbose 0


nach einem reload bzw. neustert habe ich nur Name, Telefon, Strasse in Plz Ort als Anzeige...

habs mal mit PLZ probiert und auch nur mit Ortsnamen....

Gruss

JoWiemann

Hm, warum anonymisierts Du die url? So können wir Dir nicht helfen.

Grüße Jörg


Gesendet von iPhone mit Tapatalk

Grüße Jörg
Jörg Wiemann

Slave: RPi B+ mit 512 MB, COC (868 MHz), CUL V3 (433.92MHz SlowRF); FHEMduino, Aktuelles FHEM

Master: CubieTruck; Debian; Aktuelles FHEM

Kusselin

Hallo Jo,

o.k. sorry..hier die URL:

https://www.aponet.de/service/notdienstapotheke-finden/suchergebnis/0/69493.html

Gruss

Vaddi

Deine URL funktioniert so nicht, da sie kein JSON Format liefert.

So sollte deine Definition aussehen:
http://apothekenfinder.mobi/interface/json.php?device=web&source=not&search=69493 0
fhem auf RPi 3
HM-MOD-RPI-PCB sowie 433mhz Sender
Mehrere HM und 433mhz Produkte

Polamare

Ist auf jeden Fall zu empfehlen.

Kusselin

Zitat von: Vaddi am 08 Juni 2018, 17:19:19
Deine URL funktioniert so nicht, da sie kein JSON Format liefert.

So sollte deine Definition aussehen:
http://apothekenfinder.mobi/interface/json.php?device=web&source=not&search=69493 0

Danke Dir...so hats funktioniert !!
Gruss