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.

[SOLVED][Request] add text from url link to mysqldatabase

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
User avatar
Fire-Fox
Master
Posts: 289
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

[SOLVED][Request] add text from url link to mysqldatabase

Post by Fire-Fox »

Hey!

I looking for a script that can do the following :

When a user types !addinfo some.text.here http://url.com/get/?a=info&id=1710031&bot=DB2 (were the info is stored) the script should then, download the text file to /home/information.

some.text.here should be the saved name of the filename to...
Last edited by Fire-Fox on Wed Jun 06, 2012 1:31 pm, edited 1 time in total.
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Haven't tested this.

Code: Select all

bind pub - !addinfo pub:addinfo

proc pub:addinfo {nick uhost hand chan text} {
	if {[scan $text {%s%s} file url] != 2} {
		puthelp "Usage: !addinfo <file> <url>"
		return
	}
	set token [::http::geturl $url]
	set content [::http::data $token]
	::http::cleanup $content
	set fp [open "/home/$file" "w"]
	foreach line [split $content \n] {
		puts $fp [join $line "\n"]
	}
	close $fp
}
Edit: fixed typo.
Last edited by caesar on Tue Jun 05, 2012 12:14 am, edited 1 time in total.
Once the game is over, the king and the pawn go back in the same box.
User avatar
Fire-Fox
Master
Posts: 289
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

Post by Fire-Fox »

I'll try it right away, and post the output

i get this :

Code: Select all

[wrong # args: should be "bind type flags cmd/mask ?procname?"]
EDIT: fixed by doing :

Code: Select all

bind pubm - "*!addinfo*" pub:addinfo 
NEW ERROR:

Code: Select all

Tcl error [pub:addinfo]: could't open socket: host is unreachable (Name or service not known)
i can download from the url... but not the bot
Last edited by Fire-Fox on Mon Jun 04, 2012 5:17 pm, edited 2 times in total.
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

bind pub - !addinfo pub:addinfo 
Fix it like that instead, the pubm bind passes text very differently. Differently as in, the trigger is included at the front of your text. Literally everything you type is passed to the procedure. The variable $::lastbind contains your pubm mask. This means your filenames or the url it attempts to fetch will contain "!addinfo" in them.

Using pub, $::lastbind will contain the trigger, and the rest of the text is passed to the procedure. This eliminates the trigger from the text passed and your filenames/urls come out correct now.
User avatar
Fire-Fox
Master
Posts: 289
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

Post by Fire-Fox »

Thanks speechles :)

All sortet out! \o/

There is just one thing, the text is placed on new line all the line, how can i put it it should be a copy of the original file, to the file i store.

There will proberly come some acsii aswell how do i handle that...
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Then drop the:

Code: Select all

   foreach line [split $content \n] {
      puts $fp [join $line "\n"]
   } 
and make it:

Code: Select all

puts $fp $content
Once the game is over, the king and the pawn go back in the same box.
User avatar
Fire-Fox
Master
Posts: 289
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

Post by Fire-Fox »

All done!

working as it should

Code: Select all

package require TclCurl
bind pub - !addinfo pub:addinfo

proc pub:addinfo {nick uhost hand chan text} { 
   if {[scan $text {%s%s%s} release url filename] != 3} {
      puthelp "Usage: !addinfo <release> <url> <filename>" 
      return 
   }

   exec mkdir "/home/bot/1/filesys/info/$release"
   set curlHandle [curl::init]
  $curlHandle configure -url $url -file "/home/bot/1/filesys/info/$release/$filename"
  $curlHandle perform
}
putlog "Reciever StoreiNfo.tcl - Loaded By Fire-Fox"
UPDATE:

now it stores the release to database (it has a "Timer for the mysql connection" aswell)

Code: Select all

##################
### Mysql path ###
##################

load /usr/lib/tcltk/mysqltcl-3.05/libmysqltcl3.05.so

# define database parameters
set mysql_(user) "USERNAME"
set mysql_(password) "PASSWORD"
set mysql_(host) "localhost"
set mysql_(database) "bots"
set mysql_(table) "TABLE"

if {![info exists mysql_(handle)]} {
set mysql_(handle) [mysqlconnect -host $mysql_(host) -user $mysql_(user) -password $mysql_(password) -db $mysql_(database)]
}

package require TclCurl
bind pub - !addinfo pub:addinfo

proc pub:addnfo {nick uhost hand chan text} { 
global mysql_
   if {[scan $text {%s%s%s} rlsname url filename] != 3} {
      puthelp "Usage: !addinfo <release> <url> <filename>" 
      return 
   }

   exec mkdir "/home/bot/1/filesys/nfo/$release"
   set curlHandle [curl::init]
  $curlHandle configure -url $url -file "/home/bot/1/filesys/info/$rlsname/$filename"
  $curlHandle perform
#TEST
set infofp [open "/home/bot/1/filesys/info/$release/$filename" "r"]
set rawinfo [read $infofp]
close $infofp
#END
putlog "$rawinfo"
set escapedinfo [mysql::escape $mysql_(handle) $rawinfo]
  set nix [mysqlexec $mysql_(handle) "INSERT INTO $mysql_(table) (release,filename,rawinfo) VALUES ( '$release' , '$filename' , '$escapednfo' )"]
}

putlog "Reciever StoreNfoToDB.tcl - Loaded By Fire-Fox"

######################################
### Timer for the mysql connection ###
######################################
if {[timerexists nfo:dbconnection] !=""} { killtimer $dbconnect(dbtimer) }

set dbconnect(dbtimer) [timer 1 info:dbconnection]

proc info:dbconnection {} {
	global mysql_ dbconnect
	if {[catch  {mysqlping $mysql_(handle)}] != 0} { 
         set mysql_(handle) [mysqlconnect -host $mysql_(host) -user $mysql_(user) -password $mysql_(password) -db $mysql_(database)]
	}
	if {[set var [timerexists info:dbconnection]] !="" } { killtimer $var }
	set dbconnect(dbtimer) [timer 1 info:dbconnection]
}
putlog "Reciever StoreiNfo.tcl - Loaded By Fire-Fox" 
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
Post Reply