Pages : 1
#1 Le 06/06/2008, à 18:34
- rOm_08
[Résolu]Météo Conky
Bonsoir,
J'ai intégré a mon Conky la météo avec un script trouver ici http://forum.ubuntu-fr.org/viewtopic.php?id=99471&p=41 celui de fsail.
Je suis allez sur http://www.nws.noaa.gov/tg/siteloc.shtml j'ai choisi Toulouse Blagnac j'obtient ces infos :
WMO Index Number: 07630
ICAO Location Indicator: LFBO
Station Name: Toulouse / Blagnac
Country: France
WMO Region: 6
Station Position: 43-38N 001-22E (dms)
Station Elevation (Ha): 152 Meters
Upper Air Position: 43-38N 001-22E (dms)
Upper Air Elevation (Hp): 153 Meters
Voila le conkyGlobalWeather.py :
#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
###############################################################################
# conkyGlobalWeather.py is a simple python script to gather details of the
# current weather for use in conky, where textual content is only valid.
#
# Author: Kaivalagi
# Dependancies: Python, PyMetar
#
# Usage: conkyGlobalWeather.py StnRef TempUnit WindUnit VisUnit DataType
#
# Where StnRef: EGSH = Norwich, UK
#
# TempUnit: M = Metric (°C)
# I = Imperial (°F)
#
# WindUnit: M = Metric (m/s)
# K = Metric (kph)
# I = Imperial(mph)
#
# VisUnit: M = Metric (kilometers)
# I = Imperial (miles)
#
# DataType: T = Temperature
# W = Wind
# V = Visibility
# S = StationName
# D = Description
# C = Conditions
# H = Humidity
# F = Weather Font Character (Based on Pixmap)
#
# Note: Only one data type should be given at any time
#
# References:
#
# PyMetar: http://www.schwarzvogel.de/software-pymetar.shtml
# Station Ref Lookup: http://www.nws.noaa.gov/tg/siteloc.shtml
#
#
# Example Output: conkyGlobalWeather.py EGSH M I I
#
# Location: Norwich Weather Centre, United Kingdom
# Description: showers in the vicinity; Cumulonimbus clouds observed
# Conditions: partly cloudy
# Temperature: 5 °C
# Wind: No Wind
# Humidity: 80 %
# Visibility: 7 miles
# Pixmap: suncloud
#
import sys, pymetar, textwrap, pickle, os, time, datetime
from stat import *
###############################################################################
# CONSTANTS
USAGE = """
conkyGlobalWeather.py is a simple python script to gather details of the
current weather for use in conky, where textual content is only valid.
Usage: conkyGlobalWeather.py StnRef TempUnit WindUnit VisUnit DataType
Where StnRef: e.g. LFBO -> http://www.nws.noaa.gov/tg/siteloc.shtml
TempUnit: M = Metric (°C)
I = Imperial (°F)
WindUnit: M = Metric (m/s)
K = Metric (kph)
I = Imperial(mph)
VisUnit: M = Metric (kilometers)
I = Imperial (miles)
DataType: T = Temperature
W = Wind
V = Visibility
S = StationName
D = Description
C = Conditions
H = Humidity
F = Weather Font Character (Based on Pixmap)
Note: Only one data type should be given at any time
"""
TEMP_FILEPATH="/tmp/globalweather.pkl"
WRAP_WIDTH = 40
EXPIRY_MINUTES = 90
#StnRef = "LFBO"
#TempUnit = "M" #M=Metric(°C)/I=Imperial(°F)
#WindUnit = "M" #M=Metric(Metres Per Second)/K=Metric(Kilometers Per Hour)/I=Imperial(Miles Per Hour)
#VisUnit = "M" #M=Metric(Kilometers)/I=Imperial(Miles)
###############################################################################
# Functions
def formatSentence(text, capitalise):
# Capitalise the first character
if capitalise == 1:
text = text.capitalize()
# wrap the text to fit the width
text = "\n".join(textwrap.wrap(text,WRAP_WIDTH))
return text
def serializeData(obj, filepath):
fileoutput = open(filepath, 'wb')
pickle.dump(obj, fileoutput)
fileoutput.close()
return
def deserializeData(filepath):
fileinput = open(filepath, 'rb')
obj = pickle.load(fileinput)
fileinput.close()
return obj
# Make calls to PyMetar for details and/or store details away
def FetchData(StnRef):
# does the data need retrieving again?
if os.path.exists(TEMP_FILEPATH):
lastmodDate = time.localtime(os.stat(TEMP_FILEPATH)[ST_MTIME])
expiryDate = (datetime.datetime.today() - datetime.timedelta(minutes=EXPIRY_MINUTES)).timetuple()
if expiryDate > lastmodDate:
RefetchData = True
else:
RefetchData = False
else:
RefetchData = True
# fetch the data, either from Metar or by 'unpickling'
if RefetchData == True:
rf = pymetar.ReportFetcher(StnRef)
re = rf.FetchReport()
rp = pymetar.ReportParser()
pr = rp.ParseReport(re)
serializeData(pr,TEMP_FILEPATH)
else:
pr = deserializeData(TEMP_FILEPATH)
return pr
def OutputData(pr,TempUnit,WindUnit,VisUnit,DataType):
# Temperature
if DataType == "T":
if TempUnit == "M":
OutputText = "%d °C" % int(pr.getTemperatureCelsius())
else:
OutputText = "%d °F" % int(pr.getTemperatureFahrenheit())
# Wind
elif DataType == "W":
WindDirection = pr.getWindCompass()
if WindDirection is None:
OutputText = "No Wind"
else:
if WindUnit == "M":
OutputText = "%d m/s -> %s" % (int(pr.getWindSpeed()),WindDirection)
elif WindUnit == "K":
OutputText = "%d kph -> %s" % (int((pr.getWindSpeed()*3600)/1000),WindDirection)
else:
OutputText = "%d mph -> %s" % (int(pr.getWindSpeedMilesPerHour()),WindDirection)
# Visibility
elif DataType == "V":
if VisUnit == "M":
OutputText = "%d kilometers" % int(pr.getVisibilityKilometers())
else:
OutputText = "%d miles" % int(pr.getVisibilityMiles())
# StationName
elif DataType == "S":
OutputText = pr.getStationName()
# Description
elif DataType == "D":
OutputText = formatSentence(pr.getWeather(),1)
# Conditions
elif DataType == "C":
OutputText = formatSentence(pr.getSkyConditions(),1)
# Humidity
elif DataType == "H":
OutputText = "%d %%" % int(pr.getHumidity())
# Weather Font Character
elif DataType == "F":
Pixmap = pr.getPixmap()
if Pixmap is None:
OutputText = "c"
elif Pixmap == "clear":
OutputText = "A"
elif Pixmap == "sun":
OutputText = "A"
elif Pixmap == "suncloud":
OutputText = "c"
elif Pixmap == "cloud":
OutputText = "e"
elif Pixmap == "rain":
OutputText = "h"
elif Pixmap == "snow":
OutputText = "k"
return OutputText
###############################################################################
# MAIN
if len(sys.argv) < 6:
print "\n",formatSentence(" ERROR: Incorrect number of command line arguments.\n"+USAGE,0)
else:
StnRef = sys.argv[1]
TempUnit = sys.argv[2]
WindUnit = sys.argv[3]
VisUnit = sys.argv[4]
DataType = sys.argv[5]
pr = FetchData(StnRef)
if pr.getTemperatureCelsius() is None:
print "\n",formatSentence(" ERROR: There was a problem obtaining the weather data.\n",0)
else:
text = OutputData(pr,TempUnit,WindUnit,VisUnit,DataType)
if text is None:
print "\n",formatSentence(" ERROR: DataType not set correctly.\n"+USAGE,0)
else:
print text
Ai-je oublier de modifier quelque chose ? je suis perdu lol
Merci.
Dernière modification par rOm_08 (Le 07/06/2008, à 14:26)
Ubuntu Lucid Lynx 10.4 | Asus P5E Deluxe | Core2Quad Q9550 | ATI HD4870 512Mo | 4Go de RAM | Coolermaster Real Power M620 | Hitachi 1To
Hors ligne
#2 Le 06/06/2008, à 21:28
- herberts
Re : [Résolu]Météo Conky
montre ton conkyrc pour voir.
Hors ligne
#3 Le 07/06/2008, à 09:14
- rOm_08
Re : [Résolu]Météo Conky
# Allow each port monitor to track at least this many connections (if 0 or not set, default is 256)
#min_port_monitor_connections 64
#emplacement
alignment top_left
#pour que corky tourne en arriere plan
background yes
#background no #pour les tests
#nombre d'echantillons a utiliser pour calculer la moyenne d'utilisation
cpu_avg_samples 4
net_avg_samples 4
#affiche le texte sur la sortie standard
out_to_console no
# Utiliser Xft (polices lissées etc)
use_xft yes
#police a utiliser : use_xft doit etre a "yes"
xftfont DejaVu Sans Condensed Oblique:size=10
# utiliser sa propre fenetre ?
own_window yes
#type de fenetre : normal(avec le cadre) / override / desktop
own_window_type override
#pseudo transparence?
own_window_transparent yes
# taux de raffraichissement de la fenetre (en secondes)
update_interval 2
# pour eviter le clignotement de la semaine (fonctionne pas chez moi)
double_buffer yes
# afficher les ombres?
draw_shades no
# afficher des contours ?
draw_outline yes
#contours autour des blocs de texte?
draw_borders no
# contour en trait-tillés, longueur d'un trait en pixels
stippled_borders 10
#largeur des marges (n'a pas l'air de fonctionner)
border_margin 20
# largeur du contour
border_width 1
# couleur par defaut du texte, de l'ombre et du contour
default_color black
default_shade_color white
default_outline_color white
# ecart avec le bord x=gauche ou droit y= haut ou bas
gap_x 80
gap_y 50
# Ajoute des espaces apres certains objets pour eviter de les faire bouger.
# Fonctionne uniquement avec la police Monospace
use_spacer no
# Soustraire les mémoires tampons de la mémoire utiliser ?
no_buffers yes
# Tout le texte en majuscule ?
uppercase no
TEXT
${color}
~~{~{ rOm` }~}~~
Nous sommes le ${color}${time %A %d %B %Y} $color Et il est ${color}${time %H:%M:%S} $color
Ubuntu 8.04 Hardy Heron
$sysname $kernel sur $machine $freq_g GHz
Allumé depuis: $uptime$alignr Load: $loadavg
$color$stippled_hr
${color}# Ressources CPU :
Core 1: ${color}${freq cpu1}Mhz $alignr${color}Core 2: ${color}${freq cpu2}Mhz
${color}${cpubar cpu1 5,85} :${cpu cpu1}% $alignr${color}${cpubar cpu2 5,85} :${cpu cpu2}%
${color}# Utilisation mémoire
RAM :${color} $mem/$memmax - $memperc% ${color}${membar}
Swap :${color} $swap/$swapmax - $swapperc% ${color}${swapbar}
$color$stippled_hr
${color}# Qualité du signal : ${alignr}${color}${wireless_link_qual_perc wlan0}${color}%
${color}${wireless_link_bar 6 wlan0}
${color}IP Locale : ${color}${addr wlan0}$alignr${color}
${color}Download :${color} ${downspeed wlan0} k/s${color} ${offset 80}${color}$alignr Upload:${color} ${upspeed wlan0} k/s
${color}Downloaded: ${color}${totaldown wlan0}$alignr ${color} ${color}Uploaded: ${color}${totalup wlan0}
$color$stippled_hr
${color}# Espace Disque :
${color}Linux ${fs_used /}/${fs_size /}${alignr}${fs_used_perc /}%
${color}${fs_bar 6 /}
${color}Données ${fs_used /media/Donnés}/${fs_size /media/Donnés}${alignr}${fs_used_perc /media/Donnés}%
${color}${fs_bar 6 /media/Donnés}
${color}Jeu ${fs_used /media/disk}/${fs_size /media/disk}${alignr}${fs_used_perc /media/disk}%
${color}${fs_bar 6 /media/disk}
${if_mounted /media/ROM`USB}${alignc}Clé Usb : ${color #7b4f94}${fs_used /media/ROM`USB} (${fs_used_perc /media/ROM`USB}%)${color} / ${fs_size /media/ROM`USB}${else}${alignc}Clé Usb : Non montée${endif}
${if_mounted /media/ROM`USB}${alignc}${color #7b4f94}${fs_bar 10,200 /media/ROM`USB}${color}${endif}
${if_mounted /media/IPOD}${alignc}Ipod : ${color #7b4f94}${fs_used /media/IPOD} (${fs_used_perc /media/IPOD}%)${color} / ${fs_size /media/IPOD}${else}${alignc}Ipod : Non montée${endif}
${if_mounted /media/IPOD}${alignc}${color #7b4f94}${fs_bar 10,200 /media/IPOD}${color}${endif}
$color$stippled_hr
${color}# Amarok :
${color}${if_running amarokapp}${color}${execi 10 dcop amarok player artist| fold -s -w 20}${alignr}${color}${execi 10 dcop amarok player title | fold -s -w 50}
${color}${execibar 6 expr `dcop amarok player trackCurrentTime` \* 100 / `dcop amarok player trackTotalTime` }
${color}${else}Non executé$endif
$color$stippled_hr
${color}# Météo
${color}Ville: ${execi 3600 python ~/scripts/conkyGlobalWeather.py LFML M M M S}
Conditions: ${execi 3600 python ~/scripts/conkyGlobalWeather.py LFML M M M C}
Description: ${execi 3600 python ~/scripts/conkyGlobalWeather.py LFML M M M D}
${font Weather:size=36}${execi 3600 python ~/scripts/conkyGlobalWeather.py LFML M M M F}${font}
Température: ${execi 3600 python ~/scripts/conkyGlobalWeather.py LFML M M M T}
Vent: ${execi 3600 python ~/scripts/conkyGlobalWeather.py LFML M K K W}
Visibilité: ${execi 3600 python ~/scripts/conkyGlobalWeather.py LFML M M M V}
Humidité: ${execi 3600 python ~/scripts/conkyGlobalWeather.py LFML M I I H}
Ubuntu Lucid Lynx 10.4 | Asus P5E Deluxe | Core2Quad Q9550 | ATI HD4870 512Mo | 4Go de RAM | Coolermaster Real Power M620 | Hitachi 1To
Hors ligne
#4 Le 07/06/2008, à 11:06
- herberts
Re : [Résolu]Météo Conky
Mais c'est quoi ton problème en fait ? ça s'affiche pas ?
En tout cas, il faut déjà que tu modifie ton conkyrc, parce que la tu n'affichera pas la bonne station.
quand tu appelles le script, tu dois remplacer les LFML par LFBO.
Et as tu penser à installer les dépendances (à savoir python-pymetar)
Dernière modification par herberts (Le 07/06/2008, à 11:12)
Hors ligne
#5 Le 07/06/2008, à 14:25
- rOm_08
Re : [Résolu]Météo Conky
En faite c'était juste LFBO a remplacer dans le conky
Merci beaucoup
Ubuntu Lucid Lynx 10.4 | Asus P5E Deluxe | Core2Quad Q9550 | ATI HD4870 512Mo | 4Go de RAM | Coolermaster Real Power M620 | Hitachi 1To
Hors ligne
#6 Le 07/06/2008, à 15:02
- herberts
Re : [Résolu]Météo Conky
de rien
Hors ligne
#7 Le 10/10/2009, à 00:34
- DuckEater
Re : [Résolu]Météo Conky
J'espère que j's'rai lu malgré le [Résolu]
J'ai voulu appliqué tout ça. Tout fonctionne sauf qu'il m'affiche TOUJOURS Toulouse/blagnac.
Pas un problème en soi, si ce n'est que j'habite Brest :x
${color white}
${color}Ville: ${execi 3600 python ~/Divers/meteo.py LFRB M M M S}
${font Weather:size=36}${execi 3600 python ~/Divers/meteo.py LFRB M M M F}${font}
${font}${execi 3600 python ~/Divers/meteo.py LFRB M M M T}, ${execi 3600 python ~/Divers/meteo.py LFRB M M M D}.
Ça, c'est la partie sur le temps : malgré les codes LFRB (Brest), il affiche toujours Toulouse.
D'où peut venir le problème ?
Merci bein :>
Hors ligne
Pages : 1