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.

URL logging

Help for those learning Tcl or writing their own scripts.
Post Reply
p
pitbull
Voice
Posts: 13
Joined: Sun Aug 12, 2007 12:12 pm

URL logging

Post by pitbull »

Hello, I have modified the URL title script to log URL's posted to a chan and output it to a html file. It works sometimes, it will log a few links, but then for some strange reason it will overwrite the whole file with a blank file, and start over.. It usually will log 3-4 urls before restarting.. Here is the part I modified (the rest of the script seems to work well). I each url posted to be inserted into the top of the file
if {[string match "*://*" $word]} {
set ulf [open /home/peakoil/public_html/urls.html r]
set ulogdata [read -nonewline $ulf]
close $ulf
set ulines [split $ulogdata "\n"]
set ulf [open /home/peakoil/public_html/urls.html w]
set urlline "<a href=\"$word\">$urtitle</a><br>"
set ulines [linsert $ulines 0 $urlline]
puts $ulf [join $ulines "\n"]
close $ulf
}
Thanks for your help!
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

If you're going to modify other peoples scripts, you best learn how to debug them as well.. Try adding putcmdlog lines in so you can see what's going on.
User avatar
CrazyCat
Revered One
Posts: 1303
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Why don't you use a regexp to extract the URL?

And opening twice the same file is quite unoptimised.

You can open the file in read/write mode and get each line one by one. If the line matches your current URL, exit the loop (and do nothing). When arriving at the end of the file (so, you didn't see the url), just append it to your file.
p
pitbull
Voice
Posts: 13
Joined: Sun Aug 12, 2007 12:12 pm

Post by pitbull »

ok let me clear some things up. The code you saw is mine, I added it into a script that grabs the url title of a url posted to a chan. It had url logging capabilities which work fine; however, it outputted the urls to an eggdrop log file. I want the URL's to be visible on a website, so I came up with that code. I want each url posted to be inserted into the top of the file, not appended at the bottom
User avatar
CrazyCat
Revered One
Posts: 1303
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Ok, sorry, I didn't look completely your code.
Peharps your variable is too big for the system, you can try adding each $uline with a foreach loop.
I know this trouble exists with exec command when the string is too long, so try this way.
Post Reply