Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: Cooking up web jokes for TTS Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
theowl
Groupie
Groupie
Avatar

Joined: February 24 2006
Location: United States
Online Status: Offline
Posts: 59
Posted: February 28 2006 at 19:32 | IP Logged Quote theowl

Tonight, I'll be introducing a script I've come to love. It's only function is to obtain jokes from a site that normally feeds the jokes to other websites, then read it over the house speakers.

First, we start cooking with GV called FUNNYSELECT, which we make "j". This GV holds what type of funny the script should request.

Then, we toss in two macros

WEBQUOTE:

ph_runscript_0("C:\Program Files\powerhome\scripts\getfunny.vbs","vbscript",0,5000,"get funny" )

WEBQUOTESEL:

ph_runscript_0("C:\Program Files\powerhome\scripts\getfunny.vbs","vbscript",0,5000,"sel ectfunny" )

Bring that to a boil by adding in two triggers. I personally like X10-in C15 on for the WEBQUOTE and C15 off for the WEBQUOTESEL, but flavor to your taste.

Finish the meal with the following Vbscript and enjoy:

sub getfunny()
dim s_html, s_joke, s_temp, l_pos1, l_return, phFunnySelect
phFunnySelect = ph.getglobal_s( "FUNNYSELECT" )

rem Get URL
s_html = left(ph.geturl("http://www.jokes2go.com/cgi-bin/includejoke. cgi?type=" & phFunnySelect),50000)

rem Eliminate beginning junk from page
s_temp = mid(s_html,252,5000)

rem Eliminate ending junk from page
l_pos1 = instr(1,s_temp,"this.document.write")-3
s_temp = left(s_temp,l_pos1-4)
s_temp = ph.replaceall ( s_temp, "<br>", "" )
s_temp = ph.replaceall ( s_temp, ".", ". " )
s_temp = ph.replaceall ( s_temp, "\n", ". " )
s_temp = ph.replaceall ( s_temp, "\", "" )
s_temp = ph.replaceall ( s_temp, "?", "? " )

rem Now joke is ready
s_joke = s_temp
ph.tts s_joke

end sub

sub selectfunny()
dim phFunnySelect

phFunnySelect = ph.getglobal_s( "FUNNYSELECT" )

select case phFunnySelect
     case "j"
           phFunnySelect = "o"
           ph.tts "Selection Change: one liner chosen"
     case "o"
           phFunnySelect = "q"
           ph.tts "Selection Change: quote chosen"
     case "q"
           phFunnySelect = "p"
           ph.tts "Selection Change: poem chosen"
     case "p"
           phFunnySelect = "s"
           ph.tts "Selection Change: story chosen"
     case "s"
           phFunnySelect = "j"
           ph.tts "Selection Change: joke chosen"
     case else
           phFunnySelect = "j"
           ph.tts "Selection Change: joke chosen"
end select

ph.setglobal_s "FUNNYSELECT", phFunnySelect

end sub


You might get a lot of repeat jokes, which is why the script is designed to allow the type of joke change.

FYI: Some of these jokes are not G or even PG rated as the lump on my head will indicate. Use at your own risk.
Back to Top View theowl's Profile Search for other posts by theowl
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: March 02 2006 at 10:15 | IP Logged Quote dhoward

I havent had a chance to test this yet (been busy with the next beta) but hope to shortly.

And definately, if you've got any more scripts or code, please feel free to post .

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
theowl
Groupie
Groupie
Avatar

Joined: February 24 2006
Location: United States
Online Status: Offline
Posts: 59
Posted: March 02 2006 at 10:30 | IP Logged Quote theowl

Hope you like it.

I've nearly exausted the joke database from the site, which will happen when you press the trigger button 30 times in a row each day.

I'm working on another code that grabs all kinds of jokes from a different website. In that one, I toyed with regexp to do the instr locate. Took me almost all day to get things working, but it's coming along nicely now.

The main problem I've come upon is getting regexp to match the joke between new line commands. I had thought that .* would do that, but it always stops at the newline. To make it easier, I just replace all the new lines with null, then start extracting.

The script still needs some work to make it easier to select the type of joke it should get, but that should be easy using some of the script I already posted.

I think today I'll try to find a nice horoscope site. Between the jokes, weather, and horoscopes, I'm getting very close to having the morning greeting I used to enjoy.

PS: Did you ever think about putting a real-time chat on this site?
Back to Top View theowl's Profile Search for other posts by theowl
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: March 02 2006 at 20:29 | IP Logged Quote TonyNo

Quote:
PS: Did you ever think about putting a real-time chat on this site?

Look on the main PH web page!
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
theowl
Groupie
Groupie
Avatar

Joined: February 24 2006
Location: United States
Online Status: Offline
Posts: 59
Posted: March 02 2006 at 21:12 | IP Logged Quote theowl

Yeah, saw that today.

Do you ever feel like your brain has gotten tired of you and left without so much as a note?

Back to Top View theowl's Profile Search for other posts by theowl
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: March 02 2006 at 21:46 | IP Logged Quote TonyNo

There is a flag you can set in ph_regex to cause the search to ignore cr/lf's within the data...

Quote:
If your regular expression must span across a line, then add 2 to the flags to have CR's and LF's temporarily converted. CR will be converted to ASCII 128 and LF will be converted to ASCII 129. If you convert CF/LF then you can include them in your search with PowerHome escape characters ~128 and ~129 respectively.
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
smarty
Super User
Super User
Avatar

Joined: May 21 2006
Location: United States
Online Status: Offline
Posts: 728
Posted: June 14 2006 at 22:01 | IP Logged Quote smarty

Help,

It appears that the jokes have moved. I wrote the two VB scripts and two macros (and GV="j"). What has now changed?
Back to Top View smarty's Profile Search for other posts by smarty
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: June 14 2006 at 22:26 | IP Logged Quote TonyNo

I went to the url in your code and it didn't work. I did it a second time and it did.

www.jokes2go.com/cgi-bin/includejoke.cgi?type=j
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
smarty
Super User
Super User
Avatar

Joined: May 21 2006
Location: United States
Online Status: Offline
Posts: 728
Posted: June 14 2006 at 22:33 | IP Logged Quote smarty

Nevermind, it now works.

I realize I broke the one VB (with two subroutines) in two seperate scripts.....hey...I know...I'm not a programmer......
Back to Top View smarty's Profile Search for other posts by smarty
 
theowl
Groupie
Groupie
Avatar

Joined: February 24 2006
Location: United States
Online Status: Offline
Posts: 59
Posted: June 15 2006 at 13:59 | IP Logged Quote theowl

I noticed that the randomness of these jokes isn't as random as it used to be. Perhaps the webmaster got tired of 10 requests per minute when I'm in the mood for jokes.

I plan to eventually rewrite this to store 10 different jokes into GVs. Once I reach joke 8, it will refresh the list.

Anyone know if PH can handle arrays directly? If so, perhaps I could store all 10 jokes into one GV.
Back to Top View theowl's Profile Search for other posts by theowl
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: June 16 2006 at 14:34 | IP Logged Quote dhoward

PowerHome cannot directly handle arrays. You could use the userdata1 table coupled with ph_directsql and ph_sqlselectinto functions to achieve comparable results but probably a little deeper than you wanted to go.

You could store all 10 jokes in a GV and use a special separator sequence that you could then pick out using one of the ph_regex functions. The current regex functions would take a little work but the upcoming beta will have a couple of enhanced regex functions to make this easier. The only problem may be the length of data in the GV. You're limited to 1024 characters. You could use one of the System global variables [GLOBAL1] thru [GLOBAL20] (stored in memory) for virtually unlimited space.

PS. If you need help with using the userdata1 table as an array, let me know and I'll walk you through the functions.

HTH,

Dave.


Edited by dhoward - June 16 2006 at 14:35
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum