Hey guys,
I am making a program called 'Weather Watch' which basically gets weather updates for any city you type in.
For now, it only gets info for a particular city. I don't know how to search for the term entered in www.weather.com and then get the updates. The code so far:
import urllib2 as url
import os
import time
os.system('cls')
print("[Content provided by The Weather Channel]")
time.sleep(3)
os.system('cls')
print("Please wait...this may take a few seconds.")
time.sleep(3)
os.system('cls')
condition=True
try:
url_open=url.urlopen("http://www.weather.com")
lines=url_open.readlines()[1192:1199]
except:
condition=False
if(condition):
print("Weather forecast for Bangalore, INDIA\n")
for x in lines:
onsplit=x.split(">")
tags=onsplit[2][:-5]
if(tags=="Pressure:"):
data=onsplit[4][:5]
elif(tags=="Dew Point:"):
data=onsplit[4][:2]
else:
data=onsplit[4][:-5]
print(tags+" "+data)
raw_input("\n<Any key to quit>")
This is what I've learnt on searching for a term in a site[Google, here]
import urllib2 as url2
import urllib as url
values={"search":"city"}
data=url.urlencode(values)
req=url2.Request("http://www.google.com",data)
res=url2.urlopen(req)
print(res.read())