rendered paste body#!/usr/bin/env python## accuweather.com import socketimport reimport timeimport stringfrom urllib import urlopen# forecastdef 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</a></div></td>(.*?)Tomorrow</a></div>', re.DOTALL) # day time else: w_info = re.compile('Conditions</a></div></td>(.*?)Tonight</a></div>', 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 zavodimport socketimport reimport sysfrom urllib import urlopendef 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('<P>(.*?)<P><BR>', 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, stringfrom urllib import urlopen, unquotedef get_weather(): site = urlopen("http://www.rijekadanas.com/index.php") temp = site.read() site.close() weather_info = re.compile('alt="Vrijeme u Rijeci">(.*?)<b>Danas', re.DOTALL) search = weather_info.findall(temp) striptags = re.compile('<[^>]+>') search2 = striptags.sub('',search[0]) strings = string.split(search2) print stringsget_weather()# EOF