This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

OnThisDay.tcl (Current Version: 1.2b-updated 1/15/08)

Support & discussion of released scripts, and announcements of new releases.
B
BeBoo
Halfop
Posts: 42
Joined: Wed Sep 26, 2007 1:44 am

OnThisDay.tcl (Current Version: 1.2b-updated 1/15/08)

Post by BeBoo »

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: Select all

#---------------------------------------------------------------------#
# 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.
User avatar
schizosmurf
Voice
Posts: 15
Joined: Fri Oct 12, 2007 10:50 am

Post by schizosmurf »

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 ;)
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

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: Select all

# 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.
User avatar
schizosmurf
Voice
Posts: 15
Joined: Fri Oct 12, 2007 10:50 am

Post by schizosmurf »

it appears i was wrong. the dates go all the way back to 20010711 ( http://www.nytimes.com/learning/general ... 10711.html ).
http://www.nytimes.com/learning/general ... chive.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 ... 10711.html
vs
http://www.nytimes.com/learning/general ... 30711.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 ;)
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

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 ... 10711.html
vs
http://www.nytimes.com/learning/general ... 30711.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 ;)
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. ;)
User avatar
schizosmurf
Voice
Posts: 15
Joined: Fri Oct 12, 2007 10:50 am

Post by schizosmurf »

i completely missed the clock format part of your previous post. reading too fast i guess. that sounds like it would work great.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

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: Select all

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 :D
User avatar
schizosmurf
Voice
Posts: 15
Joined: Fri Oct 12, 2007 10:50 am

Post by schizosmurf »

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.
B
BeBoo
Halfop
Posts: 42
Joined: Wed Sep 26, 2007 1:44 am

Post by BeBoo »

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!
B
BeBoo
Halfop
Posts: 42
Joined: Wed Sep 26, 2007 1:44 am

1.1b Released!

Post by BeBoo »

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
G
Gordon
Voice
Posts: 35
Joined: Wed Apr 04, 2007 11:45 am

Post by Gordon »

Very nice and useful script.

Basically i miss a thing you already have in your "to do" list.
More customization for display of information
..and i dont want that birthday information at the end, if possible :)
B
BeBoo
Halfop
Posts: 42
Joined: Wed Sep 26, 2007 1:44 am

Post by BeBoo »

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.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

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: Select all

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.
B
BeBoo
Halfop
Posts: 42
Joined: Wed Sep 26, 2007 1:44 am

Post by BeBoo »

Fixed \n seperator issue. Thanks, speechles!

Download link in first post.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

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:
Post Reply