Conky, meva configuració

Fecfactor em demanava ahir que publiqués la configuració de l'Conky que mostro a la captura a continuació

Com poden veure es tracta de 3 conkys, que són executats mitjançant un script, la configuració de la mateixa està basada en aquest post que va publicar l'usuari Bruce M. en els fòrums de Ubuntu-Ar amb algunes modificacions en el Conky de l'correu, que en el meu cas és per a Gmail.

En el post de referència està molt ben explicat per Bruce, però també com a ajuda memòria per a mi, vaig a copiar els passos a seguir i el codi de les meves conkys per a qui vulgui el tingui.

Bé, ens cal és clar tenir instal·lat Conky, curl i python així que tipeamos en la consola:

sudo apt-get install Conky curl python

La font de weather.ttf i de arrows.ttf aquí. La font de moon.ttf aquí un cop baixades cal copiar-les a / usr / share / fonts

Crearem ara nostre script anomenat ~. / Startconky

gksudo gedit ~ / .startconky

dins l'arxiu buit enganxem el següent

#! / Bin / bash
sleep 0 & # 0 good for Xfce - use 20 to 30 for Gnome
Conky -c ~ / Conky / conkymain &
#sleep 0 & # 0 good for Xfce - usi 1 for Gnome
Conky -c ~ / Conky / conkyforecast &
#sleep 0 & # 0 good for Xfce - usi 1 for Gnome
Conky -c ~ / Conky / conkymail &

Ara creem l'arxiu conkymain a la carpeta ~ / Conky sinó tenim la carpeta Conky caldrà crear-la.

gedit ~ / Conky / conkymain

jo faig servir la font Calibri, si no la tens reemplazala per la que vulguis.

Enganxem dins el que segueix

background no
own_window yes
own_window_transparent yes
own_window_hints undecorated, below, sticky, skip_taskbar, skip_pager
own_window_colour black
double_buffer yes
use_spacer left
use_xft yes
font Calibri: size = 9
xftfont Calibri: size = 9
xftalpha 0.5
update_interval 5.0
uppercase no # setembre to yes if you want all text to be in uppercase
stippled_borders 3
border_margin maig
border_width 10
default_color white
default_outline_color black
default_shade_color black
color0 cyan
color1 lightblue
color2 orange
color3 groc
color4 wheat
color5 blanc
color6 blanc
color7 blanc
color8 blanc
color9 blanc
alignment top_right # or top_left, bottom_left, bottom_right
gap_x maig
gap_y 35
text_buffer_size 128 # usi 1024 for the forecast
no_buffers yes # Subtract file system buffers from used memory?
draw_borders no
draw_outline yes # amplifies text if yes
draw_shades yes # shadecolor black

TEXT
$ {Font Calibri: size = 12} $ {alignc} $ {color1} $ sysname $ nucli on $ machine} $ color $ font
$ {Font Calibri: size = 12} $ {alignc} $ {color2} $ {exec whoami} @ $ nodeName $ color $ font
$ {Color0} $ {hr 1} $ color
$ {Font Calibri: size = 20} $ {alignc} $ {time% H:% M} $ font
$ {Font Calibri: size = 12} $ {color1} $ {alignc} $ {time% A,% d% b. % I} $ color $ font
$ {Color3} UpTime: $ {alignr 2} $ uptime $ color
$ {Color0} $ {hr 1} $ color
$ {Voffset 5} $ {color2} CPU: $ {alignc} $ color $ running_processes $ {color1} / $ color $ processes $ {alignr 2} $ {color2} $ {cpubar cpu0 14,80} $ color
$ {Color1} $ {voffset -16} $ {alignr 5} $ CPU% $ color
$ {Voffset 2} $ {color1} Load Avg ($ {color3} Min $ {color1}): $ {alignr 2} $ {color3} 1: $ color $ {loadavg 1} $ {color3} 5: $ color $ {loadavg 2} $ {color3} 15: $ color $ {loadavg 3}
$ {Voffset 5} $ {color2} RAM: $ color $ mem $ {color2} / $ color $ memmax $ {alignr 2} $ {color2} $ {membar 14,80} $ color
$ {Color1} $ {voffset -16} $ {alignr 5} $ memperc% $ color
$ {Voffset 2} $ {color1} buffered: $ color $ {buffers} $ {alignr 2} $ {color1} Cached: $ color $ {cached}
$ {Voffset 5} $ {color2} SWAP: $ color $ swap $ {color2} / $ color $ {swapmax} $ {alignr 2} $ {color2} $ {swapbar 14,80} $ color
$ {Color1} $ {voffset -16} $ {alignr 5} $ swapperc%
$ {Color0} $ {hr 1} $ color
$ {Voffset 5} $ {color2} HD Informació $ {color1} - $ color Free $ {color1} - Used - $ {color2} Total
$ {Voffset 5} $ {color1} Root: $ color $ {fs_free_perc /}% $ {alignr 2} $ {fs_free /} $ {color2} / $ {color1} $ {fs_used /} $ color / $ {color2} $ {fs_size /} $ color
$ {Color1} Home: $ color $ {fs_free_perc / home / usuari}% $ {alignr 2} $ {fs_free / home / usuari} $ {color2} / $ {color1} $ {fs_used / home / usuari} $ color / $ {color2} $ {fs_size / home / usuari} $ color
$ {Color0} $ {hr 1} $ color
$ {Color1} Des: $ color Buenos Aires, Argentina
$ {Color1} Lat: $ {color2} 34 ° 35'S $ {color1} Long: $ {color2} 58 ° 21'W $ {color1} Alt: $ {color2} 25 m $ color
$ {Voffset 5} $ {color2} $ {font Calibri: size = 12} avui: $ font $ {color3} $ {execi 3600 python ~ / Conky / scripts / conkyForecast.py -location = ARBA0009 -datatype = CC} $ color $ {alignr 2} $ {color1} ST: $ {color2} $ {execi 3600 python ~ / Conky / scripts / conkyForecast.py -location = ARBA0009 -datatype = LT}
$ {Color3} $ {font Weather: size = 50} $ {execi 3600 python ~ / Conky / scripts / conkyForecast.py -location = ARBA0009 -datatype = WF} $ font $ color
$ {Alignr 50} $ {voffset -55} $ {font Calibri: size = 25} $ {execi 3600 python ~ / Conky / scripts / conkyForecast.py -location = ARBA0009 -datatype = HT} $ font
$ {Alignc 20} $ {voffset -30} $ {font Arrows: size = 20} $ {color4} $ {execi 3600 python ~ / Conky / scripts / conkyForecast.py -location = ARBA0009 -datatype = BF} $ color $ font
$ {Alignc 10} $ {voffset 5} $ {color4} Vent: $ {execi 3600 python ~ / Conky / scripts / conkyForecast.py -location = ARBA0009 -datatype = WS} $ color
$ {Color1} Humitat: $ {color3} $ {execi 3600 python ~ / Conky / scripts / conkyForecast.py -location = ARBA0009 -datatype = HM} $ {alignr 2} $ {color1} Precipitació: $ {color3} $ { execi 3600 python ~ / Conky / scripts / conkyForecast.py -location = ARBA0009 -datatype = PC} $ color
$ {Alignc} $ {color1} Pressió: $ {color3} $ {execi 3600 python ~ / Conky / scripts / conkyForecast.py -location = ARBA0009 -datatype = BR} - $ {color3} $ {execi 3600 python ~ / Conky /scripts/conkyForecast.py -location = ARBA0009 -datatype = BD} $ color
$ {Color4} $ {hr} $ color
$ {Color1} Sortida de Sol: $ {color3} $ {execi 3600 python ~ / Conky / scripts / conkyForecast.py -location = ARBA0009 -datatype = SR} $ {alignr 2} $ {color1} Ocàs: $ {color3} $ {execi 3600 python ~ / Conky / scripts / conkyForecast.py -location = ARBA0009 -datatype = SS} $ color
$ {Voffset 15} $ {color1} Lluna: $ {color4} $ {alignr 2} $ {color3} $ {execi 3600 python ~ / Conky / scripts / conkyForecast.py -location = ARBA0009 -datatype = MP} $ color
$ {Voffset -20} $ {òfset 80} $ {color4} $ {font moon phases: size = 20} $ {execi 3600 python ~ / Conky / scripts / conkyForecast.py -location = ARBA0009 -datatype = MF} $ font $ color
$ {Color0} $ {hr} $ color
$ {Voffset 5} $ {color2} IP: $ {alignc} $ color $ {addr eth0}
$ {Color1} Down: $ color $ {downspeed eth0} k / s $ {alignr 2} $ {color1} Up: $ color $ {upspeed eth0} k / s
$ {Color1} Total: $ color $ {totaldown eth0} $ {alignr 2} $ {color1} Total: $ color $ {totalup eth0}
$ {Color1} Inbound: $ color $ {tcp_portmon 1 32767 count} $ {color1} Outbound: $ color $ {tcp_portmon 32768 61000 count} $ {alignr 2} $ {color1} Total: $ color $ {tcp_portmon 1 65535 count}
$ {Voffset 5} $ {color2} Connections: $ color $ {tcp_portmon 32768 61000 count} $ {alignr 2} $ {color2} Service / Port $ color
$ {Voffset 5} $ {tcp_portmon 32768 61000 rhost 0} $ {alignr 2} $ {tcp_portmon 32768 61000 rservice 0}
$ {Tcp_portmon 32768 61000 rhost 1} $ {alignr 2} $ {tcp_portmon 32768 61000 rservice 1}
$ {Tcp_portmon 32768 61000 rhost 2} $ {alignr 2} $ {tcp_portmon 32768 61000 rservice 2}
$ {Tcp_portmon 32768 61000 rhost 3} $ {alignr 2} $ {tcp_portmon 32768 61000 rservice 3}
$ {Tcp_portmon 32768 61000 rhost 4} $ {alignr 2} $ {tcp_portmon 32768 61000 rservice 4}
$ {Tcp_portmon 32768 61000 rhost 5} $ {alignr 2} $ {tcp_portmon 32768 61000 rservice 5} $ color

vam crear el fitxer ~ / Conky / conkyforecast

gedit ~ / Conky / conkyforecast

i enganxem dins el següent

background no
own_window yes
own_window_transparent yes
own_window_hints undecorated, below, sticky, skip_taskbar, skip_pager
own_window_colour black
double_buffer yes
use_spacer left
use_xft yes
font Calibri: size = 8
xftfont Calibri: size = 8
xftalpha 0.5
update_interval 5.0
uppercase no # setembre to yes if you want all text to be in uppercase
stippled_borders 3
border_margin maig
border_width 10
default_color white
default_outline_color black
default_shade_color black
color0 cyan
color1 lightblue
color2 orange
color3 groc
color4 wheat
color5 blanc
color6 blanc
color7 blanc
color8 blanc
color9 blanc
alignment bottom_left # or top_left, bottom_left, bottom_right
gap_x maig
gap_y 35
text_buffer_size 1024 # usi 1024 for the forecast
no_buffers yes # Subtract file system buffers from used memory?
draw_borders no
draw_outline yes # amplifies text if yes
draw_shades yes # shadecolor black

TEXT
$ {Color4} $ {font Calibri: size = 11} Pronostico Estès $ font $ color
$ {Color0} $ {hr} $ color
$ {Color4} $ {font Calibri: size = 9} $ {execi 3600 python ~ / Conky / scripts / conkyForecast.py -location = ARBA0009 -template = / home / usuari / Conky / scripts / myweather.template} $ font $ color

vam crear el fitxer ~ / Conky / conkymail

gedit ~ / Conky / conkymail

enganxem dins de l'arxiu el següent

background no
own_window yes
own_window_transparent yes
own_window_hints undecorated, below, sticky, skip_taskbar, skip_pager
own_window_colour black
double_buffer yes
use_spacer left
use_xft yes
font Calibri: size = 8
xftfont Calibri: size = 8
xftalpha 0.5
update_interval 5.0
uppercase no # setembre to yes if you want all text to be in uppercase
stippled_borders 3
border_margin maig
border_width 10
default_color white
default_outline_color black
default_shade_color black
color0 cyan
color1 lightblue
color2 orange
color3 groc
color4 wheat
color5 blanc
color6 blanc
color7 blanc
color8 blanc
color9 blanc
alignment bottom_left # or top_left, bottom_left, bottom_right
gap_x maig
gap_y 35
text_buffer_size 128 # usi 1024 for the forecast
no_buffers yes # Subtract file system buffers from used memory?
draw_borders no
draw_outline yes # amplifies text if yes
draw_shades yes # shadecolor black

TEXT
$ {Font Calibri: size = 11} $ {alignc} $ {color4} Gmail
$ {Color0} $ {hr} $ color
$ {Font Calibri: size = 11} $ {color4} Tenim $ {color3} $ {execi 300 python ~ / Conky / scripts / mail / conkyEmail.py} $ {color4} email (s) $ font

Vam crear un arxiu en ~ / Conky / scripts / conkyForecast.py (cal crear la carpeta scripts)

gedit ~ / Conky / scripts / conkyForecast.py

#! / Usr / bin / python
# - * - coding: utf-8 - * -
################################################## #############################
# ConkyForecast.py is a (not so) simple (anymore) python script to gather
# Detalls of the current weather for use in Conky.
#
# Autor: Kaivalagi
# Created: 13/04/2008
# Modifications:
# 14/04/2008 Allow day ranges for forecast data
# 14/04/2008 Check for connectivity to xoap service
# 18/04/2008 Allow the setting of spaces for ranged output
# 18/04/2008 Allow Night and Day forecast output
# 18/04/2008 Support locale for condition code text «CC» option, awaiting spanish language translation
# 18/04/2008 Utilitza pickling for class data rather than opening xml, this bypasses the need to interrogate cached data
# 19/04/2008 Added spanish condition text - Thanks Bruce M
# 19/04/2008 Added isnumeric check on all numeric output with units suffix
# 19/04/2008 Altered pickle file naming to include location code
# 19/04/2008 Added spanish week days conversion via locale
# 20/04/2008 Added decent command argument parser
# 20/04/2008 Added -shortweekday option, if given the day of week data type is shortened to 3 characters
# 21/04/2008 Fixed locale options for forecast output
# 21/04/2008 Added -template option to allow custom output using a single exec call 🙂
# 21/04/2008 Added -hideunits option to remove, for example, mph and C from output
# 23/04/2008 Removed -imperial option from template, this MUST be setembre es a standard option on the script call and not used in the template file.
# 23/04/2008 Readded -imperial option to template, enabling metric or imperial values ​​per datatype. Note when using templates command line option will not work.
# 23/04/2008 Added output notifying user if the location given is bad
# 24/04/2008 Added serveis de terra for no connectivity, will revert to cached data now (erroring if no cau exists). Tests by trying to open xoap.weather.com
# 24/04/2008 Fixed Celsius to fahrenheit conversion
# 06/05/2008 Updated URL used after webservice was updated
# 09/05/2008 Consolidated current condition and forecast data fetch into one call
# 09/05/2008 Added Sunrise and sunset to datatypes, these are specific to both current conditions and forecast data
# 09/05/2008 Added moon phase, Barometer reading and Barometer description to datatypes, these are only specific to current conditions and so are N / A in forecasted output
# 09/05/2008 Added unit Conversions for Barometer from mb to inches (imperial)
# 09/05/2008 Updated spanish condition text - Thanks Bruce M
# 10/05/2008 Added french locale data - Thanks benpaka
# 12/05/2008 Added new BF (bearing font) datatype to provide an arrow character (usi with Arrow.ttf font) instead of NSEW output from WD (wind direction)
# 12/05/2008 Updated WD output to be locale specific, currently supports default english and spanish - Thanks Bruce M
# 18/05/2008 Added new MF (moon font) datatype to provide a moon font character (characters incorrect and no dedicated font yet).
# 21/05/2008 For current conditions the -datatype = LT option now displays «feels like» temperature rather than the current temperature
#
# TOT:
# Consolidate PKL files into one file / class
# Add a weather font based moon phase output based on moon icon data
#??? Any more requirements out there?

import sys, us, socket, urllib2, datetime, time
from xml.dom import minidom
from stat import *
from optparse import OptionParser
import locale
import gettext
importar escabetx
de la importació de matemàtiques *

APP = »conkyForecast.py»
DIR = os.path.dirname (__file__) + '/ locale'
gettext.bindtextdomain (APP, DIR)
gettext.textdomain (APP)
_ = Gettext.gettext

class CommandLineParser:

parser = None

def __init __ (self):

self.parser = OptionParser ()
self.parser.add_option ( «- l», »- location», dest = »location», default = »UKXX0103", type = »string», metavar = »CODE», help = u »location code for weather data [ default:% default], Utilitza the following uRL to determini your location code by city name: http://xoap.weather.com/search/search?where=Norwich »)
self.parser.add_option ( «- d», »- datatype», dest = »datatype», default = »HT», type = »string», metavar = »DataType», help = u »[default:% default] The data type options are: DW (Day Of Week), WF (Weather Font Output), LT (Forecast: Low Temp, Current: Feels Like Temp), HT (Forecast: High Temp, Current: Current Temp), CC (Current Conditions), CT (Conditions Text), PC (Precipitation Chance), HM (Humidity), WD (Wind Direction), WS (Wind Speed), WG (Wind Gusts), CN (City Name), Sr. (sunrise), SS (sunset), MP (moon phase), MF (moon font), BR (Barometer reading), BD (Barometer description). Not applicable at command line when using templates. »)
self.parser.add_option ( «- s», »- startday», dest = »startday», type = »int», metavar = »NUMBER», help = u »defineix the starting day number, if omitted current conditions are output . Not applicable at command line when using templates. »)
self.parser.add_option ( «- i», »- endday», dest = »endday», type = »int», metavar = »NUMBER», help = u »defineix the ending day number, if omitted only starting day data is output. Not applicable at command line when using templates. »)
self.parser.add_option ( «- S», »- spaces», dest = »spaces», type = »int», default = 1, metavar = »NUMBER», help = u »[default:% default] Defineix the number of spaces between ranged output. Not applicable at command line when using templates. »)
self.parser.add_option ( «- t», »- template ', dest =» template', type = »string», metavar = »FILE», help = u »defineix a template file to generate output in one call. A displayable item in the file is in the form {-datatype = HT -startday = 1}. The following are possible options within each item: -datatype, -startday, -endday, -night, -shortweekday, -imperial, -hideunits, -spaces. Note that the short forms of the options are not currently supported! None of these options are applicable at command line when using templates. »)
self.parser.add_option ( «- L», »- locale», dest = »locale», type = »string», help = u »override the system locale for language output (en = english, és = spanish, fr = french, more to come) »)
self.parser.add_option ( «- i», »- imperial», dest = »imperial», default = False, action = »store_true», help = u »request imperial units, if omitted output is in metric. Not applicable at command line when using templates. »)
self.parser.add_option ( «- n», »- night», dest = »night», default = False, action = »store_true», help = u »switch output to night data, if omitted day output will be output. not applicable at command line when using templates. »)
self.parser.add_option ( «- w», »- shortweekday», dest = »shortweekday», default = False, action = »store_true», help = u »Shorten the day of week data type to 3 characters. Not applicable at command line when using templates. »)
self.parser.add_option ( «- o», »- hideunits», dest = »hideunits», default = False, action = »store_true», help = u »Hide units such as mph or C, degree symbols (°) are still shown. Not applicable at command line when using templates. »)
self.parser.add_option ( «- v», »- verbose», dest = »verbose», default = False, action = »store_true», help = u »request verbose output, no a good idea when running through Conky!» )
self.parser.add_option ( «- r», »- refetch», dest = »refetch», default = False, action = »store_true», help = u »fetch data regardless of data expiry»)

def parse_args (self):
(Options, args) = self.parser.parse_args ()
return (options, args)

def print_help (self):
return self.parser.print_help ()

class WeatherData:
def __init __ (self, day_of_week, low, high, condition_code, condition_text, precip, humidity, wind_dir, wind_speed, wind_gusts, city, sunrise, sunset, moon_phase, moon_icon, bar_read, bar_desc):
self.day_of_week = u »» + day_of_week
self.low = u »» + low
self.high = u »» + high
self.condition_code = u »» + condition_code
self.condition_text = u »» + condition_text
self.precip = u »» + precip
self.humidity = u »» + humidity
self.wind_dir = u »» + wind_dir
self.wind_speed = u »» + wind_speed
self.wind_gusts = u »» + wind_gusts
self.city = u »» + city
self.sunrise = u »» + sunrise
self.sunset = u »» + sunset
self.moon_phase = u »» + moon_phase
self.moon_icon = u »» + moon_icon
self.bar_read = u »» + bar_read
self.bar_desc = u »» + bar_desc

class WeatherText:

conditions_text = {
«0»: _ (o »Tornat»),
«1»: _ (o »Tropical Storm»),
«2»: _ (o »Hurricane»),
«3»: _ (o »Severe Pressió»),
«4»: _ (o »Pressió»),
«5»: _ (o »Mixed Rain and Snow»),
«6»: _ (o »Mixed Rain and Sleet»),
«7»: _ (o »Mixed Precipitation»),
«8»: _ (o »Freezing Drizzle»),
«9»: _ (o »Drizzle»),
«10»: _ (o »Freezing Rain»),
«11»: _ (o »Showers»),
«12»: _ (o »Showers»),
«13»: _ (o »Snow Flurries»),
«14»: _ (o »Light Snow Showers»),
«15»: _ (o »Blowing Snow»),
«16»: _ (o »Snow»),
«17»: _ (o »Hail»),
«18»: _ (o »Sleet»),
«19»: _ (o »Dust»),
«20»: _ (o »Fog»),
«21»: _ (o »Haze»),
«22»: _ (o »Smoke»),
«23»: _ (o »Blustery»),
«24»: _ (o »Windy»),
«25»: _ (o »Cold»),
«26»: _ (o »Cloudy»),
«27»: _ (o »Mostly Cloudy»),
«28»: _ (o »Mostly Cloudy»),
«29»: _ (o »Fair»),
«30»: _ (o »Fair»),
«31»: _ (o »Clear»),
«32»: _ (o »Clear»),
«33»: _ (o »Fair»),
«34»: _ (o »Fair»),
«35»: _ (o »Mixed Rain and Hail»),
«36»: _ (o »Hot»),
«37»: _ (o »Isolated Pressió»),
«38»: _ (o »Scattered Pressió»),
«39»: _ (o »Scattered Pressió»),
«40»: _ (o »Scattered Showers»),
«41»: _ (o »Heavy Snow»),
«42»: _ (o »Scattered Snow Showers»),
«43»: _ (o »Heavy Snow»),
«44»: _ (o »Fair»),
«45»: _ (o »Thunder Showers»),
«46»: _ (o »Snow Showers»),
«47»: _ (o »Isolated Pressió»),
«Na»: _ (o »N / A»),
«-«: _ (o »N / A»)
}

conditions_text_ca = {
«0»: _ (o »Tornat»),
«1»: _ (o »Tempesta Tropical»),
«2»: _ (o »Huracá¡n»),
«3»: _ (o »Tempestes Fortes»),
«4»: _ (o »Tempestes»),
«5»: _ (o »Pluja i Neu Barrejada»),
«6»: _ (o »Pluja i Aiguaneu Barrejada»),
«7»: _ (o »Aiguaneu»),
«8»: _ (o »Plugim Gelada»),
«9»: _ (o »Plugim»),
«10»: _ (o »pluja gelant»), # o pluja gelada
«11»: _ (o »Xàfecs»),
«12»: _ (o »Xàfecs»),
«13»: _ (o »Neu Lleugera»),
«14»: _ (o »Neu Lleugera»),
«15»: _ (o »Torb de Neu»),
«16»: _ (o »Neu»),
«17»: _ (o »Calamarsa»),
«18»: _ (o »Aiguaneu»),
«19»: _ (o »Pols»),
«20»: _ (o »Boira»),
«21»: _ (o »Boira»),
«22»: _ (o »Fum»),
«23»: _ (o »Tempesta»),
«24»: _ (o »Ventoso»),
«25»: _ (o »fred»),
«26»: _ (o »Molt ennuvolat»),
«27»: _ (o »Principalment Ennuvolat»),
«28»: _ (o »Principalment Ennuvolat»),
«29»: _ (o »Parcialment ennuvolat»),
«30»: _ (o »Parcialment ennuvolat»),
«31»: _ (o »Clar»),
«32»: _ (o »Clar»),
«33»: _ (o »Una mica ennuvolat»),
«34»: _ (o »Una mica ennuvolat»),
«35»: _ (o »Pluja amb Calamarsa»),
«36»: _ (o »Calor»),
«37»: _ (o »Tempestes aïllades»),
«38»: _ (o »Tempestes dispersos»),
«39»: _ (o »Tempestes dispersos»),
«40»: _ (o »Xàfecs Dispersos»),
«41»: _ (o »Neu Pesada»),
«42»: _ (o »Nevades Febles i dispersos»),
«43»: _ (o »Nevada intensa»),
«44»: _ (o »Núvols dispersos»),
«45»: _ (o »Tempestes»),
«46»: _ (o »Nevades dispersos»),
«47»: _ (o »Tempestes aïllades»),
«Na»: _ (o »N / A»),
«-«: _ (o »N / A»)
}

conditions_text_fr = {
«0»: _ (o »Tornade»),
«1»: _ (o »Tempête Tropicale»),
«2»: _ (o »Ouragan»),
«3»: _ (o »Orages Violents»),
«4»: _ (o »Orageux»),
«5»: _ (o »Pluie et Neige»),
«6»: _ (o »Pluie et Neige Mouillée»),
«7»: _ (o »Variable avec averses»),
«8»: _ (o »Bruine Givrante»),
«9»: _ (o »Bruine»),
«10»: _ (o »Pluie Glacante»),
«11»: _ (o »Averses»),
«12»: _ (o »Averses»),
«13»: _ (o »Légère Neige»),
«14»: _ (o »Forte Neige»),
«15»: _ (o »Tempête de Neige»),
«16»: _ (o »Neige»),
«17»: _ (o »Grêle»),
«18»: _ (o »Pluie / Neige»),
«19»: _ (o »Nuage de poussière»),
«20»: _ (o »Brouillard»),
«21»: _ (o »Brume»),
«22»: _ (o »fumee»),
«23»: _ (o »Tres Venteux»),
«24»: _ (o »Venteux»),
«25»: _ (o »Froid»),
«26»: _ (o »Nuageux»),
«27»: _ (o »Tres Nuageux»),
«28»: _ (o »Tres Nuageux»),
«29»: _ (o »Nuages ​​Disséminés»),
«30»: _ (o »Nuages ​​Disséminés»),
«31»: _ (o »Beau»),
«32»: _ (o »Beau»),
«33»: _ (o »Belles Éclaircies»),
«34»: _ (o »Belles Éclaircies»),
«35»: _ (o »Pluie avec Grêle»),
«36»: _ (o »Chaleur»),
«37»: _ (o »Orages Isoles»),
«38»: _ (o »Orages Localisés»),
«39»: _ (o »Orages Localisés»),
«40»: _ (o »Averses Localisées»),
«41»: _ (o »Neige Lourde»),
«42»: _ (o »Tempête de Neige Localisées»),
«43»: _ (o »Neige Lourde»),
«44»: _ (o »Nuages ​​Disséminés»),
«45»: _ (o »Orages»),
«46»: _ (o »Tempête de Neige»),
«47»: _ (o »Orages Isoles»),
«Na»: _ (o »N / A»),
«-«: _ (o »N / A»)
}

conditions_weather_font = {
«0»: _ (o »W»),
«1»: _ (o »V»),
«2»: _ (o »W»),
«3»: _ (o »s»),
«4»: _ (o »p»),
«5»: _ (o »k»),
«6»: _ (o »k»),
«7»: _ (o »g»),
«8»: _ (o »g»),
«9»: _ (o »g»),
«10»: _ (o »h»),
«11»: _ (o »g»),
«12»: _ (o »g»),
«13»: _ (o »k»),
«14»: _ (o »k»),
«15»: _ (o »k»),
«16»: _ (o »k»),
«17»: _ (o »k»),
«18»: _ (o »k»),
«19»: _ (o »i»),
«20»: _ (o »i»),
«21»: _ (o »a»),
«22»: _ (o »d»),
«23»: _ (o »d»),
«24»: _ (o »d»),
«25»: _ (o »d»),
«26»: _ (o »i»),
«27»: _ (o »i»),
«28»: _ (o »i»),
«29»: _ (o »c»),
«30»: _ (o »c»),
«31»: _ (o »a»),
«32»: _ (o »a»),
«33»: _ (o »b»),
«34»: _ (o »b»),
«35»: _ (o »k»),
«36»: _ (o »a»),
«37»: _ (o »f»),
«38»: _ (o »f»),
«39»: _ (o »f»),
«40»: _ (o »g»),
«41»: _ (o »k»),
«42»: _ (o »k»),
«43»: _ (o »k»),
«44»: _ (o »b»),
«45»: _ (o »g»),
«46»: _ (o »k»),
«47»: _ (o »f»),
«Na»: _ (o »»),
«-«: _ (o »»)
}

conditions_moon_font = {
«0»: _ (o »1"),
«1»: _ (o »N»),
«2»: _ (o »O»),
«3»: _ (o »P»),
«4»: _ (o »Q»),
«5»: _ (o »R»),
«6»: _ (o »S»),
«7»: _ (o »T»),
«8»: _ (o »O»),
«9»: _ (o »V»),
«10»: _ (o »W»),
«11»: _ (o »X»),
«12»: _ (o »I»),
«13»: _ (o »Z»),
«14»: _ (o »0"),
«15»: _ (o »0"),
«16»: _ (o »A»),
«17»: _ (o »B»),
«18»: _ (o »C»),
«19»: _ (o »D»),
«20»: _ (o »I»),
«21»: _ (o »F»),
«22»: _ (o »G»),
«23»: _ (o »H»),
«24»: _ (o »I»),
«25»: _ (o »J»),
«26»: _ (o »K»),
«27»: _ (o »L»),
«28»: _ (o »M»),
«29»: _ (o »1"),
«Na»: _ (o »»),
«-«: _ (o »»)
}

day_of_week = {
«Today»: _ (o »Today»),
«Monday»: _ (o »Monday»),
«Tuesday»: _ (o »Tuesday»),
«Wednesday»: _ (o »Wednesday»),
«Thursday»: _ (o »Thursday»),
«Friday»: _ (o »Friday»),
«Saturday»: _ (o »Saturday»),
«Sunday»: _ (o »Sunday»)
}

day_of_week_short = {
«Today»: _ (o »Now»),
«Monday»: _ (o »Mon»),
«Tuesday»: _ (o »Tue»),
«Wednesday»: _ (o »Wed»),
«Thursday»: _ (o »Thu»),
«Friday»: _ (o »Fri»),
«Saturday»: _ (o »Sat»),
«Sunday»: _ (o »Sun»)
}

day_of_week_ca = {
«Today»: _ (o »avui»),
«Monday»: _ (o »dilluns»),
«Tuesday»: _ (o »dimarts»),
«Wednesday»: _ (o »dimecres»),
«Thursday»: _ (o »dijous»),
«Friday»: _ (o »divendres»),
«Saturday»: _ (o »dissabte»),
«Sunday»: _ (o »diumenge»)
}

day_of_week_short_ca = {
«Today»: _ (o »avui»),
«Monday»: _ (o »dl»),
«Tuesday»: _ (o »mar»),
«Wednesday»: _ (o »dc»),
«Thursday»: _ (o »dj»),
«Friday»: _ (o »dv»),
«Saturday»: _ (o »ds»),
«Sunday»: _ (o »dom«)
}

day_of_week_fr = {
«Today»: _ (o »Aujourd'hui»),
«Monday»: _ (o »Lundi»),
«Tuesday»: _ (o »Mardi»),
«Wednesday»: _ (o »Mercredi»),
«Thursday»: _ (o »Jeudi»),
«Friday»: _ (o »Vendredi»),
«Saturday»: _ (o »Samedi»),
«Sunday»: _ (o »Dimanche»)
}

day_of_week_short_fr = {
«Today»: _ (o »Auj»),
«Monday»: _ (o »Dll»),
«Tuesday»: _ (o »mar»),
«Wednesday»: _ (o »Mer»),
«Thursday»: _ (o »Jeu»),
«Friday»: _ (o »Vine»),
«Saturday»: _ (o »Sam»),
«Sunday»: _ (o »Dim»)
}

bearing_arrow_font = {
«N»: _ (o »i»),
«NNE»: _ (o »j»),
«NE»: _ (o »k»),
«ENE»: _ (o »l»),
«I»: _ (o »m»),
«ESE»: _ (o »n»),
«ES»: _ (o »o»),
«SSE»: _ (o »p»),
«S»: _ (o »a»),
«SSW»: _ (o »b»),
«SW»: _ (o »c»),
«WSW»: _ (o »d»),
«W»: _ (o »i»),
«WNW»: _ (o »f»),
«NW»: _ (o »g»),
«NNW»: _ (o »h»),
«N / A»: _ (o »«)
}

bearing_text_ca = {
«N»: _ (o »N»),
«NNE»: _ (o »NNE»),
«NE»: _ (o »NE»),
«ENE»: _ (o »ENE»),
«I»: _ (o »I»),
«ESE»: _ (o »ESE»),
«ES»: _ (o »ES»),
«SSE»: _ (o »SSE»),
«S»: _ (o »S»),
«SSW»: _ (o »SSO»),
«SW»: _ (o »SO»),
«WSW»: _ (o »WOW»),
«W»: _ (o »O»),
«WNW»: _ (o »ONO»),
«NW»: _ (o »NO»),
«NNW»: _ (o »NNO»),
«N / A»: _ (o »N \ A»)
}

bearing_text_fr = {
«N»: _ (o »N»),
«NNE»: _ (o »NNE»),
«NE»: _ (o »NE»),
«ENE»: _ (o »ENE»),
«I»: _ (o »I»),
«ESE»: _ (o »ESE»),
«ES»: _ (o »ES»),
«SSE»: _ (o »SSE»),
«S»: _ (o »S»),
«SSW»: _ (o »SSO»),
«SW»: _ (o »SO»),
«WSW»: _ (o »WOW»),
«W»: _ (o »O»),
«WNW»: _ (o »ONO»),
«NW»: _ (o »NO»),
«NNW»: _ (o »NNO»),
«N / A»: _ (o »N \ A»)
}

class GlobalWeather:

condicions_actuals = []
day_forecast = []
night_forecast = []

locale = «a»

options = None
weatherxmldoc = «»

TEMP_FILEPATH_CURRENT = «/tmp/conkyForecast-c-LOCATION.pkl»
TEMP_FILEPATH_DAYFORECAST = "/tmp/conkyForecast-df-LOCATION.pkl"
TEMP_FILEPATH_NIGHTFORECAST = "/tmp/conkyForecast-nf-LOCATION.pkl"
EXPIRY_MINUTES = 30
DEFAULT_SPACING = u »«

def __init __ (self, options):

self.options = options

if self.options.locale == None:
provar:
# Self.locale = locale.getdefaultlocale () [0] [0: 2]
self.locale = «és» #uncomment this line to force Spanish locale
# Self.locale = «fr» #uncomment this line to force French locale
excepte:
print locale not set
en cas contrari:
# Self.locale = self.options.locale
self.locale = «és» #uncomment this line to force Spanish locale
# Self.locale = «fr» #uncomment this line to force French locale

if self.options.verbose == True:
print >> sys.stdout, «locale setembre to«, self.locale

def gettext (self, nodelist):
rc = «»
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc = rc + node.data
return rc

def getSpaces (self, spaces):
string = u »»
if spaces == None:
string = self.DEFAULT_SPACING
en cas contrari:
for i in range (0, spaces + 1):
string = string + o »«
return string

def isNumeric (self, string):
provar:
dummy = float (string)
torna Veritat
excepte:
retornar Fals

def isConnectionAvailable (self):
# Ensure we can access weather.com 's server by opening the URL
provar:
usock = urllib2.urlopen ( 'http://xoap.weather.com')
usock.close ()
torna Veritat
excepte:
retornar Fals

def getBearingText (self, bearing):
bearing = float (bearing)
if bearing <11.25:
return o »N»
elif bearing <33.75:
return o »NNE»
elif bearing <56.25:
return o »NE»
elif bearing <78.75:
return o »GEN»
elif bearing <101.25:
return o »E»
elif bearing <123.75:
return o »ESE»
elif bearing <146.25:
return o »ES»
elif bearing <168.75:
return o »SSE»
elif bearing <191.25:
return o »S»
elif bearing <213.75:
return o »SSW»
elif bearing <236.25:
return o »SW»
elif bearing <258.75:
return o »WSW»
elif bearing <281.25:
return o »W»
elif bearing <303.75:
return o »WNW»
elif bearing <326.25:
return o »NW»
elif bearing <348.75:
return o »NNW»
en cas contrari:
return «N / A»

def convertCelsiusToFahrenheit (self, temp):
return str (int (floor (((float (temp) * 9.0) /5.0) +32)))

def convertKilometresToMiles (self, dist):
return str (int (floor (float (dist) * 0.621371192)))

def convertMillibarsToInches (self, mb):
return str (int (floor (float (mb) /33.8582)))

def getTemplateList (self, template):

templatelist = []

for template_part in template.split ( «{«):
if template_part! = «»:
for template_part in template_part.split ( «}»):
if template_part! = «»:
templatelist.append (o »» + template_part)

return templatelist

def getOutputText (self, datatype, startday, endday, night, shortweekday, imperial, hideunits, spaces):
#try:
output = u »»

# Defineix current units for output
if hideunits == False:
if imperial == False:
tempunit = u »° C»
speedunit = u »kph»
pressureunit = u »mb»
en cas contrari:
tempunit = u »° F»
speedunit = u »mph»
pressureunit = u »in»
en cas contrari:
tempunit = u »°»
speedunit = u »»
pressureunit = u »»

if startday == None: # current conditions

if datatype == «DW»:
if self.locale == «és»:
if shortweekday == True:
output = WeatherText.day_of_week_short_es [self.current_conditions [0] .day_of_week]
en cas contrari:
output = WeatherText.day_of_week_es [self.current_conditions [0] .day_of_week]
elif self.locale == «fr»:
if shortweekday == True:
output = WeatherText.day_of_week_short_fr [self.current_conditions [0] .day_of_week]
en cas contrari:
output = WeatherText.day_of_week_fr [self.current_conditions [0] .day_of_week]
en cas contrari:
if shortweekday == True:
output = WeatherText.day_of_week_short [self.current_conditions [0] .day_of_week]
en cas contrari:
output = WeatherText.day_of_week [self.current_conditions [0] .day_of_week]
elif datatype == «WF»: # weather font
output = WeatherText.conditions_weather_font [self.current_conditions [0] .condition_code]
elif datatype == «LT»:
string = self.current_conditions [0] .low
if self.isNumeric (string) == True:
if imperial == True:
string = self.convertCelsiusToFahrenheit (string)
string = string + tempunit
output=string
elif datatype == «HT»:
string = self.current_conditions [0] .high
if self.isNumeric (string) == True:
if imperial == True:
string = self.convertCelsiusToFahrenheit (string)
string = string + tempunit
output=string
elif datatype == «CC»:
if self.locale == «és»:
output = WeatherText.conditions_text_es [self.current_conditions [0] .condition_code]
elif self.locale == «fr»:
output = WeatherText.conditions_text_fr [self.current_conditions [0] .condition_code]
en cas contrari:
output = WeatherText.conditions_text [self.current_conditions [0] .condition_code]
elif datatype == «CT»:
output = self.current_conditions [0] .condition_text
elif datatype == «PC»:
string = self.current_conditions [0] .precip
if self.isNumeric (string) == True:
string = string + o »%»
output=string
elif datatype == «HM»:
string = self.current_conditions [0] .humidity
if self.isNumeric (string) == True:
string = string + o »%»
output=string
elif datatype == «WD»:
string = self.current_conditions [0] .wind_dir
if self.isNumeric (string) == True:
string = self.getBearingText (string)

if self.locale == «és»:
output = WeatherText.bearing_text_es [string]
elif self.locale == «fr»:
output = WeatherText.bearing_text_fr [string]
en cas contrari:
output=string

elif datatype == «BF»:
string = self.current_conditions [0] .wind_dir
if self.isNumeric (string) == True:
string = WeatherText.bearing_arrow_font [self.getBearingText (string)]
output=string
elif datatype == WS:
string = self.current_conditions [0] .wind_speed
if self.isNumeric (string) == True:
if imperial == True:
string = self.convertKilometresToMiles (string)
string = string + speedunit
output=string
elif datatype == "WG":
string = self.current_conditions [0] .wind_gusts
if self.isNumeric (string) == True:
if imperial == True:
string = self.convertKilometresToMiles (string)
string = string + speedunit
output=string
elif datatype == «CN»:
output = self.current_conditions [0] .city
elif datatype == «SR»:
output = self.current_conditions [0] .sunrise
elif datatype == «SS»:
output = self.current_conditions [0] .sunset
elif datatype == «MP»:
output = self.current_conditions [0] .moon_phase
elif datatype == «MF»:
output = WeatherText.conditions_moon_font [self.current_conditions [0] .moon_icon]
elif datatype == «BR»:
string = self.current_conditions [0] .bar_read
if self.isNumeric (string) == True:
if imperial == True:
string = self.convertMillibarsToInches (string)
string = string + pressureunit
output=string
elif datatype == «BD»:
output = self.current_conditions [0] .bar_desc
en cas contrari:
output = «\ nError: Unknown data type requested»

else: # forecast data

if endday == None: # if no endday was setembre usi startday
endday = startday

if night == True: # night forecast requerida

for day_number in range (startday, endday + 1):

if datatype == «DW»:
if self.locale == «és»:
if shortweekday == True:
output = output + self.getSpaces (spaces) + WeatherText.day_of_week_short_es [self.night_forecast [day_number] .day_of_week]
en cas contrari:
output = output + self.getSpaces (spaces) + WeatherText.day_of_week_es [self.night_forecast [day_number] .day_of_week]
elif self.locale == «fr»:
if shortweekday == True:
output = output + self.getSpaces (spaces) + WeatherText.day_of_week_short_fr [self.night_forecast [day_number] .day_of_week]
en cas contrari:
output = output + self.getSpaces (spaces) + WeatherText.day_of_week_fr [self.night_forecast [day_number] .day_of_week]
en cas contrari:
if shortweekday == True:
output = output + self.getSpaces (spaces) + WeatherText.day_of_week_short [self.night_forecast [day_number] .day_of_week]
en cas contrari:
output = output + self.getSpaces (spaces) + WeatherText.day_of_week [self.night_forecast [day_number] .day_of_week]
elif datatype == «WF»: # weather font
output = output + self.getSpaces (spaces) + WeatherText.conditions_weather_font [self.night_forecast [day_number] .condition_code]
elif datatype == «LT»:
string = self.night_forecast [day_number] .low
if self.isNumeric (string) == True:
if imperial == True:
string = self.convertCelsiusToFahrenheit (string)
string = string + tempunit
output = output + self.getSpaces (spaces) + string

elif datatype == «HT»:
string = self.night_forecast [day_number] .high
if self.isNumeric (string) == True:
if imperial == True:
string = self.convertCelsiusToFahrenheit (string)
string = string + tempunit
output = output + self.getSpaces (spaces) + string
elif datatype == «CC»:
if self.locale == «és»:
output = output + self.getSpaces (spaces) + WeatherText.conditions_text_es [self.night_forecast [day_number] .condition_code]
elif self.locale == «fr»:
output = output + self.getSpaces (spaces) + WeatherText.conditions_text_fr [self.night_forecast [day_number] .condition_code]
en cas contrari:
output = output + self.getSpaces (spaces) + WeatherText.conditions_text [self.night_forecast [day_number] .condition_code]
elif datatype == «CT»:
output = output + self.getSpaces (spaces) + self.night_forecast [day_number] .condition_text
elif datatype == «PC»:
string = self.night_forecast [day_number] .precip
if self.isNumeric (string) == True:
string = string + o »%»
output = output + self.getSpaces (spaces) + string
elif datatype == «HM»:
string = self.night_forecast [day_number] .humidity
if self.isNumeric (string) == True:
string = string + o »%»
output = output + self.getSpaces (spaces) + string
elif datatype == «WD»:
string = self.night_forecast [day_number] .wind_dir
if self.locale == «és»:
output = output + self.getSpaces (spaces) + WeatherText.bearing_text_es [string]
elif self.locale == «fr»:
output = output + self.getSpaces (spaces) + WeatherText.bearing_text_fr [string]
en cas contrari:
output = output + self.getSpaces (spaces) + string

elif datatype == «BF»:
output = output + self.getSpaces (spaces) + WeatherText.bearing_arrow_font [self.night_forecast [day_number] .wind_dir]
elif datatype == WS:
string = self.night_forecast [day_number] .wind_speed
if self.isNumeric (string) == True:
if imperial == True:
string = self.convertKilometresToMiles (string)
string = string + speedunit
output = output + self.getSpaces (spaces) + string
elif datatype == "WG":
string = self.night_forecast [day_number] .wind_gusts
if self.isNumeric (string) == True:
if imperial == True:
string = self.convertKilometresToMiles (string)
string = string + speedunit
output = output + self.getSpaces (spaces) + string
elif datatype == «CN»:
output = output + self.getSpaces (spaces) + self.night_forecast [day_number] .city
elif datatype == «SR»:
output = output + self.getSpaces (spaces) + self.night_forecast [day_number] .sunrise
elif datatype == «SS»:
output = output + self.getSpaces (spaces) + self.night_forecast [day_number] .sunset
elif datatype == «MP»:
output = output + self.getSpaces (spaces) + self.night_forecast [day_number] .moon_phase
elif datatype == «MF»:
output = output + self.getSpaces (spaces) + WeatherText.conditions_moon_font [self.night_forecast [day_number] .moon_icon]
elif datatype == «BR»:
output = output + self.getSpaces (spaces) + self.night_forecast [day_number] .bar_read
elif datatype == «BD»:
output = output + self.getSpaces (spaces) + self.night_forecast [day_number] .bar_desc
en cas contrari:
output = «\ nError: Unknown data type requested»
trencar

else: # day forecast wanted

for day_number in range (startday, endday + 1):

if datatype == «DW»:
if self.locale == «és»:
if shortweekday == True:
output = output + self.getSpaces (spaces) + WeatherText.day_of_week_short_es [self.day_forecast [day_number] .day_of_week]
en cas contrari:
output = output + self.getSpaces (spaces) + WeatherText.day_of_week_es [self.day_forecast [day_number] .day_of_week]
elif self.locale == «fr»:
if shortweekday == True:
output = output + self.getSpaces (spaces) + WeatherText.day_of_week_short_fr [self.day_forecast [day_number] .day_of_week]
en cas contrari:
output = output + self.getSpaces (spaces) + WeatherText.day_of_week_fr [self.day_forecast [day_number] .day_of_week]
en cas contrari:
if shortweekday == True:
output = output + self.getSpaces (spaces) + WeatherText.day_of_week_short [self.day_forecast [day_number] .day_of_week]
en cas contrari:
output = output + self.getSpaces (spaces) + WeatherText.day_of_week [self.day_forecast [day_number] .day_of_week]
elif datatype == «WF»: # weather font
output = output + self.getSpaces (spaces) + WeatherText.conditions_weather_font [self.day_forecast [day_number] .condition_code]
elif datatype == «LT»:
string = self.day_forecast [day_number] .low
if self.isNumeric (string) == True:
if imperial == True:
string = self.convertCelsiusToFahrenheit (string)
string = string + tempunit
output = output + self.getSpaces (spaces) + string
elif datatype == «HT»:
string = self.day_forecast [day_number] .high
if self.isNumeric (string) == True:
if imperial == True:
string = self.convertCelsiusToFahrenheit (string)
string = string + tempunit
output = output + self.getSpaces (spaces) + string
elif datatype == «CC»:
if self.locale == «és»:
output = output + self.getSpaces (spaces) + WeatherText.conditions_text_es [self.day_forecast [day_number] .condition_code]
elif self.locale == «fr»:
output = output + self.getSpaces (spaces) + WeatherText.conditions_text_fr [self.day_forecast [day_number] .condition_code]
en cas contrari:
output = output + self.getSpaces (spaces) + WeatherText.conditions_text [self.day_forecast [day_number] .condition_code]
elif datatype == «CT»:
output = output + self.getSpaces (spaces) + self.day_forecast [day_number] .condition_text
elif datatype == «PC»:
string = self.day_forecast [day_number] .precip
if self.isNumeric (string) == True:
string = string + o »%»
output = output + self.getSpaces (spaces) + string
elif datatype == «HM»:
string = self.day_forecast [day_number] .humidity
if self.isNumeric (string) == True:
string = string + o »%»
output = output + self.getSpaces (spaces) + string
elif datatype == «WD»:
string = self.day_forecast [day_number] .wind_dir

if self.locale == «és»:
output = output + self.getSpaces (spaces) + WeatherText.bearing_text_es [string]
elif self.locale == «fr»:
output = output + self.getSpaces (spaces) + WeatherText.bearing_text_fr [string]
en cas contrari:
output = output + self.getSpaces (spaces) + string

elif datatype == «BF»:
output = output + self.getSpaces (spaces) + WeatherText.bearing_arrow_font [self.day_forecast [day_number] .wind_dir]
elif datatype == WS:
string = self.day_forecast [day_number] .wind_speed
if self.isNumeric (string) == True:
if imperial == True:
string = self.convertKilometresToMiles (string)
string = string + speedunit
output = output + self.getSpaces (spaces) + string
elif datatype == "WG":
string = self.day_forecast [day_number] .wind_gusts
if self.isNumeric (string) == True:
if imperial == True:
string = self.convertKilometresToMiles (string)
string = string + speedunit
output = output + self.getSpaces (spaces) + string
elif datatype == «CN»:
output = output + self.getSpaces (spaces) + self.day_forecast [day_number] .city
elif datatype == «SR»:
output = output + self.getSpaces (spaces) + self.day_forecast [day_number] .sunrise
elif datatype == «SS»:
output = output + self.getSpaces (spaces) + self.day_forecast [day_number] .sunset
elif datatype == «MP»:
output = output + self.getSpaces (spaces) + self.day_forecast [day_number] .moon_phase
elif datatype == «MF»:
output = output + self.getSpaces (spaces) + WeatherText.conditions_moon_font [self.day_forecast [day_number] .moon_icon]
elif datatype == «BR»:
output = output + self.getSpaces (spaces) + self.day_forecast [day_number] .bar_read
elif datatype == «BD»:
output = output + self.getSpaces (spaces) + self.day_forecast [day_number] .bar_desc
en cas contrari:
output = u »\ nError: Unknown data type requested»
trencar

output = u »» + output.strip (o »«) # else leading / trailing spaces
retorn de sortida

#except:
#print «getOutputText: Unexpected error:«, sys.exc_info () [0]

def getOutputTextFromTemplate (self, template):
#try:

# Keys to template data
DATATYPE_KEY = «-datatype =»
STARTDAY_KEY = «-startday =»
ENDDAY_KEY = «-endday =»
NIGHT_KEY = «-night»
SHORTWEEKDAY_KEY = «-shortweekday»
IMPERIAL_KEY = «-imperial»
HIDEUNITS_KEY = «-hideunits»
SPACES_KEY = «-spaces =»

output = u »»

optionfound = False

#load the file
provar:
fileinput = open (self.options.template)
template = fileinput.read ()
fileinput.close ()
excepte:
output = u »Template file no found!»

templatelist = self.getTemplateList (template)

# Lets walk through the template list and determini the output for each item found
for i in range (0, len (templatelist) -1):

pos = templatelist [i] .find (DATATYPE_KEY)
if pos! = -1:
optionfound = True
pos = pos + len (DATATYPE_KEY)
datatype = templatelist [i] [pos: pos + 4] .strip ( «}»). strip ( «{«). strip ( «-«). strip ( »«)
en cas contrari:
datatype = None

pos = templatelist [i] .find (STARTDAY_KEY)
if pos! = -1:
optionfound = True
pos = pos + len (STARTDAY_KEY)
startday = int (templatelist [i] [pos: pos + 4] .strip ( «}»). strip ( «{«). strip ( «-«). strip ( »«))
en cas contrari:
startday = None

pos = templatelist [i] .find (ENDDAY_KEY)
if pos! = -1:
optionfound = True
pos = pos + len (ENDDAY_KEY)
endday = int (templatelist [i] [pos: pos + 4] .strip ( «}»). strip ( «{«). strip ( «-«). strip ( »«))
en cas contrari:
endday = None

pos = templatelist [i] .find (NIGHT_KEY)
if pos! = -1:
optionfound = True
night = True
en cas contrari:
night = False

pos = templatelist [i] .find (SHORTWEEKDAY_KEY)
if pos! = -1:
optionfound = True
shortweekday = True
en cas contrari:
shortweekday = False

pos = templatelist [i] .find (IMPERIAL_KEY)
if pos! = -1:
optionfound = True
imperial = True
en cas contrari:
imperial = False

pos = templatelist [i] .find (HIDEUNITS_KEY)
if pos! = -1:
optionfound = True
hideunits = True
en cas contrari:
hideunits = False

pos = templatelist [i] .find (SPACES_KEY)
if pos! = -1:
optionfound = True
pos = pos + len (SPACES_KEY)
spaces = int (templatelist [i] [pos: pos + 4] .strip ( «}»). strip ( «{«). strip ( «-«). strip ( »«))
en cas contrari:
spaces = 1

if optionfound == True:
templatelist [i] = self.getOutputText (datatype, startday, endday, night, shortweekday, imperial, hideunits, spaces)
optionfound = False

# Go through the list concatenating the output now that it 's been populated
for item in templatelist:
output = output + item

retorn de sortida

#except:
#print «getOutputTextFromTemplate: Unexpected error:«, sys.exc_info () [0]

def fetchData (self):

# Always fetch metric data, utilitzeu conversation functions on this data
file_path_current = self.TEMP_FILEPATH_CURRENT.replace ( «LOCATION», self.options.location)
file_path_dayforecast = self.TEMP_FILEPATH_DAYFORECAST.replace ( «LOCATION», self.options.location)
file_path_nightforecast = self.TEMP_FILEPATH_NIGHTFORECAST.replace ( «LOCATION», self.options.location)

if self.isConnectionAvailable () == False:
if os.path.exists (file_path_current):
RefetchData = False
else: # no connection, no cau, Bang!
print «No connection internet is available and no cached weather data exists.»
elif self.options.refetch == True:
RefetchData = True
en cas contrari:
# Does the data need Retrieving again?
if os.path.exists (file_path_current):
lastmodDate = time.localtime (os.stat (file_path_current) [ST_MTIME])
expiryDate = (datetime.datetime.today () - datetime.timedelta (minutes = self.EXPIRY_MINUTES)). timetuple ()

if expiryDate> lastmodDate:
RefetchData = True
en cas contrari:
RefetchData = False
en cas contrari:
RefetchData = True

# Fetch the current conditions data, either from the website or by 'unpickling'
if RefetchData == True:

# Obtain current conditions data from xoap service
provar:

# http://xoap.weather.com/weather/local/UKXX0103?cc=*&dayf=5&link=xoap∏=xoap&par=1061785028&key=e374effbfd74930b

url = 'http://xoap.weather.com/weather/local/' + self.options.location + '? cc = * & dayf = 8 & link = xoapΠ = xoap & parell = 1061785028 & key = e374effbfd74930b & unit = m'
if self.options.verbose == True:
print >> sys.stdout, «fetching weather data from«, url

usock = urllib2.urlopen (URL)
xml = usock.read ()
usock.close ()
self.weatherxmldoc = minidom.parseString (xml)
excepte:
print «fetchData: Unexpected error:«, sys.exc_info () [0]
print Unable to contact weather source for current conditions

# Tell the user if the location is bad ...
found = xml.find ( «Invalid location provided»)
if found! = -1:
print Invalid location provided

# Interrogate weather data, load into class structure and pickle it
provar:

# Prepari weather data lists
self.current_conditions = []
self.day_forecast = []
self.night_forecast = []

# Collect general data
weather_n = self.weatherxmldoc.documentElement
location_n = weather_n.getElementsByTagName ( 'loc') [0]
city_n = location_n.getElementsByTagName ( 'dnam') [0]
city ​​= self.getText (city_n.childNodes)

# Collect current conditions data
day_of_week = u »Today»
precip = u »N / A»
sunrise_n = location_n.getElementsByTagName ( 'sunr') [0]
sunrise = self.getText (sunrise_n.childNodes)
sunset_n = location_n.getElementsByTagName ( 'suns') [0]
sunset = self.getText (sunset_n.childNodes)
current_condition_n = weather_n.getElementsByTagName ( 'cc') [0]
current_desc_n = current_condition_n.getElementsByTagName ( 't') [0]
current_desc = self.getText (current_desc_n.childNodes)
current_code_n = current_condition_n.getElementsByTagName ( 'icon') [0]
current_code = self.getText (current_code_n.childNodes)
current_temp_n = current_condition_n.getElementsByTagName ( 'tmp') [0]
current_temp = self.getText (current_temp_n.childNodes)
current_temp_feels_n = current_condition_n.getElementsByTagName ( 'Flik') [0]
current_temp_feels = self.getText (current_temp_feels_n.childNodes)
bar_n = current_condition_n.getElementsByTagName ( 'bar') [0]
bar_read_n = bar_n.getElementsByTagName ( 'r') [0]
bar_read = self.getText (bar_read_n.childNodes)
bar_desc_n = bar_n.getElementsByTagName ( 'd') [0]
bar_desc = self.getText (bar_desc_n.childNodes)
wind_n = current_condition_n.getElementsByTagName ( 'wind') [0]
wind_speed_n = wind_n.getElementsByTagName ( 's') [0]
wind_speed = self.getText (wind_speed_n.childNodes)
wind_gust_n = wind_n.getElementsByTagName ( 'gust') [0]
wind_gusts = self.getText (wind_gust_n.childNodes)
wind_dir_n = wind_n.getElementsByTagName ( 'd') [0]
wind_direction = self.getText (wind_dir_n.childNodes)
humidity_n = current_condition_n.getElementsByTagName ( 'hmid') [0]
humidity = self.getText (humidity_n.childNodes)
moon_n = current_condition_n.getElementsByTagName ( 'moon') [0]
moon_icon_n = moon_n.getElementsByTagName ( 'icon') [0]
moon_icon = self.getText (moon_icon_n.childNodes)
moon_phase_n = moon_n.getElementsByTagName ( 't') [0]
moon_phase = self.getText (moon_phase_n.childNodes)
current_conditions_data = WeatherData (day_of_week, current_temp_feels, current_temp, current_code, current_desc, precip, humidity, wind_direction, wind_speed, wind_gusts, city, sunrise, sunset, moon_phase, moon_icon, bar_read, bar_desc)
self.current_conditions.append (current_conditions_data)

# Collect forecast data
bar_read = u »N / A»
bar_desc = u »N / A»
moon_phase = u »N / A»
moon_icon = u »na»
forecast_n = weather_n.getElementsByTagName ( 'dayf') [0]
day_nodes = forecast_n.getElementsByTagName ( 'day')

for day in day_nodes:
day_of_week = day.getAttribute ( 't')
day_of_year = day.getAttribute ( 'dt')
high_temp_n = day.getElementsByTagName ( 'hi') [0]
high_temp = self.getText (high_temp_n.childNodes)
low_temp_n = day.getElementsByTagName (companyia de baix ') [0]
low_temp = self.getText (low_temp_n.childNodes)

sunrise_n = day.getElementsByTagName ( 'sunr') [0]
sunrise = self.getText (sunrise_n.childNodes)
sunset_n = day.getElementsByTagName ( 'suns') [0]
sunset = self.getText (sunset_n.childNodes)

# Day forecast specific data
daytime_n = day.getElementsByTagName ( 'part') [0] # day
condition_code_n = daytime_n.getElementsByTagName ( 'icon') [0]
condition_code = self.getText (condition_code_n.childNodes)
condition_n = daytime_n.getElementsByTagName ( 't') [0]
condition = self.getText (condition_n.childNodes)
precip_n = daytime_n.getElementsByTagName ( 'PPCP') [0]
precip = self.getText (precip_n.childNodes)
humidity_n = daytime_n.getElementsByTagName ( 'hmid') [0]
humidity = self.getText (humidity_n.childNodes)
wind_n = daytime_n.getElementsByTagName ( 'wind') [0]
wind_speed_n = wind_n.getElementsByTagName ( 's') [0]
wind_speed = self.getText (wind_speed_n.childNodes)
wind_direction_n = wind_n.getElementsByTagName ( 't') [0]
wind_direction = self.getText (wind_direction_n.childNodes)
wind_gusts_n = wind_n.getElementsByTagName ( 'gust') [0]
wind_gusts = self.getText (wind_gusts_n.childNodes)
day_forecast_data = WeatherData (day_of_week, low_temp, high_temp, condition_code, condition, precip, humidity, wind_direction, wind_speed, wind_gusts, city, sunrise, sunset, moon_phase, moon_icon, bar_read, bar_desc)
self.day_forecast.append (day_forecast_data)

# Night forecast specific data
daytime_n = day.getElementsByTagName ( 'part') [1] # night
condition_code_n = daytime_n.getElementsByTagName ( 'icon') [0]
condition_code = self.getText (condition_code_n.childNodes)
condition_n = daytime_n.getElementsByTagName ( 't') [0]
condition = self.getText (condition_n.childNodes)
precip_n = daytime_n.getElementsByTagName ( 'PPCP') [0]
precip = self.getText (precip_n.childNodes)
humidity_n = daytime_n.getElementsByTagName ( 'hmid') [0]
humidity = self.getText (humidity_n.childNodes)
wind_n = daytime_n.getElementsByTagName ( 'wind') [0]
wind_speed_n = wind_n.getElementsByTagName ( 's') [0]
wind_speed = self.getText (wind_speed_n.childNodes)
wind_direction_n = wind_n.getElementsByTagName ( 't') [0]
wind_direction = self.getText (wind_direction_n.childNodes)
wind_gusts_n = wind_n.getElementsByTagName ( 'gust') [0]
wind_gusts = self.getText (wind_gusts_n.childNodes)
night_forecast_data = WeatherData (day_of_week, low_temp, high_temp, condition_code, condition, precip, humidity, wind_direction, wind_speed, wind_gusts, city, sunrise, sunset, moon_phase, moon_icon, bar_read, bar_desc)
self.night_forecast.append (night_forecast_data)

# Pickle the data for next time!
fileoutput = open (file_path_current, 'w')
pickle.dump (self.current_conditions, fileoutput)
fileoutput.close ()

fileoutput = open (file_path_dayforecast, 'w')
pickle.dump (self.day_forecast, fileoutput)
fileoutput.close ()

fileoutput = open (file_path_nightforecast, 'w')
pickle.dump (self.night_forecast, fileoutput)
fileoutput.close ()

excepte:
print «fetchData: Unexpected error:«, sys.exc_info () [0]
print Unable to interrogate the weather data

else: # fetch weather data from pickled class files
if self.options.verbose == True:
print >> sys.stdout, «fetching weather data from file:«, file_path_current

fileinput = open (file_path_current, 'r')
self.current_conditions = pickle.load (fileinput)
fileinput.close ()

if self.options.verbose == True:
print >> sys.stdout, «fetching day forecast data from files:«, file_path_dayforecast, file_path_nightforecast

fileinput = open (file_path_dayforecast, 'r')
self.day_forecast = pickle.load (fileinput)
fileinput.close ()

if self.options.verbose == True:
print >> sys.stdout, «fetching day forecast data from files:«, file_path_nightforecast, file_path_nightforecast

fileinput = open (file_path_nightforecast, 'r')
self.night_forecast = pickle.load (fileinput)
fileinput.close ()

def outputData (self):
#try:

if self.options.template! = None:

output = self.getOutputTextFromTemplate (self.options.template)

en cas contrari:

output = self.getOutputText (self.options.datatype, self.options.startday, self.options.endday, self.options.night, self.options.shortweekday, self.options.imperial, self.options.hideunits, self. options.spaces)

print output.encode ( «utf-8»)

#except:
#print «outputData: Unexpected error:«, sys.exc_info () [0]

if __name__ == «__main__»:

parser = CommandLineParser ()
(Options, args) = parser.parse_args ()

if options.verbose == True:
print >> sys.stdout, «location:», options.location
print >> sys.stdout, «imperial:», options.imperial
print >> sys.stdout, «datatype:», options.datatype
print >> sys.stdout, «night:», options.night
print >> sys.stdout, «start day:», options.startday
print >> sys.stdout, «end day:», options.endday
print >> sys.stdout, «spaces:», options.spaces
print >> sys.stdout, «verbose:», options.verbose
print >> sys.stdout, «refetch:», options.refetch

# Create new global weather object
weather = GlobalWeather (options)
weather.fetchData ()
weather.outputData ()

Creem el fitxer ~ / Conky / scripts / myweather.template

gedit ~ / Conky / scripts / myweather.template

peguem dins el següent:

{-Datatype = DW -startday = 1}: {-datatype = CC -startday = 1}
{-Datatype = HT -startday = 1} / {-datatype = LT -startday = 1} Vent de l'{-datatype = WD -startday = 1} a {-datatype = WS -startday = 1}
Humitat: {-datatype = HM -startday = 1} precipitació: {-datatype = PC -startday = 1}
Sortida de Sol: {-datatype = SR -startday = 1} Ocàs: {-datatype = SS -startday = 1}
——————————————————
{-Datatype = DW -startday = 2}: {-datatype = CC -startday = 2}
{-Datatype = HT -startday = 2} / {-datatype = LT -startday = 2} Vent de l'{-datatype = WD -startday = 2} a {-datatype = WS -startday = 2}
Humitat: {-datatype = HM -startday = 2} precipitació: {-datatype = PC -startday = 2}
Sortida de Sol: {-datatype = SR -startday = 2} Ocàs: {-datatype = SS -startday = 2}
——————————————————
{-Datatype = DW -startday = 3}: {-datatype = CC -startday = 3}
{-Datatype = HT -startday = 3} / {-datatype = LT -startday = 3} Vent de l'{-datatype = WD -startday = 3} a {-datatype = WS -startday = 3}
Humitat: {-datatype = HM -startday = 3} precipitació: {-datatype = PC -startday = 3}
Sortida de Sol: {-datatype = SR -startday = 3} Ocàs: {-datatype = SS -startday = 3}
——————————————————
{-Datatype = DW -startday = 4}: {-datatype = CC -startday = 4}
{-Datatype = HT -startday = 4} / {-datatype = LT -startday = 4} Vent de l'{-datatype = WD -startday = 4} a {-datatype = WS -startday = 4}
Humitat: {-datatype = HM -startday = 4} precipitació: {-datatype = PC -startday = 4}
Sortida de Sol: {-datatype = SR -startday = 4} Ocàs: {-datatype = SS -startday = 4}

Creem el fitxer ~ / Conky / scripts / mail / conkyEmail.py (cal crear la carpeta mail)

gedit ~ / Conky / scripts / mail / conkyEmail.py

i enganxem dins el següent:

import us
import string

#Enter your username and password sota double quotes
# Eg. username = »username» and password = »password»
username = »EL TEU_USUARI_SINARROBA«
password = »TU_CLAU«

com = »wget -O - https: //» + username + »:» + password + »@ mail.google.com / mail / feed / atom -no-check-certificate»

temp = os.popen (com)
msg = temp.read ()
index = string.find (msg, » »)
index2 = string.find (msg, » »)
fc = int (msg [index + 11: index2])

if fc == 0:
print «0 new»
en cas contrari:
print str (fc) + »new»

Asique ara tenes 7 fitxers:

A la carpeta: ~
-> .startconky << - fer executable

A la carpeta: ~ / Conky
-> conkymain
-> conkyforecast
-> conkymail

i en la carpeta: ~ / Conky / scripts
-> conkyForecast.py << - fer executable
-> myweather.template

i en la carpeta: ~ / Conky / scripts / mail
conkyEmail.py << - fer executable

i això és tot, aclariments, on diu / home / usuari / ... va el teu nom d'usuari i en la part on van les dades de Gmail, vaig ressaltar en colors sondi cal posar les teves dades.

per matar el procés de Conky escriu en una consola

killall Conky

per executar Conky escriu en una consola

./.startconky

una vegada que tinguis tot ajustat, si vols que Conky s'iniciï en cada sessió

Sistema-> Preferències-> Sessions i en programes d'inici el afegim

en Nom podem escriure Conky, en Ordre ./.startconky amb això s'iniciarà cada vegada que encenguis la pc.

Això és tot, espero que els serveixi.


Deixa el teu comentari

La seva adreça de correu electrònic no es publicarà. Els camps obligatoris estan marcats amb *

*

*

  1. Responsable de les dades: Miguel Ángel Gatón
  2. Finalitat de les dades: Controlar l'SPAM, gestió de comentaris.
  3. Legitimació: El teu consentiment
  4. Comunicació de les dades: No es comunicaran les dades a tercers excepte per obligació legal.
  5. Emmagatzematge de les dades: Base de dades allotjada en Occentus Networks (UE)
  6. Drets: En qualsevol moment pots limitar, recuperar i esborrar la teva informació.