Hi,
ich würde gerne mit einem Dashbutton eine html welche auf dem Pi liegt öffnen.
Ich habe dazu ein script gefunden und dies leicht verändert sodass keine Webside sondern meine Lokale html aufgerufen wird.
iimport datetime
import logging
import urllib2
import webbrowser
# Constants
timespan_threshhold = 3
# Globals
lastpress = datetime.datetime(1970,1,1)
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
from scapy.all import *
def button_pressed_dash1():
global lastpress
thistime = datetime.datetime.now()
timespan = thistime - lastpress
if timespan.total_seconds() > timespan_threshhold:
current_time = datetime.datetime.strftime(thistime, '%Y-%m-%d %H:%M:%S')
print 'Gilette button pressed at ' + current_time
url = "file:///home/pi/Documents/Homepage/achtung.html"
webbrowser.open(url, new=0, autoraise=True)
lastpress = thistime
def button_pressed_dash2():
global lastpress
thistime = datetime.datetime.now()
timespan = thistime - lastpress
if timespan.total_seconds() > timespan_threshhold:
current_time = datetime.datetime.strftime(thistime, '%Y-%m-%d %H:%M:%S')
print 'Ariel button pressed at ' + current_time
url = "file:///home/pi/Documents/Homepage/achtung.html"
webbrowser.open(url, new=0, autoraise=True)
lastpress = thistime
def udp_filter(pkt):
options = pkt[DHCP].options
for option in options:
if isinstance(option, tuple):
if 'requested_addr' in option:
# we've found the IP address, which means its the second and final UDP request, so we can trigger our action
mac_to_action[pkt.src]()
break
mac_to_action = {'XX:XX:XX:XX:XX:XX' : button_pressed_dash2 , 'XX:XX:XX:XX:XX:XX' : button_pressed_dash1}
mac_id_list = list(mac_to_action.keys())
print "Waiting for a button press..."
sniff(prn=udp_filter, store=0, filter="udp", lfilter=lambda d: d.src in mac_id_list)
if __name__ == "__main__":
main()
Alles anzeigen
Das Ganze funktioniert auch wirklich gut.
Allerdings öffnet Firefox immer einen neuen Tab.
Wenn ich das "Handbuch" richtig verstehe, sollte sich das Verhalten ändern sofern man im Teil
" webbrowser.open(url, new=0, autoraise=True)" das new ändert.
sprich:
Display url using the default browser. If new is 0, the url is opened in the same browser window if possible. If new is 1, a new browser window is opened if possible. If new is 2, a new browser page (“tab”) is opened if possible
ich habe also ein wenig gegoogelt und viele User schreiben, dass dies problem nicht in new=0 liegt, sondern dass dies mit Python nicht umzusetzten sei.
Die Alternative die ich gefunden habe wäre Selenium.
Mein Problem besteht darin, dass meine Pythonkenntnisse sehr schwach sind und mich mit Selenium gar nicht auskenne...
Brauche ich jetzt ein komplettes Selenium-script oder kann man die beiden Verknüpfen
z.B.
iimport datetime
import logging
import urllib2
import webbrowser
import selenium as webdriver
from time import sleep
# Constants
timespan_threshhold = 3
# Globals
lastpress = datetime.datetime(1970,1,1)
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
from scapy.all import *
def button_pressed_dash1():
global lastpress
thistime = datetime.datetime.now()
timespan = thistime - lastpress
if timespan.total_seconds() > timespan_threshhold:
current_time = datetime.datetime.strftime(thistime, '%Y-%m-%d %H:%M:%S')
print 'Gilette button pressed at ' + current_time
driver.get("file:///home/pi/Ducuments/homepage/achtung.html"
...
Alles anzeigen
Ich nutze PI3 mit Raspbian Jessie with PIXEL
Image with PIXEL desktop based on Debian Jessie
Version: March 2017
Release date: 2017-03-02
Kernel version: 4.4
vielleicht weiss hier jemand Rat.