Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
Status
Not open for further replies.
location-based weather?

I travel a lot for work and would like the weather in my GeekTool to auto-detect where my laptop is based on my IP address.

I can return my current city (as well as latitude/longitude) via the following:
http://api.hostip.info/get_xml.php

How can I use this data to load current and forecast weather? Does anyone know a weather service that I can feed the lat/long into the address? Or city and state?

Thanks much...
 
I travel a lot for work and would like the weather in my GeekTool to auto-detect where my laptop is based on my IP address.

I can return my current city (as well as latitude/longitude) via the following:
http://api.hostip.info/get_xml.php

How can I use this data to load current and forecast weather? Does anyone know a weather service that I can feed the lat/long into the address? Or city and state?

Thanks much...

page 120, post #2994.
 
Hello,

I need some help with a script. I am trying to display the temperature using a python script that grabs weather from yahoo. This already works with changing images, I just don't know how to display the output from python

Code:
do shell script "curl --silent 'http://weather.yahooapis.com/forecastrss?p=USCA0090&u=f' > /tmp/yahooweather.xml"

set conditions to do shell script "python /Users/Zach/Documents/Customize/GeekTool/Weather/Weather.py -c"
set currentTime to hours of (current date)
set temp to do shell script "python /Users/Zach/Documents/Customize/GeekTool/Weather/Weather.py -t"

# Display Temperature * * * * * * * * * * * * * * * * * * *
display??? temp

SO basically I want to display the temperature number via apple script and then import it into geek tool. How can I do this
 
Actually I have a better question --

How can I create a geektool script in a text file, and then call that text file to be displayed in Geektool? Is there any way to create external files and have geektool treat them the same way?
 
Hello,

I need some help with a script. I am trying to display the temperature using a python script that grabs weather from yahoo. This already works with changing images, I just don't know how to display the output from python

Code:
do shell script "curl --silent 'http://weather.yahooapis.com/forecastrss?p=USCA0090&u=f' > /tmp/yahooweather.xml"

set conditions to do shell script "python /Users/Zach/Documents/Customize/GeekTool/Weather/Weather.py -c"
set currentTime to hours of (current date)
set temp to do shell script "python /Users/Zach/Documents/Customize/GeekTool/Weather/Weather.py -t"

# Display Temperature * * * * * * * * * * * * * * * * * * *
display??? temp

SO basically I want to display the temperature number via apple script and then import it into geek tool. How can I do this

You're over-complicating things here. You don't need to be using Applescript at all for this, the weather.py script will output the appropriate text to the Geeklet.

Which weather.py script do you have? If it is mine from way back, re-read the instructions on the page on how to use the script. Geektool mimics a bash prompt, so any command you can put in bash, you can put into Geektool (I'm assuming that there are some exceptions to this).
 
Thank you for your response. I am not sure which weather.py I am using. If it is yours it is great :)

Code:
#!/usr/bin/env python

# INITIAL FIGURING OUT OF XML PARSING FROM Thomas Upton's (http://www.thomasupton.com/) weather.py SCRIPT
# HAVE LEARNED A LOT FROM HIS PYTHON SCRIPT

import sys
from optparse import OptionParser
from xml.dom.minidom import parse

# SET UP WEATHER NAME SERVICE FOR THE XML
weatherNS = 'http://xml.weather.yahoo.com/ns/rss/1.0'

# SET UP THE COMMAND LINE OPTION HOLDER
cmdparse = OptionParser()
    
# ADD COMMAND LINE OPTIONS
cmdparse.add_option('-t', '--temp', action="store_true", default=False)
cmdparse.add_option('-c', '--cond', action="store_true", default=False)
cmdparse.add_option('-o', '--code', action="store_true", default=False)
cmdparse.add_option('-b', '--both', action="store_true", default=False)

# PARSE THE COMMAND LINE OPITONS
opts, args = cmdparse.parse_args(sys.argv[1:])

# PARSE THE XML FILE
dom = parse("/tmp/yahooweather.xml")

# GRAB THE UNITS OF MEASURE AND CURRENT CONDITION
currUNITS = dom.getElementsByTagNameNS(weatherNS, 'units')[0]
currCOND  = dom.getElementsByTagNameNS(weatherNS, 'condition')[0]

I am trying to do external scripts so I don't have to put it directly into geektool. Are you saying I should just put all my code into a bash script and call it from GT? How would I do that without putting it directly into GT?

How would I do this just for temperature?

Thanks!
 
Hello,

I have a problem with this script that's supposed to show battery status for wireless keyboard and magic trackpad. It shows the battery status for trackpad correctly but I can't get it to show status for wireless keyboard :(


Code:
kbatt=`ioreg -c AppleBluetoothHIDKeyboard | grep BatteryPercent | tail -1|awk '{print $10}'`;
tbatt=`ioreg -c BNBTrackpadDevice | grep BatteryPercent | tail -1|awk '{print $10}'`;

if [ ${#kbatt} -lt 1 ]; then
  echo "Keyboard: disconnected"
else
  echo "Keyboard Battery: $kbatt%"
fi
if [ ${#tbatt} -lt 1 ]; then
  echo "Trackpad: disconnected"
else
  echo "Trackpad Battery: $tbatt%"
fi

This is what it looks like at the moment:

Screen%20shot%202011-06-25%20at%2020.11.24.png


Keyboard's battery level is 77% atm and it is connected but still it shows "disconnected" as you can see.

Any help would be appreciated :)
 
Hi,

Does anyone have solid weather and weather image scripts that do no require any other downloads or programs? Just simple scripts that I can enter into a shell or image selection?

How about any good processes scripts?

I am new to GeekTool and I have searched the thread but a lot of these scripts show up blank for me.

Thank you.
 
Hey, does anyone have a script for a battery bar that drains as the battery goes down instead of a percentage? I've seen them before but I could never find the code.


Thanks. :)
 
Hey guys,

I'd like to have a set-up that displays iTunes info when playing and a custom message displayed when iTunes is not playing. I'm currently using the following in Geektool shells to give me the current song name and artist:

Code:
osascript -e 'tell application "iTunes" to if player state is playing then get name of current track'
Code:
osascript -e 'tell application "iTunes" to if player state is playing then get artist of current track'

It keeps iTunes open, but I don't necessarily mind that. And I wouldn't want my iTunes info on a single line.

Is there a way to tweak these geeklets to display a message when iTunes is not playing? Like have the first say "iTunes is" and the second say "not playing", something like that? Been trying different things, no solution yet.
 
You're over-complicating things here. You don't need to be using Applescript at all for this, the weather.py script will output the appropriate text to the Geeklet.

Which weather.py script do you have? If it is mine from way back, re-read the instructions on the page on how to use the script. Geektool mimics a bash prompt, so any command you can put in bash, you can put into Geektool (I'm assuming that there are some exceptions to this).


xtacocorex,

I am trying to simply display the temperature.

When I use this script, it works, but I can only display a dialogue.

How would I import the result of this into geektool?

Thanks,
nobugs

Code:
do shell script "curl --silent 'http://weather.yahooapis.com/forecastrss?p=USCA0090&u=f' > /tmp/yahooweather.xml"

set temp to do shell script "python /Users/Zach/Documents/Customize/GeekTool/Weather/Weather.py -t"

# Display Temperature * * * * * * * * * * * * * * * * * * *
print temp
 
Hi Guys,

I really need help. When I was trying to move my Geeklets around, I clicked on my Weather Image Geeklet and made the height of it "2" and the top of it was behind the Menu Bar. Now it's basically the size of a line and it's assumed to be behind the Menu Bar. I can't see it but it's obviously there.

I can't even delete the Group. It just keeps renaming itself to Default Group when I try to delete everything.

What are my options here? Thank you.

EDIT: This almost seems unfixable. I deleted the .plist file and I couldn't tell if it was gone or not but just for giggles I created a new Weather Image (that I could see), deleted that .plist file, and it remained on the Desktop.

Any way to fix this?

EDIT2: I uninstalled Geektol via downloading it and using the "uninstall" option. I then did a Finder search for system files on my Mac with the search terms "geektool" and "geeklet" and I have deleted everything but there are four blank files called "org.tynsoe.geeklet.shell.plist" that cannot be deleted. In fact, I can't do anything to them, and couldn't while Geektool was still installed. They have no containing folder, it says "Calculating Size" for Size, and my Sharing & Permissions lists "you have unknown access."

What are these and is there a way I can get rid of them. Also, does uninstalling Geektool and reinstalling get rid of everything permanently?

I know this is a lot but if someone could help me then I would greatly appreciate it. Thank you.
 
Last edited by a moderator:
Hi Guys,

<snip>

I know this is a lot but if someone could help me then I would greatly appreciate it. Thank you.

First quit the app, then use "App cleaner" to fully delete all files then restart your mac then reinstall geektool & yes when u uninstall geektool it should get rid of evrything but thats why you should restart your mac before reinstalling...could be a glitch, thats all
 
Hi Guys,

I really need help.

...

I know this is a lot but if someone could help me then I would greatly appreciate it. Thank you.

Instead of doing all this, I'd just try to hide the menu bar so that you can see behind it. Here's how (on an app-to-app basis)
Just dont forget to bring it back to normal after!
 
Well, I already uninstalled and reinstalled GeekTool. That gets rid of all Image, File, and Shell Scripts, right? It got rid of all my visible Shell scripts of course, but I feel like the Image one is still there. I know that sounds stupid haha, it's just really annoying me.

Any info on those .plist files that are blank and cannot be deleted? Does anyone else have those when doing a system files search?

EDIT: I think those old .plists (I can view the Created Date at least) were from shells that I got rid of. When I click on them I have the option to "Delete Alias" (doesn't work of course), "Fix Alias" (doesn't work..) and "Ok." When I click "Open" inside the "Fix Alias" option I get Error Code -8060 when trying to open it. I cannot move or drag these files. I tried creating a folder to store them in order to trash it but that did not work. They do not show up in my Library > Preferences folder; only in a Finder search that includes System Files. I would appreciate if anyone would do a similar search and discover whether or not I am the only one with these ghostly files on my computer. : )

Thanks for the help.
 
Last edited by a moderator:
xtacocorex,

I am trying to simply display the temperature.

When I use this script, it works, but I can only display a dialogue.

How would I import the result of this into geektool?

Thanks,
nobugs

Code:
do shell script "curl --silent 'http://weather.yahooapis.com/forecastrss?p=USCA0090&u=f' > /tmp/yahooweather.xml"

set temp to do shell script "python /Users/Zach/Documents/Customize/GeekTool/Weather/Weather.py -t"

# Display Temperature * * * * * * * * * * * * * * * * * * *
print temp

So the new problem is interesting, I don't mess with Applescript all that often, but the
Code:
print temp
is actually trying to send the variable to the printer, it's looking for a file named whatever your temperature is at the given moment (mine happened to be "68F").

The only way I know to print stuff to the screen is with the
Code:
return
syntax.

This also poses problems because as soon as you call the first return, any commands that follow the first return will not be executed due to how return works.

I've tried messing around with "handlers" in Applescript (which is their term for a function), but that didn't work too well either.

I still stand by my statement of this being too complex if you're still going down the route of putting all of the information you want to have shown in one large applescript.

I also think that one large geeklet will be more of a resource hog than multiple small scripts due to the fact that you'd probably set the refresh rate based on the most pertinent information you want to see (which would be a quick refresh) and that would cause all the items in the Applescript to update.

Now if you're just using small Applescripts to wrap single program calls so you just have to do an
Code:
osascript mysmallapplescript.scpt
instead of all the commands in one geeklet, the "return" in the script will work to display the data you want.
 
So the new problem is interesting, I don't mess with Applescript all that often, but the
Code:
print temp
is actually trying to send the variable to the printer, it's looking for a file named whatever your temperature is at the given moment (mine happened to be "68F").

The only way I know to print stuff to the screen is with the
Code:
return
syntax.

This also poses problems because as soon as you call the first return, any commands that follow the first return will not be executed due to how return works.

I've tried messing around with "handlers" in Applescript (which is their term for a function), but that didn't work too well either.

I still stand by my statement of this being too complex if you're still going down the route of putting all of the information you want to have shown in one large applescript.

I also think that one large geeklet will be more of a resource hog than multiple small scripts due to the fact that you'd probably set the refresh rate based on the most pertinent information you want to see (which would be a quick refresh) and that would cause all the items in the Applescript to update.

Now if you're just using small Applescripts to wrap single program calls so you just have to do an
Code:
osascript mysmallapplescript.scpt
instead of all the commands in one geeklet, the "return" in the script will work to display the data you want.

That did it! You fixed it, thank you very much!

Actually I'm not doing everything in one applescript file because of the problems you addressed. I definitely am doing it modularly.

However I only want one geeklet per function (ie. one weather script, one cpu script, etc) called externally. For most I just put it in a bash or python file and call it from geektool with that same syntax you provided (except python or bash) but weather is a little more tricky considering I want the image and the degrees.

I am using your script, the only problem is it didn't display the temperature. Now it does thanks to you ;)

Any ideas on how I could append the degrees symbol to the temperature? Should I edit the python script or the Apple Script?

Now to figure out how I can automatically get weather based on my computer's location...
 
Here is an updated weather script that allows you to output the degree symbol and will grab weather based on your location.

You will not need to input a URL into this code and the "curl --silent myurl > /tmp/weather.xml" no longer needs to be done.

The location grabbing works as follows, it will grab your external IP address and then figure out your location. From that, it will grab the Yahoo WOEID for your location. This WOEID is mapped to your zipcode and then stored in a file in your home directory (it's hidden so you can't see it). The code defaults to look at the map file to find your WOEID so it doesn't have to use the Yahoo Query Language (YQL)servers unless the WOEID for your current location could not be found in the map file. (The YQL servers have a limited number of hits per hour that you can use)

I have weather image stuff working (and there are other examples in this thread), that is why there is the option in this code to output the weather code. Yahoo has a group of weather images that map to those codes. For my display of the weather image, I took the images from the 5 Day Yahoo Weather Widget, re-colored them to all white, and then built another script to display them. This is my current setup: https://forums.macrumors.com/posts/12866218/

Code:
#!/usr/bin/env python

# INITIAL FIGURING OUT OF XML PARSING FROM Thomas Upton's (http://www.thomasupton.com/) weather.py SCRIPT
# HAVE LEARNED A LOT FROM HIS PYTHON SCRIPT

import sys, urllib, os, re, ast
from optparse import OptionParser
from xml.dom.minidom import parse

# SET UP WEATHER NAME SERVICE FOR THE XML
weatherNS = 'http://xml.weather.yahoo.com/ns/rss/1.0'
WEATHER_URL = 'http://xml.weather.yahoo.com/forecastrss?p=%s'
METRIC_PARAMETER = '&u=c'
URLTYPE = "RSS"

# FILE FOR WHERE THE WOEID TO ZIPCODE MAP GOES
# CURRENTLY SET TO BE A HIDDEN FOLDER IN THE USERS HOME DIRECTORY
# YOU CAN CUSTOMIZE THIS IF YOU WANT THE FILE SOMEPLACE ELSE
FCASTWOEIDDATA = os.getenv('HOME') + os.path.sep + ".zip_woeid_map.txt"

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

# DEBUG FLAG
DEBUG = False
UNITTEST = False
UNITS = "F"

YQLBASEURL = "http://query.yahooapis.com/v1/public/yql"
IPLOCURL   = "http://ipinfodb.com/my_ip_location.php"

# CONSTANTS
COMMA = "%2C"
SPACE = "%20"
EQUAL = "%3D"

def myencode(instr):
    rstr = ""
    for i in xrange(len(instr)):
        if   instr[i] == " ":
            rstr += SPACE
        elif instr[i] == "=":
            rstr += EQUAL
        else:
            rstr += instr[i]
    
    return rstr

def getLocationData():
    """
        getWOEID
         - FUNCTION TO GET THE WOEID ID FROM THE LOCALLY STORED DATABASE
          OR
           PULLS THE DATA FROM THE INTERNET AND STORES INTO THE DATABASE
         - INPUT:  NONE
         - OUPUTS: locdict - DICTIONARY OF LOCATION DATA
    """
    # SET UP OUR DICTIONARY
    locdict = { 'zipcode' : "", 
                'country' : "",
                'stprov'  : "", 
                'city'    : "",
                'lat'     : "",
                'lon'     : ""}
    
    # GET THE ZIP CODE BASED UPON OUR EXTERNAL IP ADDRESS
    if not UNITTEST:
        url = urllib.urlopen(IPLOCURL)
        ippagedata = url.read()
        url.close()
    
    if UNITTEST and DEBUG:
        # DEBUG
        print "USING LOCAL FILE"
        loco = open("./myloc.txt")
        ippagedata = loco.read()
        loco.close()
    
    # REGULAR EXPRESSION TO FIND THE NEEDED DATA IN THE WEBPAGE
    # WOULD BE BETTER TO USE SGML TO PARSE THE HTML BUT I DON'T
    # WANT TO FIGURE IT OUT
    
    # GET THE COUNTRY
    mat = re.search('<li>Country : .*<img',ippagedata)
    locdict['country'] = mat.group(0).split(': ')[1].split('<img')[0].rstrip().lower()
    
    # GET THE STATE/PROVINCE
    mat = re.search('<li>State/Province : .*</li>',ippagedata)
    locdict['stprov'] = mat.group(0).split(': ')[1].split('</li>')[0].lower()
    
    # GET THE CITY
    mat = re.search('<li>City : .*</li>',ippagedata)
    locdict['city'] = mat.group(0).split(': ')[1].split('</li>')[0].lower()
    
    # GET THE ZIP CODE
    mat = re.search('<li>Zip or postal code : .*</li>',ippagedata)
    locdict['zipcode'] = mat.group(0).split(': ')[1].split('</li>')[0]

    # GET THE LATITUDE
    mat = re.search('<li>Latitude : .*</li>',ippagedata)
    locdict['lat'] = mat.group(0).split(': ')[1].split('</li>')[0]

    # GET THE LONGITUDE
    mat = re.search('<li>Longitude : .*</li>',ippagedata)
    locdict['lon'] = mat.group(0).split(': ')[1].split('</li>')[0]

    # RETURN THE LOCATION DICTIONARY
    return locdict

def getWOEID(zipcode):
    """
        getWOEID
         - FUNCTION TO GET THE WOEID ID FROM THE LOCALLY STORED DATABASE
          OR
           PULLS THE DATA FROM THE INTERNET AND STORES INTO THE DATABASE
         - INPUT:  zipcode - ZIPCODE FROM LOCATION DATA OR USER INPUT
         - OUPUTS: woeid   - THE WOEID WE WANT BASED ON OUR ZIPCODE
    """
    
    # CHECK TO SEE IF THE ZIP IS IN THE FILE
    haveWOEID = False
    infile    = False
    if os.path.isfile(FCASTWOEIDDATA):
        fin = open(FCASTWOEIDDATA,'r+a')
        infile = True
    else:
        # WE HIT THE CASE WHERE THE FILE DOESN'T EXIST
        fin = open(FCASTWOEIDDATA,'w')
        infile = False
        
    # IF WE HAVE THE INPUT FILE, LOOK FOR OUR ZIPCODE
    if infile:
        for line in fin.readlines():
            if zipcode in line:
                haveWOEID = True
                # GET THE WOEID AND RIGHT STRIP TO REMOVE THE RETURN LINE FROM THE FILE
                woeid     = line.split(",")[1].rstrip()
                # NOT RETURNING HERE SO WE CAN GRACEFULLY CLOSE THE INPUT FILE
                # THIS IS A STUPID LITTLE ISSUE
            else:
                haveWOEID = False

    # IF WE DON'T HAVE THE WOEID, LET'S GET THE SHIZZLE AND STORE LOCALLY    
    if not haveWOEID:
    
        # GET THE URL TO FIND WOEID
        yqlquery  = "select woeid from geo.places where text=" + zipcode + " limit 1"
        yqlformat = "json"
        WOEIDURL = YQLBASEURL + "?q=" + myencode(yqlquery) + "&format=" + yqlformat
        
        # GET THE DATA FROM THE INTERNETS
        reqresp = urllib.urlopen(WOEIDURL)
        
        # NEED TO BREAK THE STRING INTO THE APPROPRIATE DICTIONARY STRUCTURE
        resp    = ast.literal_eval(reqresp.read())
        reqresp.close()
        
        # SEARCH THE RESPONSE FOR THE WOEID
        # JSON IS AWESOME! YAY FOR NESTED DICTIONARIES
        woeid = resp['query']['results']['place']['woeid']
        
        # WRITE THE DATA TO THE FILE
        fmt = "%s,%s\n" % (zipcode, woeid)
        fin.write(fmt)
    
    # NOW WE CAN CLOSE THE FILE
    fin.close()
    
    # RETURN THE WOEID WE FOUND
    return woeid

def makeUrl(utype,locdict,woeid,units):
    """
        makeUrl
         - FUNCTION TO CREATE THE URL FOR EITHER THE YAHOO WEATHER RSS
           OR THE 5-DAY FORECAST
         - INPUT:  utype   - TYPE OF URL: RSS OR 5DAY
                   locdict - ZIPCODE FROM LOCATION DATA OR USER INPUT
                   woeid   - THE WOEID WE WANT BASED ON OUR ZIPCODE
                   units   - UNITS OF MEASURE
         - OUPUTS: url     - THE URL FOR THE PAGE WE WANT TO PARSE
    """
    if   utype == "RSS":
        url = "http://weather.yahooapis.com/forecastrss?w="+woeid
        if units == "C":
            url += "&u=c"
    elif utype == "5DAY":
        # FORMAT THE COUNTRY PROPERLY
        tmp = locdict['country'].split(" ")
        country = ""
        for i in xrange(len(tmp)):
            country += tmp[i]
            if i < len(tmp)-1:
                country += "-"
        
        # FORMAT THE STATE/PROVINCE CORRECTLY
        tmp = locdict['stprov'].split(" ")
        stprov = ""
        for i in xrange(len(tmp)):
            stprov += tmp[i]
            if i < len(tmp)-1:
                stprov += "-"
        
        # FORMAT THE CITY PROPERLY
        tmp = locdict['city'].split(" ")
        city = ""
        for i in xrange(len(tmp)):
            city += tmp[i]
            if i < len(tmp)-1:
                city += "-"
    
        # GENERATE URL
        url = "http://weather.yahoo.com/" + country + "/" + stprov + "/" + city + "-" + woeid + "/"
    
        if DEBUG:
            print country
            print stprov
            print city
        
        if units == "C":
            url += "&unit=c"

    # RETURN THE URL
    return url

if __name__ == "__main__":

    # SET UP THE COMMAND LINE OPTION HOLDER
    cmdparse = OptionParser()
        
    # ADD COMMAND LINE OPTIONS
    cmdparse.add_option('-t', '--temp', action="store_true", default=False)
    cmdparse.add_option('-d', '--deg', action="store_true", default=False)
    cmdparse.add_option('-c', '--cond', action="store_true", default=False)
    cmdparse.add_option('-o', '--code', action="store_true", default=False)
    cmdparse.add_option('-b', '--both', action="store_true", default=False)
    cmdparse.add_option('-m', '--metric', action="store_true", default=False)
    
    # PARSE THE COMMAND LINE OPITONS
    opts, args = cmdparse.parse_args(sys.argv[1:])
        
     # GET OUR LOCATION DICTIONARY
    locdict = getLocationData()

    if (opts.metric):
        UNITS = "C"
    
    # GET OUR WOEID
    mywoeid = getWOEID(locdict['zipcode'])

    # GET THE APPROPRIATE URL WE REQUIRE
    url = makeUrl(URLTYPE,locdict,mywoeid,UNITS)
    
    # PARSE THE XML FILE
    dom = parse(urllib.urlopen(url))
    
    # GRAB THE UNITS OF MEASURE AND CURRENT CONDITION
    currUNITS = dom.getElementsByTagNameNS(weatherNS, 'units')[0]
    currCOND  = dom.getElementsByTagNameNS(weatherNS, 'condition')[0]
    
    # PARSE OUT currUNITS AND currCond
    unit     = currUNITS.getAttribute('temperature')
    currWX   = currCOND.getAttribute('text')
    currTEMP = currCOND.getAttribute('temp')
    currCODE = currCOND.getAttribute('code')
    
    # PRINT OUT DATA BASED UPON CLI ARGUMENTS
    if (opts.temp):
        if (opts.deg):
            print currTEMP + unichr(176) + unit
        else:
            print currTEMP + unit
    
    if (opts.cond):
        print currWX
    
    if (opts.code):
        print currCODE
        
    if (opts.both):
        print currWX + ", " + currTEMP + unit
 
Last edited:
xtacore

that looks awesome. However when I run the script I get an error (with the same AppleScript to change the image and display the temperature). I got rid of the --curl...

error "Traceback (most recent call last):
File \"/Users/Z/Documents/Customize/GeekTool/Weather/weather2.py\", line 248, in <module>
mywoeid = getWOEID(locdict['zipcode'])
File \"/Users/Z/Documents/Customize/GeekTool/Weather/weather2.py\", line 154, in getWOEID
resp = ast.literal_eval(reqresp.read())
NameError: global name 'ast' is not defined" number 1
 
xtacore

that looks awesome. However when I run the script I get an error (with the same AppleScript to change the image and display the temperature). I got rid of the --curl...

error "Traceback (most recent call last):
File \"/Users/Z/Documents/Customize/GeekTool/Weather/weather2.py\", line 248, in <module>
mywoeid = getWOEID(locdict['zipcode'])
File \"/Users/Z/Documents/Customize/GeekTool/Weather/weather2.py\", line 154, in getWOEID
resp = ast.literal_eval(reqresp.read())
NameError: global name 'ast' is not defined" number 1

In the python script, in the import section, change the following line
Code:
import sys, urllib, os, re
to
Code:
import sys, urllib, os, re, ast

Forgot to add the import for that module when I copied code over from my other scripts.
 
One more thing now that I've added both the -t and -d options from Apple Script. It has a problem with the encoding method for the degrees symbol:

error "Traceback (most recent call last):
File \"/Users/Z/Documents/Customize/GeekTool/Weather/weather.py\", line 270, in <module>
print currTEMP + unichr(176) + unit
UnicodeEncodeError: 'ascii' codec can't encode character u'\\xb0' in position 2: ordinal not in range(128)" number 1


I've tried all I could reencoding the character, and even changing the coding of the script to no avail. Can you tackle this one?
 
One more thing now that I've added both the -t and -d options from Apple Script. It has a problem with the encoding method for the degrees symbol:

error "Traceback (most recent call last):
File \"/Users/Z/Documents/Customize/GeekTool/Weather/weather.py\", line 270, in <module>
print currTEMP + unichr(176) + unit
UnicodeEncodeError: 'ascii' codec can't encode character u'\\xb0' in position 2: ordinal not in range(128)" number 1


I've tried all I could reencoding the character, and even changing the coding of the script to no avail. Can you tackle this one?

I think you need to change the Geeklet from Ascii encoding to Unicode. The python script works perfect in the terminal. If changing the encoding doesn't work, it's probably something in Applescript.
 
Status
Not open for further replies.
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.