Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pywx v2.0.1
- I removed the IRC functions because I would prefer not to have 15 pywx's...
- Also it doesn't create all the files it needs and I'm not sure how to do that... And you'll need to recode it to just work in the cmd (which is how version 1 worked on my comp)
- [code]
- def ping(): # This is our first function! It will respond to server Pings.
- ircsock.send("PONG :pingis\n")
- wx()
- def findnth(haystack, needle, n):
- parts= haystack.split(needle, n+1)
- if len(parts)<=n+1:
- return -1
- return len(haystack)-len(parts[-1])-len(needle)
- def sendmsg(chan , msg): # This is the send message function, it simply sends messages to the channel.
- ircsock.send("PRIVMSG "+ chan +" :"+ msg +"\n")
- def joinchan(chan): # This function is used to join channels.
- ircsock.send("JOIN "+ chan +"\n")
- def hello(): # This function responds to a user that inputs "Hello Mybot"
- ircsock.send("PRIVMSG "+ channel +" :Hello!\n")
- def grand():
- i = int(random.random()*2)
- j = int(random.random()*2)
- k = a[i] + b[j]
- ircsock.send("PRIVMSG "+ channel +" : Your generated string is\:"+ k +"\n")
- def wx():
- s1 = wptq20()
- s4 = wtnt21()
- s5 = wtnt22()
- s6 = wtnt23()
- s7 = wtnt24()
- s8 = wtnt25()
- s9 = wtin20()
- s10 = wwjp25()
- s11 = wtio30()
- s12 = wtpz21()
- s13 = wtpz22()
- s14 = wtpz23()
- s15 = wtpz24()
- s16 = wtpz25()
- s17 = wwps21()
- s18 = wtps11()
- s19 = axau01()
- s20 = axau02()
- #s21 = axau03()
- s22 = axau01_adrm()
- s23 = axau21()
- if s1:
- ircsock.send("PRIVMSG "+ channel +" :"+ s1 +"\n")
- if s4:
- ircsock.send("PRIVMSG "+ channel +" :"+ s4 +"\n")
- if s5:
- ircsock.send("PRIVMSG "+ channel +" :"+ s5 +"\n")
- if s6:
- ircsock.send("PRIVMSG "+ channel +" :"+ s6 +"\n")
- if s7:
- ircsock.send("PRIVMSG "+ channel +" :"+ s7 +"\n")
- if s8:
- ircsock.send("PRIVMSG "+ channel +" :"+ s8 +"\n")
- if s9:
- ircsock.send("PRIVMSG "+ channel +" :"+ s9 +"\n")
- if s10:
- ircsock.send("PRIVMSG "+ channel +" :"+ s10 +"\n")
- if s11:
- ircsock.send("PRIVMSG "+ channel +" :"+ s11 +"\n")
- if s12:
- ircsock.send("PRIVMSG "+ channel +" :"+ s12 +"\n")
- if s13:
- ircsock.send("PRIVMSG "+ channel +" :"+ s13 +"\n")
- if s14:
- ircsock.send("PRIVMSG "+ channel +" :"+ s14 +"\n")
- if s15:
- ircsock.send("PRIVMSG "+ channel +" :"+ s15 +"\n")
- if s16:
- ircsock.send("PRIVMSG "+ channel +" :"+ s16 +"\n")
- if s17:
- ircsock.send("PRIVMSG "+ channel +" :"+ s17 +"\n")
- if s18:
- ircsock.send("PRIVMSG "+ channel +" :"+ s18 +"\n")
- if s19:
- ircsock.send("PRIVMSG "+ channel +" :"+ s19 +"\n")
- if s20:
- ircsock.send("PRIVMSG "+ channel +" :"+ s20 +"\n")
- #if s21:
- # ircsock.send("PRIVMSG "+ channel +" :"+ s21 +"\n")
- if s22:
- ircsock.send("PRIVMSG "+ channel +" :"+ s22 +"\n")
- if s23:
- ircsock.send("PRIVMSG "+ channel +" :"+ s23 +"\n")
- else:
- pass
- def wwjp25():
- file = urllib2.urlopen("http://weather.noaa.gov/pub/data/raw/ww/wwjp25.rjtd..txt")
- output = open('wwjp25_1.txt','w+b')
- output.write(file.read())
- output.seek(0)
- header = output.read(6)
- output.seek(12)
- newproducttime = output.read(6)
- output.close()
- output = open('wwjp25.txt','rb')
- output.seek(12)
- producttime = output.read(6)
- output.close()
- if newproducttime != producttime:
- output = open('wwjp25.txt','w+b')
- copy = open('wwjp25_1.txt','rb')
- output.write(copy.read())
- output.close()
- copy.seek(0)
- line_offset = []
- offset = 0
- for line in copy:
- line_offset.append(offset)
- offset += len(line)
- copy.seek(0)
- test = copy.read()
- if test.find("TROPICAL DEPRESSION") != -1:
- index = test.find("TROPICAL DEPRESSION")
- copy.seek(index)
- name = copy.readline()
- name = name.strip('\n')
- index = test.find("HPA AT")
- if index != -1:
- update = "WWJP25 %s" % (name)
- copy.close()
- return update
- def wptq20():
- file = urllib2.urlopen("http://weather.noaa.gov/pub/data/raw/wt/wtpq20.rjtd..txt")
- output = open('wtpq20_1.txt','w+b')
- output.write(file.read())
- output.seek(0)
- header = output.read(6)
- output.seek(12)
- newproducttime = output.read(6)
- output.close()
- output = open('wtpq20.txt','rb')
- output.seek(12)
- producttime = output.read(6)
- output.close()
- if newproducttime != producttime:
- output = open('wtpq20.txt','w+b')
- copy = open('wtpq20_1.txt','rb')
- output.write(copy.read())
- output.close()
- copy.seek(0)
- #Read in the file once and build a list of line offsets
- line_offset = []
- offset = 0
- for line in copy:
- line_offset.append(offset)
- offset += len(line)
- copy.seek(line_offset[2]+6)
- name = copy.readline()
- name = name.strip('\n')
- copy.seek(line_offset[4]+16)
- location = copy.readline()
- location = location.strip('\n')
- copy.seek(line_offset[5]+6)
- dir = copy.readline()
- dir = dir.strip('\n')
- copy.seek(line_offset[6]+6)
- pres = copy.readline()
- pres = pres.strip('\n')
- copy.seek(line_offset[7]+6)
- wind = copy.readline()
- wind = wind.strip('\n')
- update = "WTPQ20 %s %s %s %s %s" % (name, location, dir, pres, wind)
- copy.close()
- return update
- def wtnt21():
- file = urllib2.urlopen("http://weather.noaa.gov/pub/data/raw/wt/wtnt21.knhc.tcm.at1.txt")
- output = open('wtnt21_1.txt','w+b')
- output.write(file.read())
- output.seek(0)
- header = output.read(6)
- output.seek(12)
- newproducttime = output.read(6)
- output.close()
- output = open('wtnt21.txt','rb')
- output.seek(12)
- producttime = output.read(6)
- output.close()
- if newproducttime != producttime:
- output = open('wtnt21.txt','w+b')
- copy = open('wtnt21_1.txt','rb')
- output.write(copy.read())
- #output.close()
- copy.seek(0)
- line_offset = []
- offset = 0
- for line in copy:
- line_offset.append(offset)
- offset += len(line)
- copy.seek(0)
- test = copy.read()
- index = test.find(" AL")
- copy.seek(index+1)
- name = copy.readline()
- name = name.strip('\n')
- index = test.find("NEAR")
- copy.seek(index+5)
- location = copy.readline()
- location = location.strip('\n')
- index = test.find("MOVEMENT")
- copy.seek(index+9)
- dir = copy.readline()
- dir = dir.strip('\n')
- index = test.find("PRESSURE")
- copy.seek(index+9)
- pres = copy.readline()
- pres = pres.strip('\n')
- index = test.find("WINDS")
- copy.seek(index+5)
- wind = copy.read(7)
- wind = wind.strip('\n')
- update = "WTNT21 %s %s %s %s %s" % (name, location, dir, pres, wind)
- copy.close()
- return update
- def wtnt22():
- file = urllib2.urlopen("http://weather.noaa.gov/pub/data/raw/wt/wtnt22.knhc.tcm.at2.txt")
- output = open('wtnt22_1.txt','w+b')
- output.write(file.read())
- output.seek(0)
- header = output.read(6)
- output.seek(12)
- newproducttime = output.read(6)
- output.close()
- output = open('wtnt22.txt','rb')
- output.seek(12)
- producttime = output.read(6)
- output.close()
- if newproducttime != producttime:
- output = open('wtnt22.txt','w+b')
- copy = open('wtnt22_1.txt','rb')
- output.write(copy.read())
- #output.close()
- copy.seek(0)
- line_offset = []
- offset = 0
- for line in copy:
- line_offset.append(offset)
- offset += len(line)
- copy.seek(0)
- test = copy.read()
- index = test.find(" AL")
- copy.seek(index+1)
- name = copy.readline()
- name = name.strip('\n')
- index = test.find("NEAR")
- copy.seek(index+5)
- location = copy.readline()
- location = location.strip('\n')
- index = test.find("MOVEMENT")
- copy.seek(index+9)
- dir = copy.readline()
- dir = dir.strip('\n')
- index = test.find("PRESSURE")
- copy.seek(index+9)
- pres = copy.readline()
- pres = pres.strip('\n')
- index = test.find("WINDS")
- copy.seek(index+5)
- wind = copy.read(7)
- wind = wind.strip('\n')
- update = "WTNT22 %s %s %s %s %s" % (name, location, dir, pres, wind)
- copy.close()
- return update
- def wtnt23():
- file = urllib2.urlopen("http://weather.noaa.gov/pub/data/raw/wt/wtnt23.knhc.tcm.at3.txt")
- output = open('wtnt23_1.txt','w+b')
- output.write(file.read())
- output.seek(0)
- header = output.read(6)
- output.seek(12)
- newproducttime = output.read(6)
- output.close()
- output = open('wtnt23.txt','rb')
- output.seek(12)
- producttime = output.read(6)
- output.close()
- if newproducttime != producttime:
- output = open('wtnt23.txt','w+b')
- copy = open('wtnt23_1.txt','rb')
- output.write(copy.read())
- #output.close()
- copy.seek(0)
- line_offset = []
- offset = 0
- for line in copy:
- line_offset.append(offset)
- offset += len(line)
- copy.seek(0)
- test = copy.read()
- index = test.find(" AL")
- copy.seek(index+1)
- name = copy.readline()
- name = name.strip('\n')
- index = test.find("NEAR")
- copy.seek(index+5)
- location = copy.readline()
- location = location.strip('\n')
- index = test.find("MOVEMENT")
- copy.seek(index+9)
- dir = copy.readline()
- dir = dir.strip('\n')
- index = test.find("PRESSURE")
- copy.seek(index+9)
- pres = copy.readline()
- pres = pres.strip('\n')
- index = test.find("WINDS")
- copy.seek(index+5)
- wind = copy.read(7)
- wind = wind.strip('\n')
- update = "WTNT23 %s %s %s %s %s" % (name, location, dir, pres, wind)
- copy.close()
- return update
- def wtnt24():
- file = urllib2.urlopen("http://weather.noaa.gov/pub/data/raw/wt/wtnt24.knhc.tcm.at4.txt")
- output = open('wtnt24_1.txt','w+b')
- output.write(file.read())
- output.seek(0)
- header = output.read(6)
- output.seek(12)
- newproducttime = output.read(6)
- output.close()
- output = open('wtnt24.txt','rb')
- output.seek(12)
- producttime = output.read(6)
- output.close()
- if newproducttime != producttime:
- output = open('wtnt24.txt','w+b')
- copy = open('wtnt24_1.txt','rb')
- output.write(copy.read())
- #output.close()
- copy.seek(0)
- line_offset = []
- offset = 0
- for line in copy:
- line_offset.append(offset)
- offset += len(line)
- copy.seek(0)
- test = copy.read()
- index = test.find(" AL")
- copy.seek(index+1)
- name = copy.readline()
- name = name.strip('\n')
- index = test.find("NEAR")
- copy.seek(index+5)
- location = copy.readline()
- location = location.strip('\n')
- index = test.find("MOVEMENT")
- copy.seek(index+9)
- dir = copy.readline()
- dir = dir.strip('\n')
- index = test.find("PRESSURE")
- copy.seek(index+9)
- pres = copy.readline()
- pres = pres.strip('\n')
- index = test.find("WINDS")
- copy.seek(index+5)
- wind = copy.read(7)
- wind = wind.strip('\n')
- update = "WTNT24 %s %s %s %s %s" % (name, location, dir, pres, wind)
- copy.close()
- return update
- def wtnt25():
- file = urllib2.urlopen("http://weather.noaa.gov/pub/data/raw/wt/wtnt25.knhc.tcm.at5.txt")
- output = open('wtnt25_1.txt','w+b')
- output.write(file.read())
- output.seek(0)
- header = output.read(6)
- output.seek(12)
- newproducttime = output.read(6)
- output.close()
- output = open('wtnt25.txt','rb')
- output.seek(12)
- producttime = output.read(6)
- output.close()
- if newproducttime != producttime:
- output = open('wtnt25.txt','w+b')
- copy = open('wtnt25_1.txt','rb')
- output.write(copy.read())
- #output.close()
- copy.seek(0)
- line_offset = []
- offset = 0
- for line in copy:
- line_offset.append(offset)
- offset += len(line)
- copy.seek(0)
- test = copy.read()
- index = test.find(" AL")
- copy.seek(index+1)
- name = copy.readline()
- name = name.strip('\n')
- index = test.find("NEAR")
- copy.seek(index+5)
- location = copy.readline()
- location = location.strip('\n')
- index = test.find("MOVEMENT")
- copy.seek(index+9)
- dir = copy.readline()
- dir = dir.strip('\n')
- index = test.find("PRESSURE")
- copy.seek(index+9)
- pres = copy.readline()
- pres = pres.strip('\n')
- index = test.find("WINDS")
- copy.seek(index+5)
- wind = copy.read(7)
- wind = wind.strip('\n')
- update = "WTNT25 %s %s %s %s %s" % (name, location, dir, pres, wind)
- copy.close()
- return update
- def wtin20():
- file = urllib2.urlopen("http://weather.noaa.gov/pub/data/raw/wt/wtin20.dems..txt")
- output = open('wtin20_1.txt','w+b')
- output.write(file.read())
- output.seek(0)
- header = output.read(6)
- output.seek(12)
- newproducttime = output.read(6)
- output.close()
- output = open('wtin20.txt','rb')
- output.seek(12)
- producttime = output.read(6)
- output.close()
- if newproducttime != producttime:
- output = open('wtin20.txt','w+b')
- copy = open('wtin20_1.txt','rb')
- output.write(copy.read())
- #output.close()
- copy.seek(0)
- line_offset = []
- offset = 0
- for line in copy:
- line_offset.append(offset)
- offset += len(line)
- copy.seek(0)
- test = copy.read()
- if test.find(" STORM") != -1:
- index = test.find(" STORM")
- copy.seek(index+6)
- name = copy.readline()
- name = name.strip('\n')
- index = test.find("LATITUDE")
- copy.seek(index)
- location = copy.read(37)
- location = location.strip('\n')
- #index = test.find("MOVEMENT")
- #copy.seek(index+9)
- #dir = copy.readline()
- #dir = dir.strip('\n')
- #index = test.find("PRESSURE")
- #copy.seek(index+9)
- #pres = copy.readline()
- #pres = pres.strip('\n')
- index = test.find("(KMPH)")
- copy.seek(index+41)
- wind1 = copy.read(3)
- wind1 = int(wind1.strip('-'))
- copy.seek(index+44)
- wind2 = copy.read(3)
- wind2 = int(wind2.strip(' '))
- wind = (wind1 + wind2) / 2
- update = "WTIN20 %s %s %s km/h" % (name, location, wind)
- copy.close()
- return update
- def wtio30():
- file = urllib2.urlopen("http://weather.noaa.gov/pub/data/raw/wt/wtio30.fmee..txt")
- output = open('wtio30_1.txt','w+b')
- output.write(file.read())
- output.seek(0)
- header = output.read(6)
- output.seek(12)
- newproducttime = output.read(6)
- output.close()
- output = open('wtio30.txt','rb')
- output.seek(12)
- producttime = output.read(6)
- output.close()
- if newproducttime != producttime:
- output = open('wtio30.txt','w+b')
- copy = open('wtio30_1.txt','rb')
- output.write(copy.read())
- output.close()
- copy.seek(0)
- #Read in the file once and build a list of line offsets
- copy.seek(0)
- test = copy.read()
- index = test.find("1.A")
- #
- copy.seek(index)
- nameline = copy.readline()
- if nameline.find("TROPICAL STORM") != -1:
- tmpind = index + nameline.find("TROPICAL STORM") + len("TROPICAL STORM")
- copy.seek(tmpind+1)
- tmpcode = copy.read(2)
- elif nameline.find("TROPICAL CYCLONE") != -1:
- tmpind = index + nameline.find("TROPICAL CYCLONE") + len("TROPICAL CYCLONE")
- copy.seek(tmpind+1)
- tmpcode = copy.read(2)
- elif nameline.find("TROPICAL DEPRESSION") != -1:
- tmpind = index + nameline.find("TROPICAL DEPRESSION") + len("TROPICAL DEPRESSION")
- copy.seek(tmpind+1)
- tmpcode = copy.read(2)
- elif nameline.find("OVERLAND DEPRESSION") != -1:
- tmpind = index + nameline.find("OVERLAND DEPRESSION") + len("OVERLAND DEPRESSION")
- copy.seek(tmpind+1)
- tmpcode = copy.read(2)
- elif nameline.find("TROPICAL DISTURBANCE") != -1:
- tmpind = index + nameline.find("TROPICAL DISTURBANCE") + len("TROPICAL DISTURBANCE")
- copy.seek(tmpind+1)
- tmpcode = copy.read(2)
- copy.seek(index+4)
- name = copy.readline()
- name = name.strip('\n')
- index = test.find("WITHIN")
- copy.seek(index)
- location = copy.readline()
- location = location.strip('\n')
- index = test.find("MOVEMENT")
- copy.seek(index+11)
- dir = copy.readline()
- dir = dir.strip('\n')
- index = test.find("5.A")
- copy.seek(index+35)
- pres = copy.readline()
- pres = pres.strip('\n')
- index = test.find("4.A")
- copy.seek(index+21)
- wind = copy.readline()
- wind = wind.strip('\n')
- update = "WTIO30 %s %s %s %s %s" % (name, location, dir, pres, wind)
- #
- index = test.find(" S ")
- copy.seek(index-4)
- lat = copy.read(4)
- index = test.find(" E\n")
- copy.seek(index-4)
- long = copy.read(4)
- pres = pres.strip(' KT') #dont ask
- wind = wind.strip(' HPA') #^^^^
- if nameline.find("(") != -1:
- copy.seek(tmpind+5)
- name = copy.readline()
- name = name.strip(')\n')
- copy.close()
- tracksrc = open('track.txt','rb')
- tracksrc.seek(0)
- #temp = tracksrc.readline()
- #code = "%s%s" % (temp[2], temp[1])
- code = "%sR" % tmpcode
- test = tracksrc.read()
- #startindex = test.find(":c")
- test = test.strip(':c')
- tracksrc.close()
- trackwrt = open('track.txt','w+b')
- trackwrt.seek(0)
- thing = "%s %s\t-%s\t+%s\t%s\t%s\t/%s/\n" % (code, newproducttime, lat, long, pres, wind, name)
- trackwrt.write(test + thing)
- trackwrt.write(':c')
- trackwrt.close()
- return update
- def wtpz21():
- file = urllib2.urlopen("http://weather.noaa.gov/pub/data/raw/wt/wtpz21.knhc.tcm.ep1.txt")
- output = open('wtpz21_1.txt','w+b')
- output.write(file.read())
- output.seek(0)
- header = output.read(6)
- output.seek(12)
- newproducttime = output.read(6)
- output.close()
- output = open('wtpz21.txt','rb')
- output.seek(12)
- producttime = output.read(6)
- output.close()
- if newproducttime != producttime:
- output = open('wtpz21.txt','w+b')
- copy = open('wtpz21_1.txt','rb')
- output.write(copy.read())
- #output.close()
- copy.seek(0)
- line_offset = []
- offset = 0
- for line in copy:
- line_offset.append(offset)
- offset += len(line)
- copy.seek(0)
- test = copy.read()
- index = test.find(" EP")
- copy.seek(index+1)
- name = copy.readline()
- name = name.strip('\n')
- index = test.find("NEAR")
- copy.seek(index+5)
- location = copy.readline()
- location = location.strip('\n')
- index = test.find("MOVEMENT")
- copy.seek(index+9)
- dir = copy.readline()
- dir = dir.strip('\n')
- index = test.find("PRESSURE")
- copy.seek(index+9)
- pres = copy.readline()
- pres = pres.strip('\n')
- index = test.find("WINDS")
- copy.seek(index+5)
- wind = copy.read(7)
- wind = wind.strip('\n')
- update = "WTPZ21 %s %s %s %s %s" % (name, location, dir, pres, wind)
- copy.close()
- return update
- def wtpz22():
- file = urllib2.urlopen("http://weather.noaa.gov/pub/data/raw/wt/wtpz22.knhc.tcm.ep2.txt")
- output = open('wtpz22_1.txt','w+b')
- output.write(file.read())
- output.seek(0)
- header = output.read(6)
- output.seek(12)
- newproducttime = output.read(6)
- output.close()
- output = open('wtpz22.txt','rb')
- output.seek(12)
- producttime = output.read(6)
- output.close()
- if newproducttime != producttime:
- output = open('wtpz22.txt','w+b')
- copy = open('wtpz22_1.txt','rb')
- output.write(copy.read())
- #output.close()
- copy.seek(0)
- line_offset = []
- offset = 0
- for line in copy:
- line_offset.append(offset)
- offset += len(line)
- copy.seek(0)
- test = copy.read()
- index = test.find(" EP")
- copy.seek(index+1)
- name = copy.readline()
- name = name.strip('\n')
- index = test.find("NEAR")
- copy.seek(index+5)
- location = copy.readline()
- location = location.strip('\n')
- index = test.find("MOVEMENT")
- copy.seek(index+9)
- dir = copy.readline()
- dir = dir.strip('\n')
- index = test.find("PRESSURE")
- copy.seek(index+9)
- pres = copy.readline()
- pres = pres.strip('\n')
- index = test.find("WINDS")
- copy.seek(index+5)
- wind = copy.read(7)
- wind = wind.strip('\n')
- update = "WTPZ22 %s %s %s %s %s" % (name, location, dir, pres, wind)
- copy.close()
- return update
- def wtpz23():
- file = urllib2.urlopen("http://weather.noaa.gov/pub/data/raw/wt/wtpz23.knhc.tcm.ep3.txt")
- output = open('wtpz23_1.txt','w+b')
- output.write(file.read())
- output.seek(0)
- header = output.read(6)
- output.seek(12)
- newproducttime = output.read(6)
- output.close()
- output = open('wtpz23.txt','rb')
- output.seek(12)
- producttime = output.read(6)
- output.close()
- if newproducttime != producttime:
- output = open('wtpz23.txt','w+b')
- copy = open('wtpz23_1.txt','rb')
- output.write(copy.read())
- #output.close()
- copy.seek(0)
- line_offset = []
- offset = 0
- for line in copy:
- line_offset.append(offset)
- offset += len(line)
- copy.seek(0)
- test = copy.read()
- index = test.find(" EP")
- copy.seek(index+1)
- name = copy.readline()
- name = name.strip('\n')
- index = test.find("NEAR")
- copy.seek(index+5)
- location = copy.readline()
- location = location.strip('\n')
- index = test.find("MOVEMENT")
- copy.seek(index+9)
- dir = copy.readline()
- dir = dir.strip('\n')
- index = test.find("PRESSURE")
- copy.seek(index+9)
- pres = copy.readline()
- pres = pres.strip('\n')
- index = test.find("WINDS")
- copy.seek(index+5)
- wind = copy.read(7)
- wind = wind.strip('\n')
- update = "WTPZ23 %s %s %s %s %s" % (name, location, dir, pres, wind)
- copy.close()
- return update
- def wtpz24():
- file = urllib2.urlopen("http://weather.noaa.gov/pub/data/raw/wt/wtpz24.knhc.tcm.ep4.txt")
- output = open('wtpz24_1.txt','w+b')
- output.write(file.read())
- output.seek(0)
- header = output.read(6)
- output.seek(12)
- newproducttime = output.read(6)
- output.close()
- output = open('wtpz24.txt','rb')
- output.seek(12)
- producttime = output.read(6)
- output.close()
- if newproducttime != producttime:
- output = open('wtpz24.txt','w+b')
- copy = open('wtpz24_1.txt','rb')
- output.write(copy.read())
- #output.close()
- copy.seek(0)
- line_offset = []
- offset = 0
- for line in copy:
- line_offset.append(offset)
- offset += len(line)
- copy.seek(0)
- test = copy.read()
- index = test.find(" EP")
- copy.seek(index+1)
- name = copy.readline()
- name = name.strip('\n')
- index = test.find("NEAR")
- copy.seek(index+5)
- location = copy.readline()
- location = location.strip('\n')
- index = test.find("MOVEMENT")
- copy.seek(index+9)
- dir = copy.readline()
- dir = dir.strip('\n')
- index = test.find("PRESSURE")
- copy.seek(index+9)
- pres = copy.readline()
- pres = pres.strip('\n')
- index = test.find("WINDS")
- copy.seek(index+5)
- wind = copy.read(7)
- wind = wind.strip('\n')
- update = "WTPZ24 %s %s %s %s %s" % (name, location, dir, pres, wind)
- copy.close()
- return update
- def wtpz25():
- file = urllib2.urlopen("http://weather.noaa.gov/pub/data/raw/wt/wtpz25.knhc.tcm.ep5.txt")
- output = open('wtpz25_1.txt','w+b')
- output.write(file.read())
- output.seek(0)
- header = output.read(6)
- output.seek(12)
- newproducttime = output.read(6)
- output.close()
- output = open('wtpz25.txt','rb')
- output.seek(12)
- producttime = output.read(6)
- output.close()
- if newproducttime != producttime:
- output = open('wtpz25.txt','w+b')
- copy = open('wtpz25_1.txt','rb')
- output.write(copy.read())
- #output.close()
- copy.seek(0)
- line_offset = []
- offset = 0
- for line in copy:
- line_offset.append(offset)
- offset += len(line)
- copy.seek(0)
- test = copy.read()
- index = test.find(" EP")
- copy.seek(index+1)
- name = copy.readline()
- name = name.strip('\n')
- index = test.find("NEAR")
- copy.seek(index+5)
- location = copy.readline()
- location = location.strip('\n')
- index = test.find("MOVEMENT")
- copy.seek(index+9)
- dir = copy.readline()
- dir = dir.strip('\n')
- index = test.find("PRESSURE")
- copy.seek(index+9)
- pres = copy.readline()
- pres = pres.strip('\n')
- index = test.find("WINDS")
- copy.seek(index+5)
- wind = copy.read(7)
- wind = wind.strip('\n')
- update = "WTPZ25 %s %s %s %s %s" % (name, location, dir, pres, wind)
- copy.close()
- return update
- def wwps21():# WHY IS THIS NOT WORKING UGH
- file = urllib2.urlopen("http://weather.noaa.gov/pub/data/raw/ww/wwps21.nffn..txt")
- output = open('wwps21_1.txt','w+b')
- output.write(file.read())
- output.seek(0)
- header = output.read(6)
- output.seek(12)
- newproducttime = output.read(6)
- output.close()
- output = open('wwps21.txt','rb')
- output.seek(12)
- producttime = output.read(6)
- output.close()
- if newproducttime != producttime:
- output = open('wwps21.txt','w+b')
- copy = open('wwps21_1.txt','rb')
- output.write(copy.read())
- #output.close()
- copy.seek(0)
- line_offset = []
- offset = 0
- for line in copy:
- line_offset.append(offset)
- offset += len(line)
- copy.seek(0)
- test = copy.read()
- if findnth(test, "TROPICAL DISTURBANCE", 2) != -1:
- index = findnth(test, "TROPICAL DISTURBANCE", 2)
- copy.seek(index+2)
- name = copy.readline()
- name = name.strip('\n')
- index = test.find("MOVING")
- copy.seek(index)
- location = copy.readline()
- location = location.strip('\n')
- index = test.find("POTENTIAL FOR")
- copy.seek(index)
- potential = copy.read(54)
- potential = potential.strip('\n')
- copy.seek(index+80)
- pot2 = copy.readline()
- pot2 = pot2.strip('\n')
- update = "WWPS21 %s %s %s %s" % (name, location, potential, pot2)
- copy.close()
- return update
- elif test.find("TROPICAL DEPRESSION") != -1:
- index = test.find("TROPICAL DEPRESSION")
- copy.seek(index)
- name = copy.readline()
- name = name.strip('\n')
- index = test.find("MOVING")
- copy.seek(index)
- location = copy.readline()
- location = location.strip('\n')
- index = test.find("POTENTIAL FOR")
- if index != -1:
- copy.seek(index)
- potential = copy.read(54)
- potential = potential.strip('\n')
- copy.seek(index+80)
- pot2 = copy.readline()
- pot2 = pot2.strip('\n')
- update = "WWPS21 %s %s %s %s" % (name, location, potential, pot2)
- update = "WWPS21 %s %s" % (name, location)
- copy.close()
- return update
- else:
- pass
- def wtps11():
- file = urllib2.urlopen("http://weather.noaa.gov/pub/data/raw/wt/wtps11.nffn..txt")
- output = open('wtps11_1.txt','w+b')
- output.write(file.read())
- output.seek(0)
- header = output.read(6)
- output.seek(12)
- newproducttime = output.read(6)
- output.close()
- output = open('wtps11.txt','rb')
- output.seek(12)
- producttime = output.read(6)
- output.close()
- if newproducttime != producttime:
- output = open('wtps11.txt','w+b')
- copy = open('wtps11_1.txt','rb')
- output.write(copy.read())
- #output.close()
- copy.seek(0)
- line_offset = []
- offset = 0
- for line in copy:
- line_offset.append(offset)
- offset += len(line)
- copy.seek(0)
- test = copy.read()
- index = test.find("UTC.")
- index2 = findnth(test, "UTC.", 1)
- index2 = index2 - index
- copy.seek(index+5)
- name = copy.read(index2)
- name = name.replace('\n', ' ')
- index = test.find("POSITION")
- copy.seek(index)
- pos = copy.read(13)
- index = test.find("MOVING")
- index2 = findnth(test, ".", 5)
- copy.seek(index)
- dir = copy.read(index2 - (index))
- index = findnth(test, "KNOTS", 1)
- copy.seek(index-4)
- wind = copy.read(10)
- wind = wind.replace('\n', ' ')
- update = "WTPS11 %s %s %s %s KNOTS." % (name, wind, pos, dir)
- copy.close()
- return update
- def axau01():
- file = urllib2.urlopen("http://weather.noaa.gov/pub/data/raw/ax/axau01.aprf..txt")
- output = open('axau01_1.txt','w+b')
- output.write(file.read())
- output.seek(0)
- header = output.read(6)
- output.seek(12)
- newproducttime = output.read(6)
- output.close()
- output = open('axau01.txt','rb')
- output.seek(12)
- producttime = output.read(6)
- output.close()
- if newproducttime != producttime:
- output = open('axau01.txt','w+b')
- copy = open('axau01_1.txt','rb')
- output.write(copy.read())
- #output.close()
- copy.seek(0)
- line_offset = []
- offset = 0
- for line in copy:
- line_offset.append(offset)
- offset += len(line)
- copy.seek(line_offset[5]+6)
- name = copy.readline()
- name = name.strip('\n')
- name = name.strip(' ')
- if name == "Tropical Low " or name == "Tropical Low " or name == "Tropical Low":
- copy.seek(line_offset[6]+12)
- id = copy.readline()
- id = id.strip('\n')
- copy.seek(line_offset[6]+12)
- id = copy.readline()
- id = id.strip('\n')
- copy.seek(line_offset[8]+10)
- lat = copy.readline()
- lat = lat.strip('\n')
- copy.seek(line_offset[9]+11)
- long = copy.readline()
- long = long.strip('\n')
- copy.seek(line_offset[10]+18)
- acc = copy.readline()
- acc = acc.strip('\n')
- copy.seek(line_offset[11]+17)
- dir = copy.readline()
- dir = dir.strip('\n')
- copy.seek(line_offset[12]+18)
- dirs = copy.readline()
- dirs = dirs.strip('\n')
- copy.seek(line_offset[15]+17)
- pres = copy.readline()
- pres = pres.strip('\n')
- copy.seek(line_offset[13]+23)
- wind = copy.readline()
- wind = wind.strip('\n')
- if name == "Tropical Low " or name == "Tropical Low " or name == "Tropical Low":
- update = "AXAU01 %s %s %s %s %s %s %s %s %s" % (name, id, lat, long, acc, dir, dirs, wind, pres)
- else:
- update = "AXAU01 %s %s %s %s %s %s %s %s" % (name, lat, long, acc, dir, dirs, wind, pres)
- copy.close()
- #############
- tracksrc = open('track.txt','rb')
- tracksrc.seek(0)
- pres = pres.strip(' hPa')
- wind = wind[:3]
- lat = lat.strip('S\n')
- long = long.strip('E\n')
- namearr = name.split(' ')
- test = tracksrc.read()
- test = test.strip(':c')
- tracksrc.close()
- trackwrt = open('track.txt','w+b')
- trackwrt.seek(0)
- thing = "%s %s\t-%s\t+%s\t%s\t%s\t/%s/\n" % (id, newproducttime, lat, long, wind, pres, namearr[len(namearr)-1])
- trackwrt.write(test + thing)
- trackwrt.write(':c')
- trackwrt.close()
- return update
- def axau02():
- file = urllib2.urlopen("http://weather.noaa.gov/pub/data/raw/ax/axau02.aprf..txt")
- output = open('axau02_1.txt','w+b')
- output.write(file.read())
- output.seek(0)
- header = output.read(6)
- output.seek(12)
- newproducttime = output.read(6)
- output.close()
- output = open('axau02.txt','rb')
- output.seek(12)
- producttime = output.read(6)
- output.close()
- if newproducttime != producttime:
- output = open('axau02.txt','w+b')
- copy = open('axau02_1.txt','rb')
- output.write(copy.read())
- #output.close()
- copy.seek(0)
- line_offset = []
- offset = 0
- for line in copy:
- line_offset.append(offset)
- offset += len(line)
- copy.seek(line_offset[5]+6)
- name = copy.readline()
- name = name.strip('\n')
- name = name.strip(' ')
- if name == "Tropical Low " or name == "Tropical Low " or name == "Tropical Low":
- copy.seek(line_offset[6]+12)
- id = copy.readline()
- id = id.strip('\n')
- copy.seek(line_offset[8]+10)
- lat = copy.readline()
- lat = lat.strip('\n')
- copy.seek(line_offset[9]+11)
- long = copy.readline()
- long = long.strip('\n')
- copy.seek(line_offset[10]+18)
- acc = copy.readline()
- acc = acc.strip('\n')
- copy.seek(line_offset[11]+17)
- dir = copy.readline()
- dir = dir.strip('\n')
- copy.seek(line_offset[12]+18)
- dirs = copy.readline()
- dirs = dirs.strip('\n')
- copy.seek(line_offset[15]+17)
- pres = copy.readline()
- pres = pres.strip('\n')
- copy.seek(line_offset[13]+23)
- wind = copy.readline()
- wind = wind.strip('\n')
- if name == "Tropical Low " or name == "Tropical Low " or name == "Tropical Low":
- update = "AXAU02 %s %s %s %s %s %s %s %s %s" % (name, id, lat, long, acc, dir, dirs, wind, pres)
- else:
- update = "AXAU02 %s %s %s %s %s %s %s %s" % (name, lat, long, acc, dir, dirs, wind, pres)
- copy.close()
- #############
- tracksrc = open('track.txt','rb')
- tracksrc.seek(0)
- pres = pres.strip(' hPa')
- wind = wind[:3]
- lat = lat.strip('S\n')
- long = long.strip('E\n')
- namearr = name.split(' ')
- test = tracksrc.read()
- test = test.strip(':c')
- tracksrc.close()
- trackwrt = open('track.txt','w+b')
- trackwrt.seek(0)
- thing = "%s %s\t-%s\t+%s\t%s\t%s\t/%s/\n" % (id, newproducttime, lat, long, wind, pres, namearr[len(namearr)-1])
- trackwrt.write(test + thing)
- trackwrt.write(':c')
- trackwrt.close()
- return update
- def axau03():
- file = urllib2.urlopen("http://weather.noaa.gov/pub/data/raw/ax/axau03.aprf..txt")
- output = open('axau03_1.txt','w+b')
- output.write(file.read())
- output.seek(0)
- header = output.read(6)
- output.seek(12)
- newproducttime = output.read(6)
- output.close()
- output = open('axau03.txt','rb')
- output.seek(12)
- producttime = output.read(6)
- output.close()
- if newproducttime != producttime:
- output = open('axau03.txt','w+b')
- copy = open('axau03_1.txt','rb')
- output.write(copy.read())
- #output.close()
- copy.seek(0)
- line_offset = []
- offset = 0
- for line in copy:
- line_offset.append(offset)
- offset += len(line)
- copy.seek(line_offset[5]+6)
- name = copy.readline()
- name = name.strip('\n')
- name = name.strip(' ')
- if name == "Tropical Low " or name == "Tropical Low " or name == "Tropical Low":
- copy.seek(line_offset[6]+12)
- id = copy.readline()
- id = id.strip('\n')
- copy.seek(line_offset[8]+10)
- lat = copy.readline()
- lat = lat.strip('\n')
- copy.seek(line_offset[9]+11)
- long = copy.readline()
- long = long.strip('\n')
- copy.seek(line_offset[10]+18)
- acc = copy.readline()
- acc = acc.strip('\n')
- copy.seek(line_offset[11]+17)
- dir = copy.readline()
- dir = dir.strip('\n')
- copy.seek(line_offset[12]+18)
- dirs = copy.readline()
- dirs = dirs.strip('\n')
- copy.seek(line_offset[15]+17)
- pres = copy.readline()
- pres = pres.strip('\n')
- copy.seek(line_offset[13]+23)
- wind = copy.readline()
- wind = wind.strip('\n')
- if name == "Tropical Low " or name == "Tropical Low " or name == "Tropical Low":
- update = "AXAU03 %s %s %s %s %s %s %s %s %s" % (name, id, lat, long, acc, dir, dirs, wind, pres)
- else:
- update = "AXAU03 %s %s %s %s %s %s %s %s" % (name, lat, long, acc, dir, dirs, wind, pres)
- copy.close()
- return update
- def axau01_adrm():
- file = urllib2.urlopen("http://weather.noaa.gov/pub/data/raw/ax/axau01.adrm..txt")
- output = open('axau01_adrm_1.txt','w+b')
- output.write(file.read())
- output.seek(0)
- header = output.read(6)
- output.seek(12)
- newproducttime = output.read(6)
- output.close()
- output = open('axau01_adrm.txt','rb')
- output.seek(12)
- producttime = output.read(6)
- output.close()
- if newproducttime != producttime:
- output = open('axau01_adrm.txt','w+b')
- copy = open('axau01_adrm_1.txt','rb')
- output.write(copy.read())
- #output.close()
- copy.seek(0)
- line_offset = []
- offset = 0
- for line in copy:
- line_offset.append(offset)
- offset += len(line)
- copy.seek(line_offset[5]+6)
- name = copy.readline()
- name = name.strip('\n')
- name = name.strip(' ')
- if name == "Tropical Low " or name == "Tropical Low " or name == "Tropical Low":
- copy.seek(line_offset[6]+12)
- id = copy.readline()
- id = id.strip('\n')
- copy.seek(line_offset[8]+10)
- lat = copy.readline()
- lat = lat.strip('\n')
- copy.seek(line_offset[9]+11)
- long = copy.readline()
- long = long.strip('\n')
- copy.seek(line_offset[10]+18)
- acc = copy.readline()
- acc = acc.strip('\n')
- copy.seek(line_offset[11]+17)
- dir = copy.readline()
- dir = dir.strip('\n')
- copy.seek(line_offset[12]+18)
- dirs = copy.readline()
- dirs = dirs.strip('\n')
- copy.seek(line_offset[15]+17)
- pres = copy.readline()
- pres = pres.strip('\n')
- copy.seek(line_offset[13]+23)
- wind = copy.readline()
- wind = wind.strip('\n')
- if name == "Tropical Low " or name == "Tropical Low " or name == "Tropical Low":
- update = "AXAU01 %s %s %s %s %s %s %s %s %s" % (name, id, lat, long, acc, dir, dirs, wind, pres)
- else:
- update = "AXAU01 %s %s %s %s %s %s %s %s" % (name, lat, long, acc, dir, dirs, wind, pres)
- copy.close()
- return update
- def axau21():
- file = urllib2.urlopen("http://weather.noaa.gov/pub/data/raw/ax/axau21.abrf..txt")
- output = open('axau21_1.txt','w+b')
- output.write(file.read())
- output.seek(0)
- header = output.read(6)
- output.seek(12)
- newproducttime = output.read(6)
- output.close()
- output = open('axau21.txt','rb')
- output.seek(12)
- producttime = output.read(6)
- output.close()
- if newproducttime != producttime:
- output = open('axau21.txt','w+b')
- copy = open('axau21_1.txt','rb')
- output.write(copy.read())
- #output.close()
- copy.seek(0)
- line_offset = []
- offset = 0
- for line in copy:
- line_offset.append(offset)
- offset += len(line)
- copy.seek(line_offset[5]+6)
- name = copy.readline()
- name = name.strip('\n')
- name = name.strip(' ')
- if name == "Tropical Low " or name == "Tropical Low " or name == "Tropical Low":
- copy.seek(line_offset[6]+12)
- id = copy.readline()
- id = id.strip('\n')
- copy.seek(line_offset[8]+10)
- lat = copy.readline()
- lat = lat.strip('\n')
- copy.seek(line_offset[9]+11)
- long = copy.readline()
- long = long.strip('\n')
- copy.seek(line_offset[10]+18)
- acc = copy.readline()
- acc = acc.strip('\n')
- copy.seek(line_offset[11]+17)
- dir = copy.readline()
- dir = dir.strip('\n')
- copy.seek(line_offset[12]+18)
- dirs = copy.readline()
- dirs = dirs.strip('\n')
- copy.seek(line_offset[15]+17)
- pres = copy.readline()
- pres = pres.strip('\n')
- copy.seek(line_offset[13]+23)
- wind = copy.readline()
- wind = wind.strip('\n')
- if name == "Tropical Low " or name == "Tropical Low " or name == "Tropical Low":
- update = "AXAU21 %s %s %s %s %s %s %s %s %s" % (name, id, lat, long, acc, dir, dirs, wind, pres)
- else:
- update = "AXAU21 %s %s %s %s %s %s %s %s" % (name, lat, long, acc, dir, dirs, wind, pres)
- copy.close()
- return update
- [/code]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement