0

I am trying to make a script that opens a url when the OPEN command is entered. This is for an IRC bot I am creating. I am trying to make it like this

OPEN http://url.com and it opens the url. This is what I have so far.

import webbrowser
test = s.recv(1024)

if test.find("http://") != 1:
        webbrowser.open(test)

else:
    print "it didnt work"

I honestly have no idea how this is done.

Max00355
  • 827
  • 2
  • 12
  • 28
  • 1
    Er, what is what you have so far? – Blorgbeard Jun 06 '12 at 21:18
  • Second Blorgbeard. The code *is* worth posting (I hope :) – machow Jun 06 '12 at 21:20
  • 1
    Post up the code, it might help us to understand what you're getting at a bit better. Just insert comments saying what should happen where you haven't got real code yet. – Max Spencer Jun 06 '12 at 21:20
  • I did, I really don't understand how this is done. – Max00355 Jun 06 '12 at 21:22
  • I am trying to make it so from my irc client I could wrute OPEN http://google.com and it would open that URL on a computer running the python script. – Max00355 Jun 06 '12 at 21:26
  • @Max: Is that all? Where does the IRC bot come in play? I mean, you can't just connect and read. You need to implement the IRC protocol. I think using the `webbrowser` module is a good solution for the actual URL opening part, though. – Niklas B. Jun 06 '12 at 21:26
  • Hey dude, maybe check out this similar question: http://stackoverflow.com/questions/1100840/irc-python-bot-best-way – Max Spencer Jun 06 '12 at 21:27
  • Have you considered using regular expressions? `re.match(r'OPEN .*',line)` would be a pretty useful start. – Jeremy Kemball Jun 06 '12 at 21:55
  • @NiklasB. That is not the important part. I have all the other parts written already I just need this part done now. – Max00355 Jun 06 '12 at 22:42

1 Answers1

1

I figured it out

import webbrowser
#command is OPEN http://url.com
a = raw_input("Command: ")

if "OPEN" in a:
    url = a.strip("OPEN ")
    webbrowser.open(url)
Max00355
  • 827
  • 2
  • 12
  • 28