KP_URL = 'http://sec.noaa.gov/rpc/costello/ace_pkp_15m.txt'
a = urllib.urlopen(KP_URL)
b = a.read()
a.close()
localfile = '/tmp/get_kp.txt';
a = open(localfile,'w');
a.write(b);
a.close();
a = open(localfile,'r');
lines = []
while 1:
line = a.readline()
if not line:
print "shouldn't have hit this ?? (exit)"
exit
if line[0] == ':' or line[0] == '#': continue
g = string.split(line);
if g[-1] == '-1.00':
break
else:
lines = line, lines[:]
a.close();
t = time.gmtime(time.time())
print '# current time UT %d %02d %02d %02d%02d' % (t[0],t[1],t[2],t[3],t[4])
s = string.split(lines[0]);
print '# recent Kp at UT %s %s %s %s' % (s[0],s[1],s[2],s[3])
kp = s[-1]
print kp
Traceback (most recent call last): localfile = '/tmp/get_kp.txt';
File "", line 1, in <module>
File "/tmp/tmpgqzwmB/___code___.py", line 5, in <module>
a = urllib.urlopen(KP_URL)
NameError: name 'urllib' is not defined