Trouble with script fetching site
stephen.no at spam.theboulets.net.please
Wed Sep 3 15:20:05 CEST 2003
I'm trying to parse a url to set my hardware & system clock (linux).
Perhaps the best way to do this would be to use the urllib2 module to
convert a site to text, but since I haven't found that option yet, I did
this instead (which sometimes works, sometimes doesn't, and when it doesn't
seems to get hung up on line 4 -- os.popen oddity?):
url = "http://www.time.gov/timezone.cgi?Central/d/-6"
f = os.popen("lynx -dump " + url)
lines = f.readlines()
i = 0
for line in lines:
lines[i] = line.strip()
i += 1
for i in range(len(s)):
if s[i].find("Right now") > -1:
time = s
day,month,year = s.split(',')
month = month.strip()
month = month.split(' ')
month = ' '.join([month[0:3],month])
year = year.strip()
result = ' '.join([day, month, time, "CDT", year])
print "result is %s.\n" % result
command = 'date -u -s "' + result + '";hwclock --systohc'
print "Command is: \n\n%s.\n" % command
f = os.popen(command)
import: Unable to open file (os,sys).
/usr/local/bin/updatetime.py: line 4: url: command not found
/usr/local/bin/updatetime.py: line 5: syntax error near unexpected token `('
/usr/local/bin/updatetime.py: line 5: `f = os.popen("lynx -dump " + url)'
I'm fetching a site
From here to there
and there to here,
funny things are everywhere. -- Dr Seuss
More information about the Python-list