egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

OnThisDay.tcl (Current Version: 1.2b-updated 1/15/08)
Goto page 1, 2  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
BeBoo
Halfop


Joined: 26 Sep 2007
Posts: 42

PostPosted: Wed Oct 10, 2007 4:52 pm    Post subject: OnThisDay.tcl (Current Version: 1.2b-updated 1/15/08) Reply with quote

I decided to learn TCL and was able to make a script that pulls data from NY Times as to what happened on the current day in history.

Code:
#---------------------------------------------------------------------#
# BlueLiquidX:OnThisDay                                         v1.2b #
#                                                                     #
# Grabs the headlines for what happened today in history              #
#                                                                     #
# Usage:                                                              #
#   .chanset #channel +today                                          #
#   !today [-b/m] [date (format: mmdd)]                               #
#                                                                     #
#   -m   Shows all history for the day                                #
#   -b   Shows all birthdays for the day                              #
#        *WARNING: using switches WILL flood channel and may result   #
#        in bot getting kicked/banned from channel and/or server.     #
#                                                                     #
# ChangeLog:                                                          #
#   1.0a - First public alpha release                                 #
#   1.1b - Fixed bug where '<age/>' showed up in birthday prior to    #
#          2007                                                       #
#        - Changed date input from yyyymmdd to mmdd. This will use a  #
#          prior year if the date is after the current date.          #
#        - Added switches to allow more information to be displayed   #
#          or only birthdays to be displayed.                         #
#   1.2b - Added variable to disable birthdays from appearing on      #
#          output.                                                    #
#        - Added variable to customize the seperator between items    #
#        - Removed debug logging                                      #
#                                                                     #
# TODO:                                                               #
#   - More customization for display of information                   #
#   - Ideas? Email me.                                                #
#                                                                     #
# http://www.blueliquidx.net                                          #
# macbrando@gmail.com                                                 #
# irc.blueliquidx.net / #AllNiteCafe - BeBoo                          #
#---------------------------------------------------------------------#


Sample IRC wrote:
(BeBoo) !today
(optix) Wednesday, October 10th - This is the 283rd day of 2007. There are 82 days left in 2007. * 1813 - Composer Giuseppe Verdi was born in Le Roncole, Italy. * 1845 - The U.S. Naval Academy opened in Annapolis, Md. * 1886 - The tuxedo dinner jacket made its American debut at the autumn ball in Tuxedo Park, N.Y. * Green Bay Packers quarterback Brett Favre turns 38 years old today.


I used incith as a basis for my script. Please be sure to check out the settings before using the script. Please feel free to point out any bugs, mistakes, misspellings, etc. Please let me know if you have any ideas for how this script can be expanded further!

You can get a copy here.


Last edited by BeBoo on Fri Feb 15, 2008 10:10 am; edited 4 times in total
Back to top
View user's profile Send private message
schizosmurf
Voice


Joined: 12 Oct 2007
Posts: 15

PostPosted: Fri Oct 12, 2007 6:24 pm    Post subject: Reply with quote

you cant access a date prior to 20061012 (Oct. 12, 2006) as of today Oct.12th 2007 on that website. so it appears you can only check the previous 365 days. which makes sense since the history of 20071012 would be the same as 20031012
so maybe you could put in a check for that?
if the current date > (query + 365) then give error msg
or something like that

other than that issue, it appears to work great

P.S.
idea for expansion:
maybe you could add in a flag !today -b
where it would only return birthday information and more than just the top one. I notice the format for the additionally listed birthdays is just Name Age as opposed to the full sentence for the top one. so that would require more work. But it's just an idea Wink
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Fri Oct 12, 2007 6:59 pm    Post subject: Reply with quote

schizosmurf wrote:
you cant access a date prior to 20061012 (Oct. 12, 2006) as of today Oct.12th 2007 on that website. so it appears you can only check the previous 365 days. which makes sense since the history of 20071012 would be the same as 20031012
so maybe you could put in a check for that?
if the current date > (query + 365) then give error msg
or something like that

Code:
# input is just MMDD
set query "http://www.nytimes.com/learning/general/onthisday/2004${input}.html"

Actually, no need for a check at all, just eliminate the year. Your 366 days of results will all be accessible via month and day selection. Thats the beauty of using 2004 for all queries, your allowing those born on february 29th "Leapyear", to actually get results too.. check February 29th, 2007 against february 29th, 2004, you can clearly see one works, one says 404 and doesn't. To get around issues involving bot parsing 2004 you can use clock format to grab the present year and store it into a year variable, then you check current month/day (again, using clock format) is less than the month/day they put, if so, subtract one from the year variable (since they are ahead of current month/day, it has to be last year, im sure you get the idea). You can know the year without asking. Then when scraping the html, you simply spot where the 2004 occurs (like that top line with so-n-so days left of 2004) that should become the year variable, and string map it in, quite simple actually. Birthdays and other year relevant information shouldn't receive the string map treatment.

@BeBoo, your script appears realized other than the !birthday scraper which schizosmurf suggested. Then your using more information from the page scrape giving users more choice. Choice offers more appeal giving your work a broader audience.
Back to top
View user's profile Send private message
schizosmurf
Voice


Joined: 12 Oct 2007
Posts: 15

PostPosted: Fri Oct 12, 2007 7:49 pm    Post subject: Reply with quote

it appears i was wrong. the dates go all the way back to 20010711 ( http://www.nytimes.com/learning/general/onthisday/20010711.html ).
http://www.nytimes.com/learning/general/onthisday/archive.html only shows the previous 365 days.

@speechles
using just 2004 would definitely work, but would be using an old article when newer ones are available.
for example if i wanted to look up yesterday, 20071011 would be available but your method would use 20041011, the article from 3 years ago.

articles for the same day on diff years ARE almost exactly the same but i did notice some differences in just the few i tested. most noticeably the person at the top of the birthday list is usually different.
example:
http://www.nytimes.com/learning/general/onthisday/20010711.html
vs
http://www.nytimes.com/learning/general/onthisday/20030711.html

2001 has 2 stories at the top and 2003 has 3.
2001's birthday top shows Sela Ward and 2003's shows Suzanne Vega.

I know it seems kinda nitpicky but say someone that was at the top of the birthday list in 2004 died, naturally they wouldn't be having a birthday in 2007.

but having the input be only MMDD is the way to go for sure. theres no sense having people trying to input dates from 25 years ago, (which is what i did right off the bat, lol)
but there should be some sort of comparison against the current date, so that the most recent article is used. i know that would be way more complicated than just using 2004, especially with leapday as u pointed out.

just my thoughts Wink
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Fri Oct 12, 2007 7:54 pm    Post subject: Reply with quote

schizosmurf wrote:

@speechles
using just 2004 would definitely work, but would be using an old article when newer ones are available.
for example if i wanted to look up yesterday, 20071011 would be available but your method would use 20041011, the article from 3 years ago.

articles for the same day on diff years ARE almost exactly the same but i did notice some differences in just the few i tested. most noticeably the person at the top of the birthday list is usually different.
example:
http://www.nytimes.com/learning/general/onthisday/20010711.html
vs
http://www.nytimes.com/learning/general/onthisday/20030711.html

2001 has 2 stories at the top and 2003 has 3.
2001's birthday top shows Sela Ward and 2003's shows Suzanne Vega.

I know it seems kinda nitpicky but say someone that was at the top of the birthday list in 2004 died, naturally they wouldn't be having a birthday in 2007.

but having the input be only MMDD is the way to go for sure. theres no sense having people trying to input dates from 25 years ago, (which is what i did right off the bat, lol)
but there should be some sort of comparison against the current date, so that the most recent article is used. i know that would be way more complicated than just using 2004, especially with leapday as u pointed out.

just my thoughts Wink
Quote:
You can use clock format to grab the present year and store it into a year variable, then you check current month/day (again, using clock format) is less than the month/day they put, if so, subtract one from the year variable (since they are ahead of current month/day, it has to be last year, im sure you get the idea). You can know the year without asking.

Doing this, you can know the year, and then prepend it to their input (set input "$_year$input") and you have the current year without even asking. This can work. Wink
Back to top
View user's profile Send private message
schizosmurf
Voice


Joined: 12 Oct 2007
Posts: 15

PostPosted: Fri Oct 12, 2007 8:02 pm    Post subject: Reply with quote

i completely missed the clock format part of your previous post. reading too fast i guess. that sounds like it would work great.
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Fri Oct 12, 2007 8:10 pm    Post subject: Reply with quote

schizosmurf wrote:
i completely missed the clock format part of your previous post. reading too fast i guess. that sounds like it would work great.

Code:
if {![regexp -- {(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])} $Input]} {
  # user didn't enter date fields correctly, MMDD
  # and either went under, over, or just plain
  # messed up on purpose, so just replace this
  # with your standard message of choice
  # ridiculing them, and calling them stupid...heh
  return 0
}
set MonthDay [clock format [clock seconds] -format {%m%d}]
set OurYear [clock format [clock seconds] -format {%Y}]
if {$MonthDay < $Input} { incr OurYear -1 }
set NewInput "$OurYear$Input"

Thats the idea right there Very Happy
Back to top
View user's profile Send private message
schizosmurf
Voice


Joined: 12 Oct 2007
Posts: 15

PostPosted: Sun Oct 14, 2007 3:44 pm    Post subject: Reply with quote

i also had another idea for expanding this script.
have some sort of -switch to allow more results to be shown.

like if default is set to 3, !today [date] would of course show 3 results but, if a user does !today -m [date] then it could show more releases 6 or 10 or whatever. maybe have the first 3 show in chan and rest show in notice. and if user did the command in pm then it wouldn't matter, all could just be replied via privmsg.
Back to top
View user's profile Send private message
BeBoo
Halfop


Joined: 26 Sep 2007
Posts: 42

PostPosted: Mon Oct 15, 2007 11:55 am    Post subject: Reply with quote

Thanks for the suggestions. I added in speechles's code but the if statement doesn't trigger if i did something dumb like !today 9999.

I am working on figuring out how to detect multiple args. Once I get that worked out, I will release a new version with the birthdays switch and the all switch.

I'm still very new to TCL but I'm picking it up slowly.

Thanks for any help!
Back to top
View user's profile Send private message
BeBoo
Halfop


Joined: 26 Sep 2007
Posts: 42

PostPosted: Mon Oct 22, 2007 11:28 pm    Post subject: 1.1b Released! Reply with quote

I have released version 1.1b. New in this version is the ability to use -m (for all information) or -b (for all birthdays). Please download the latest version from the link in the first post. Let me know if you have any issues and keep those feature requests coming!!

BeBoo
Back to top
View user's profile Send private message
Gordon
Voice


Joined: 04 Apr 2007
Posts: 34

PostPosted: Sun Dec 30, 2007 8:31 am    Post subject: Reply with quote

Very nice and useful script.

Basically i miss a thing you already have in your "to do" list.
Quote:
More customization for display of information


..and i dont want that birthday information at the end, if possible Smile
Back to top
View user's profile Send private message
BeBoo
Halfop


Joined: 26 Sep 2007
Posts: 42

PostPosted: Tue Jan 15, 2008 1:41 pm    Post subject: Reply with quote

Added a few features.

1.2b - Added variable to disable birthdays from appearing on output.
- Added variable to customize the seperator between items
- Removed debug logging

Can't get the seperator \n to work, tho... Only outputs first line. If anyone can assist me with that, it'd be great.

Download link in first post.
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Tue Jan 15, 2008 2:37 pm    Post subject: Reply with quote

BeBoo wrote:
Can't get the seperator \n to work, tho... Only outputs first line. If anyone can assist me with that, it'd be great.

The problem is that eggdrop cannot display something with a newline in it. You will only get the text up to the newline, not anything beyond it. You can get around this limitation easily by using foreach and split.
Code:
if {[string match "\n" $seperator]} {
  foreach line [split $output "\n"] {
    putserv "privmsg $chan :$line"
  }
}


Last edited by speechles on Tue Jan 15, 2008 3:22 pm; edited 1 time in total
Back to top
View user's profile Send private message
BeBoo
Halfop


Joined: 26 Sep 2007
Posts: 42

PostPosted: Tue Jan 15, 2008 3:18 pm    Post subject: Reply with quote

Fixed \n seperator issue. Thanks, speechles!

Download link in first post.
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Tue Jan 15, 2008 4:48 pm    Post subject: Reply with quote

BeBoo wrote:
Download link in first post.

clicking the download link wrote:
Forbidden

You don't have permission to access /onthisday.tcl on this server.


Might want to change permissions for that file possibly.. Wink
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases All times are GMT - 4 Hours
Goto page 1, 2  Next
Page 1 of 2

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


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber