#!/usr/bin/env python # # accuweather.com import socket import re import time import string from urllib import urlopen # forecast def getWeather(city='RIJEKA'): zipcode = 'zipcode=EUR|HR|HR013|%s|' % city socket.setdefaulttimeout(5) site = urlopen('http://wwwa.accuweather.com/index-world-forecast.asp?%s' % zipcode) load = site.read() site.close() # night time if time.localtime()[3] >= 17: w_info = re.compile('Conditions(.*?)Tomorrow', re.DOTALL) # day time else: w_info = re.compile('Conditions(.*?)Tonight', re.DOTALL) search = w_info.findall(load) striptags = re.compile('<[^>]+>') build = striptags.sub('',search[0]).replace('°','').replace('®','') # put this with striptags strings = string.split(build) try: basenum = strings.index('C') report= strings[:basenum-2] temp = strings[-basenum:-3] # real feel #real = strings[-basenum+3:] out = ' '.join(report)+', '+' '.join(temp) return out except ValueError: return 'I can\'t access the site, try again later' ################################################################## #!/usr/bin/env python # HR meteoroloski zavod import socket import re import sys from urllib import urlopen def getWeather(day): prognoza = [] socket.setdefaulttimeout(5) if day == 'today': day = "hrdanas_n.html" elif day == 'tomorrow': day = "hrsutra_n.html" else: return 'Samo: danas, sutra' try: site = urlopen("http://www.dhmz.htnet.hr/prognoza/%s" % day) except IOError, socket.timeout: return 'Prognoza nedostupna!' load = site.read() site.close() winfo = re.compile('
(.*?)
', re.DOTALL)
search = winfo.findall(load)
prognoza.append(re.compile('<[^>]+>').sub('', search[0]).replace('\r\n',''))
return prognoza[0].decode('cp1250').encode('utf-8').replace(' ',' ').replace(' ',' ')
##################################################################
#!/usr/bin/env python
#
# rijekadanas.com
import re, string
from urllib import urlopen, unquote
def get_weather():
site = urlopen("http://www.rijekadanas.com/index.php")
temp = site.read()
site.close()
weather_info = re.compile('alt="Vrijeme u Rijeci">(.*?)Danas', re.DOTALL)
search = weather_info.findall(temp)
striptags = re.compile('<[^>]+>')
search2 = striptags.sub('',search[0])
strings = string.split(search2)
print strings
get_weather()
# EOF