import httplib re gorod_key 23606 Ukhta gorod_key 27612 Moscow host we

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
import httplib, re
gorod_key = "23606" # Ukhta
#gorod_key = "27612" # Moscow
host = "weather.yandex.ru"
con = httplib.HTTPConnection(host, 80)
con.request("GET", "http://weather.yandex.ru/"+gorod_key, None, {})
response = con.getresponse()
status = response.status
reason = response.reason
data = response.read()
con.close()
if status != '200' and reason != 'OK': exit("ERROR!")
#data = "return {orientation: 'horizontal', range:[-50, 50], step:0.2, value: -31 }"
print re.findall("orientation\: \'horizontal\'\, range\:\[-50\, 50\]\, step\:0\.2\, value\: (.*?) ", data)[0]