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.

Weather Script - .py to .tcl conversion?

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
n
neocharles
Voice
Posts: 34
Joined: Tue Apr 23, 2013 4:29 pm

Weather Script - .py to .tcl conversion?

Post by neocharles »

I am looking at this script here... https://code.google.com/p/crappy-irc-bo ... 3ab1791b42

Any shot that can easily be moved over (and work) as a tcl file for an eggdrop?
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

Code: Select all

# e-mail:  tomekk/@/tomekk/./org
# home page: http://tomekk.org/
#
# Version 0.1
#
# This file is Copyrighted under the GNU Public License.
# http://www.gnu.org/copyleft/gpl.html

###########################################################
bind pub - !fw fweather

package require tdom
package require http

proc fweather { nick uhost hand chan arg } {
        set arg [string trim $arg]

        if {$arg != ""} {
                set f_url "http://thefuckingweather.com/?where=$arg"       

                regsub -all {\s} $f_url "+" f_url

                set f_fake_ua "Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Firefox/24.0"

                set f_token [http::config -useragent $f_fake_ua]

                if {[catch {set f_token [::http::geturl $f_url -timeout 10000]}]} {
                        putquick "PRIVMSG $chan :Error retrieving [censored] weather data!"
                } else {
                        set f_data [[dom parse -html [http::data $f_token]] getElementsByTagName span]
        
                        foreach f_loc_temp $f_data {
                                set location_data [string trim [$f_loc_temp asText]]

                                if {$location_data != ""} {
                                        if {[regexp {^([0-9]+)$} $location_data]} {
                                                set location_data "${location_data}°"
                                        }
                                        putquick "PRIVMSG $chan :$location_data"
                                } else {
                                        putquick "PRIVMSG $chan :location: $arg not found"
                                }
                        }
                }
        } else {
                putquick "PRIVMSG $chan :use: !fw <location>"
        }
}

putlog "fweather.tcl ver 0.1 by tomekk loaded"
n
neocharles
Voice
Posts: 34
Joined: Tue Apr 23, 2013 4:29 pm

Post by neocharles »

Thank you for doing this - Apparently I didn't have notifications turned on.

My problem now, however, is that it uses tdom. I used apt-get to install tdom and tdom-dev, but it still errors out when starting it.

Code: Select all

me@me:~/eggdrop/$ tclsh
% package require tdom
0.8.3
% exit
So it looks like it's installed... however

Code: Select all

[11:18:14] Tcl error in file 'eggdrop.conf':
[11:18:14] can't find package tdom
    while executing
"package require tdom"
    (file "scripts/fweather.tcl" line 12)
    invoked from within
"source scripts/fweather.tcl"
    (file "eggdrop.conf" line 1405)
[11:18:14] * CONFIG FILE NOT LOADED (NOT FOUND, OR ERROR)

<edit>

Looks like I had to just move over some things... thanks speechless for assisting.

Now, it's just a matter of re-writing some of this script to parse the data correctly....
Post Reply