bin env python coding utf-8 town_id 26179 depth timeout 10 import urll

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/env python
# -*- coding: utf-8 -*-
town_id = 26179
depth = 5 # <=9
timeout = 10
import urllib2
import socket
import re
try:
socket.setdefaulttimeout(timeout)
data = urllib2.urlopen('http://wap.gismeteo.ru/%d.wml' % town_id).read()
values = re.search(ur'(?su).*?\<card id=.*?title=".*?"\>\r\n.*?<p\>\r\n' + (ur'(.*?)\<br\/>\r\n\<img.*?alt="(.*?)"\/\>\s\<b\>(.*?)\s&.*?\<\/b\>\<br\/\>.*?\<br\/\>\<br\/\>\r\n\r\n' * depth), data).groups()
i = 0
while (i < len(values)):
print '%s%s%s%s%s %s' % (
values[i], ' '*(20-len(unicode(values[i], 'UTF-8'))),
values[i+1], ' '*(25-len(unicode(values[i+1],'UTF-8'))),
values[i+2], '°C'
)
i += 3
except urllib2.URLError, strerr:
import sys
print '%s: %s' % (sys.argv[0], strerr)
sys.exit(1)
except:
import sys
print '%s: Unknown Error' % sys.argv[0]
sys.exit(2)