Početak›Forumi›Prvi put na Linuksu?›Vremenska prognoza
- This topic has 14 odgovora, 10 glasova, and was last updated 14 years, 11 months ranije by dukenukem_4d.
-
AutorČlanci
-
17. maj 2009. u 11:55 am #78673na12Učesnik
Sremska Mitrovica SRXX0016
17. maj 2009. u 12:57 pm #78674MoneoUčesnikBrate instaliraj ekstenziju za FF koja se zove 1-click weather i koja je zaista super i resi se muka-dovoljno je samo da ukucas lokaciju i on ce je automatski prepoznati-meni za Loznicu npr 😉
Ako koristis Operu-zalim slucaj,zna se koji je browser ipak no 1 :p :biggrin:18. maj 2009. u 9:46 pm #78675na12UčesnikEvo za one koji koriste Openbox jedna skripta za pipe-menu
yweather.py
[code]#!/usr/bin/python
import urllib
from xml.etree.cElementTree import parse
from datetime import datetime, timedelta
import os
from os.path import join
from sys import argv
try:
import cPickle as pickle
except ImportError:
import pickle#Usage: yweather.py AYXX0001 Celsius
if len(argv) != 3:
raise Exception(‘Usage: yweather.py zip_code units. zip_code is your city code in Yahoo Weather, units can be Celsius or Fahrenheit.’)
else:
zip_code = argv[1]
if argv[2] == ‘Fahrenheit’ or argv[2] == ‘fahrenheit’:
units = ‘f’
else:
units = ‘c’CACHE_HOURS = 6
#http://weather.yahooapis.com/forecastrss
WEATHER_URL = ‘http://xml.weather.yahoo.com/forecastrss?p=%s&u=%s’
WEATHER_NS = ‘http://xml.weather.yahoo.com/ns/rss/1.0’def weather_for_zip(zip_code, units):
url = WEATHER_URL % (zip_code, units)
rss = parse(urllib.urlopen(url)).getroot()
forecasts = []
for element in rss.findall(‘channel/item/{%s}forecast’ % WEATHER_NS):
forecasts.append(dict(element.items()))
ycondition = rss.find(‘channel/item/{%s}condition’ % WEATHER_NS)
return {
‘current_condition’: dict(ycondition.items()),
‘forecasts’: forecasts,
‘title’: rss.findtext(‘channel/title’),
‘pubDate’: rss.findtext(‘channel/item/pubDate’), #rss.findtext(‘channel/lastBuildDate’),
‘location’: dict(rss.find(‘channel/{%s}location’ % WEATHER_NS).items()),
‘wind’: dict(rss.find(‘channel/{%s}wind’ % WEATHER_NS).items()),
‘atmosphere’: dict(rss.find(‘channel/{%s}atmosphere’ % WEATHER_NS).items()),
‘astronomy’: dict(rss.find(‘channel/{%s}astronomy’ % WEATHER_NS).items()),
‘units’: dict(rss.find(‘channel/{%s}units’ % WEATHER_NS).items())
}def print_openbox_pipe_menu(weather):
print ”
print ” % (weather[‘location’][‘city’],weather[‘pubDate’])
print ”
print ” % weather[‘current_condition’][‘text’]
print ” % ( weather[‘current_condition’][‘temp’],
weather[‘units’][‘temperature’] )
print ” % weather[‘atmosphere’][‘humidity’]
print ” % ( weather[‘atmosphere’][‘visibility’],
weather[‘units’][‘distance’] )
#pressure: steady (0), rising (1), or falling (2)
if weather[‘atmosphere’][‘rising’] == 0:
pressure_state = ‘steady’
elif weather[‘atmosphere’][‘rising’] == 1:
pressure_state = ‘rising’
else:
pressure_state = ‘falling’
print ” % ( weather[‘atmosphere’][‘pressure’],
weather[‘units’][‘pressure’], pressure_state )
print ” % ( weather[‘wind’][‘chill’],
weather[‘units’][‘temperature’] )
print ” % weather[‘wind’][‘direction’]
print ” % ( weather[‘wind’][‘speed’],
weather[‘units’][‘speed’] )
print ” % weather[‘astronomy’][‘sunrise’]
print ” % weather[‘astronomy’][‘sunset’]
for forecast in weather[‘forecasts’]:
print ” % forecast[‘day’]
print ” % forecast[‘text’]
print ” % ( forecast[‘low’],
weather[‘units’][‘temperature’] )
print ” % ( forecast[‘high’],
weather[‘units’][‘temperature’] )
print ”cache_file = join(os.getenv(“HOME”), ‘.yweather.cache’)
try:
f = open(cache_file,’rb’)
cache = pickle.load(f)
f.close()
except IOError:
cache = Noneif cache == None or (zip_code, units) not in cache or (
cache[(zip_code, units)][‘date’] + timedelta(hours=CACHE_HOURS) < datetime.utcnow()):
# The cache is outdated
weather = weather_for_zip(zip_code, units)
if cache == None:
cache = dict()
cache[(zip_code, units)] = {'date': datetime.utcnow(), 'weather': weather}
#Save the data in the cache
try:
f = open(cache_file, 'wb')
cache = pickle.dump(cache, f, -1)
f.close()
except IOError:
raise
else:
weather = cache[(zip_code, units)]['weather']print_openbox_pipe_menu(weather)[/code]
posle se samo doda u menu.xml
[code]
[/code]
gde je YIXX0016 kod za vas grad na yahoo weather.
19. maj 2009. u 8:21 pm #78676SiouxUčesnikNa Operi koristim fast dial u kome je ugnježdena stranica Umbrella zapadni Balkan.
Klikneš na Beograd i dobiješ dobru vremensku kartu za narednih 4 dana.19. maj 2009. u 8:53 pm #78677dukenukem_4dUčesnikhttp://www.hidmet.gov.rs/
valjda imamo i neki superkompijuter koji ovo izračunava ???
(unapred O0 ) -
AutorČlanci
Moraš biti prijavljen da bi postavio komentar u ovoj temi.