On my linux computer i'm running mysql + mysql.mod
I have a mysql database that is keeping the users online time in my channel.
So i have :
Now i have normal txt file, that contains the following:id names uptime
1 David 2 days 5 hours 24 minutues 1 second
2 Helen 5 weeks 3 days 29 minutes
3 Bonjo 6 days 4 hours 2 minutes
What i would like to do, is to make a little script that read the txt file, and checks if the users in the txt file are known in my mysql database.David was online for 2 hours 1 minute 3 seconds
Marcus was online for 1 day 3 hours 21 minutes 2 seconds
Helen was online for 35 minutes 25 seconds
Odeline was online for 3 days 25 minutes 3 seconds
David was online for 3 hours 2 minutes 25 seconds
Helen was online for 5 hours 3 minutes 1 second
...
If exist, the uptime will be updated [expr]
If the nick doesn't exist, it will have to be created.
I have already the following, but i don't know how to check if the field "names" has a user of my txt file.
Code: Select all
bind pub - "!update_data" update
proc update {nick uhost hand chan arg} {
mysql_connect MyDB localhost username passw /var/lib/mysql/mysql.sock
  set file [open /usr/account/eggdrop/logs/times.txt r] 
  set buf [read $file] 
  close $file 
  foreach line [split $buf \n] {
    set line [string trim $line " "] 
    if {$line == ""} {continue} 
    set line [split $line] 
    set user_nick [lindex $line 0] 
    set user_online [join [lrange $line 4 end]] 
    set user_online [converter $user_online]  #the proc convert is working good (put all in seconds)
    if {![info exists useronline($user_nick)]} { 
      set useronline($user_nick) $user_online 
    } else { 
      set useronline($user_nick) [expr $useronline($user_nick)+$user_online] 
    } 
  } 
  foreach {user_nick user_online} [array get useronline] {
#** here should come the part to check if user exists or not, but i'm totally lost for this part**
#So if user exist, i'll go directly to update of database
#If user doesn't exist, create the user with default data of table
#this is the part to update the database uptime
set presenttime [mysql_query "SELECT useruptime FROM Userinfo WHERE name='$usernick'"]
set convpresenttime [converter $presenttime]
set convuseronline [converter $user_online]
set useronline [expr $convuseronline+$convpresenttime]
set onlinetime [duration $user_online($user_nick)]
set newtime [mysql_query "UPDATE Userinfo SET useruptime='$onlinetime' WHERE name='$usernick'"] 
}
}
}
Buffy

 
  
 