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 

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

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
Fire-Fox
Master


Joined: 23 Sep 2006
Posts: 270
Location: /dev/null

PostPosted: Mon Jun 04, 2012 1:12 pm    Post subject: [SOLVED][Request] add text from url link to mysqldatabase Reply with quote

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...
_________________
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze


Last edited by Fire-Fox on Wed Jun 06, 2012 1:31 pm; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3645
Location: Mint Factory

PostPosted: Mon Jun 04, 2012 3:40 pm    Post subject: Reply with quote

Haven't tested this.
Code:

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.
_________________
Once the game is over, the king and the pawn go back in the same box.


Last edited by caesar on Tue Jun 05, 2012 12:14 am; edited 1 time in total
Back to top
View user's profile Send private message
Fire-Fox
Master


Joined: 23 Sep 2006
Posts: 270
Location: /dev/null

PostPosted: Mon Jun 04, 2012 5:00 pm    Post subject: Reply with quote

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

i get this :
Code:

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


EDIT: fixed by doing :
Code:
bind pubm - "*!addinfo*" pub:addinfo


NEW ERROR:

Code:
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
_________________
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze


Last edited by Fire-Fox on Mon Jun 04, 2012 5:17 pm; edited 2 times in total
Back to top
View user's profile Send private message MSN Messenger
speechles
Revered One


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

PostPosted: Mon Jun 04, 2012 5:12 pm    Post subject: Reply with quote

Code:
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.
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
Fire-Fox
Master


Joined: 23 Sep 2006
Posts: 270
Location: /dev/null

PostPosted: Mon Jun 04, 2012 5:16 pm    Post subject: Reply with quote

Thanks speechles Smile

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
Back to top
View user's profile Send private message MSN Messenger
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3645
Location: Mint Factory

PostPosted: Tue Jun 05, 2012 12:20 am    Post subject: Reply with quote

Then drop the:
Code:

   foreach line [split $content \n] {
      puts $fp [join $line "\n"]
   }

and make it:
Code:

puts $fp $content

_________________
Once the game is over, the king and the pawn go back in the same box.
Back to top
View user's profile Send private message
Fire-Fox
Master


Joined: 23 Sep 2006
Posts: 270
Location: /dev/null

PostPosted: Tue Jun 05, 2012 7:08 am    Post subject: Reply with quote

All done!

working as it should

Code:

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:

##################
### 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
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
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