Python Forum
How do you specify which web browser opens?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do you specify which web browser opens?
#1
I've skirmished around the net for an answer but their are none that a novice like me can understand. I really need help, I would be eternally grateful for your support.

The program works by receiving data from NFC readers and then outputting a video based on what cards were read by the NFC reader. The videos are currently HTML files but they open in explorer and don't work, i need them to open in chrome.

Plsss halp this is urgent!! i don't think the solution is complex, i just don;t know enough! Thanks!!! Cod
Code:

import serial
import webbrowser
import thread
import time
import Queue

def read_serial(portname, portno, usbno):
    try:
        ser = serial.Serial(portname, portno)
        currentcard = ""
        while True:
            #get data from serial port to a variable serialdata
            serialdata = ser.readline()
            temp = str(serialdata)
            if temp.find ("Found chip PN5")>=0:
                print temp
            if temp.find("Read card #")>0:   
                newcard = temp[30:]
                #print newcard
                #this is the logic to make sure that new cards are dectected
                #also makes sure that cards are only detected once
                #this is only for the first time ever
                if (currentcard == ""):
                    currentcard = newcard
                    #print currentcard
                    print usbno
                    if usbno == 1:
                        #nfcid1 = currentcard
                        #populate the queue for the other thread to read
                        q.put("nfcid1-" + str(currentcard))
                        #print nfcid1
                    elif usbno == 2:
                        #nfcid2 = currentcard
                        q.put("nfcid2-" + str(currentcard))
                        #print nfcid2
                    elif usbno == 3:
                        #nfcid3 = currentcard
                        q.put("nfcid3-" + str(currentcard))
                        #print nfcid3

                    #the code to play the video
                    #what to do
                    #1 you have the id of the card
                    #match id of the card to video file name
                    #if currentcard = knownid:
                    #play the video
                    #sample code for video below

                    #the currentcard variable - hold the id read from the card
                    #if currentcard.find("#1167006660") >=0:
                    #    url = 'file:///Volumes/Data/Arduino/Trinity-Racing/video1.html'
                    #    webbrowser.open_new(url)
                    #elif currentcard = "knownid1":
                        #url = 'file:///Volumes/Data/Arduino/video1.html'
                        #webbrowser.open_new(url)
                    #elif currentcard = "knownid1":
                        #url = 'file:///Volumes/Data/Arduino/video1.html'
                        #webbrowser.open_new(url)

                #this is the part where new and subsequent cards are read continously
                if (currentcard != newcard):
                    currentcard = newcard
                    #print currentcard
                    if usbno == 1:
                        #nfcid1 = currentcard
                        q.put("nfcid1-" + str(currentcard))
                        #print nfcid1
                    elif usbno == 2:
                        #nfcid2 = currentcard
                        q.put("nfcid2-" + str(currentcard))
                        #print nfcid2
                    elif usbno == 3:
                        #nfcid3 = currentcard
                        q.put("nfcid3-" + str(currentcard))
                        #print nfcid3
                    #if currentcard.find("#1167006660") >=0:
                    #    url = 'file:///Volumes/Data/Arduino/Trinity-Racing/video1.html'
                    #    webbrowser.open_new(url)

    except Exception as inst:
        print "Error Type"
        print type(inst)
        print inst.args
        print inst

        
#This code will read all the three card and determine which video to play
#invalid combiantions will be excluded
def compute_video():
    nfcid1 = ""
    nfcid2 = ""
    nfcid3 = ""
    print "Waiting for Readers" 
    while 1:
        #+ nfcid1
        #if  (len(nfcid1) > 2 and len(nfcid2) >2 and len(nfcid3) >2):
        tempvalue = q.get()
        if tempvalue.find ("nfcid1-")>=0:
            nfcid1 = tempvalue
        elif tempvalue.find ("nfcid2-")>=0:
            nfcid2 = tempvalue
        elif tempvalue.find ("nfcid3-")>=0:
            nfcid3 = tempvalue
        
        if  (len(nfcid1) > 2 and len(nfcid2) >2 and len(nfcid3) >2):
            print nfcid1, nfcid2, nfcid3
        #here are the combinations
        if (nfcid1.find ("20") > 2 and nfcid2.find ("64") > 1 and nfcid3.find ("00") > 1):
            print "Currnetly playing combination 1"
            url = 'file:///Users/625447/Documents/F1/Coding/WorldFinalsSetup/FinalVids/1,1,1.html' 
            webbrowser.open_new(url)
        elif (nfcid1.find ("20") > 2 and nfcid2.find ("64") > 1 and nfcid3.find ("56") > 1):
            print "Currnetly playing combination 2"
            url = 'file:///Volumes/Data/Arduino/Trinity-Racing/video1.html' 
            webbrowser.open_new(url)
        elif (nfcid1.find ("20") > 2 and nfcid2.find ("76") > 1 and nfcid3.find ("00") > 1):
            print "Currnetly playing combination 3"
            url = 'file:///Volumes/Data/Arduino/Trinity-Racing/video1.html' 
            webbrowser.open_new(url)
        elif (nfcid1.find ("20") > 2 and nfcid2.find ("76") > 1 and nfcid3.find ("56") > 1):
            print "Currnetly playing combination 4"
            url = 'file:///Volumes/Data/Arduino/Trinity-Racing/video1.html' 
            webbrowser.open_new(url)
        elif (nfcid1.find ("16") > 2 and nfcid2.find ("64") > 1 and nfcid3.find ("00") > 1):
            print "Currnetly playing combination 5"
            url = 'file:///Volumes/Data/Arduino/Trinity-Racing/video1.html' 
            webbrowser.open_new(url)
        elif (nfcid1.find ("16") > 2 and nfcid2.find ("64") > 1 and nfcid3.find ("56") > 1):
            print "Currnetly playing combination 6"
            url = 'file:///Volumes/Data/Arduino/Trinity-Racing/video1.html' 
            webbrowser.open_new(url)
        elif (nfcid1.find ("16") > 2 and nfcid2.find ("76") > 1 and nfcid3.find ("00") > 1):
            print "Currnetly playing combination 7"
            url = 'file:///Volumes/Data/Arduino/Trinity-Racing/video1.html' 
            webbrowser.open_new(url)
        elif (nfcid1.find ("16") > 2 and nfcid2.find ("76") > 1 and nfcid3.find ("56") > 1):
            print "Currnetly playing combination 8"
            url = 'file:///Volumes/Data/Arduino/Trinity-Racing/video1.html' 
            webbrowser.open_new(url)
        time.sleep(5)
        
# Create two threads as follows
try:
    #data from different readers are sent to the queue
    q = Queue.Queue()
    #change based on the computer -- 
    thread.start_new_thread( read_serial, ("COM3", 9600, 1) )
    thread.start_new_thread( read_serial, ("COM7", 9600, 2) )
    thread.start_new_thread( read_serial, ("COM6", 9600, 3) )
    thread.start_new_thread (compute_video , ())
except:
    print "Error: unable to start thread"

while 1:
    pass
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  key = getkey() opens platforms.py Toolman 1 1,665 May-28-2020, 07:10 AM
Last Post: Gribouillis
  How do I activate my script when another program opens? jhave_21 3 3,816 Nov-23-2017, 08:29 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020