Re: So much for the weather applet
Posted: Tue Jan 08, 2019 4:36 am
Welcome to the Linux Mint forums!
https://forums.linuxmint.com/
Code: Select all
background false #doesn't seem to make any difference, yes/no, true/false
use_xft yes #anti aliased fonts
xftfont Sans:size=8
xftalpha 1
update_interval 2.0
total_run_times 0
own_window yes
own_window_transparent yes
own_window_type desktop
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
double_buffer yes
minimum_size 0 0
#maximum_width 1000
draw_shades no
draw_outline no
draw_borders no
stippled_borders 0
default_color white
default_shade_color grey
default_outline_color white
alignment top_middle
no_buffers yes
uppercase no
override_utf8_locale no
text_buffer_size 4096
default_outline_color black
default_shade_color black
gap_y 0
gap_x 0
##############################################
# Output
##############################################
TEXT
${execpi 3600 python /home/andy/.conky/UKweather.py}
Code: Select all
#! usr/bin/python2
#------------
#Dependencies
#------------
import metoffer, datetime
"""
datetime is 'built-in' to python , metoffer.py has to be downloaded and
installed from https://pypi.python.org/pypi/MetOffer, it parses UK met office
data in json format.
"""
#---------------------------------
# Function BST (BritishSummerTime)
#---------------------------------
"""
Met office data is returned in zulu = GMT, BST is 1 hr ahead and
times in forecasts during BST need to be adjusted
Year Clocks go forward Clocks go back
2016 27 March 30 October
2017 26 March 29 October
2018 25 March 28 October
2019 31 March 27 October
2020 29 March 25 October
2021 28 March 31 October
2022 27 March 30 October
Forward last Sunday in March, back last Sunday in October
clocks change at 2am.
Output - the function returns 1 = 1hr if adate is during BST, 0 otherwise
Dependencies - datetime module
"""
def BST(adate):
back2016 = datetime.datetime(2016,10,30,2)
forward2017 = datetime.datetime(2017,3,26,2)
back2017 = datetime.datetime(2017,10,29,2)
forward2018 = datetime.datetime(2018,3,25,2)
back2018 = datetime.datetime(2018,10,28,2)
forward2019 = datetime.datetime(2018,3,31,2)
back2019 = datetime.datetime(2019,10,27,2)
if adate < back2016:
return 1
else:
if adate < forward2017:
return 0
else:
if adate < back2017:
return 1
else:
if adate < forward2018:
return 0
else:
if adate < back2018:
return 1
else:
if adate < forward2019:
return 0
else:
if adate < back2019:
return 1
else:
return 0
#end function---------------------------------------------------------------
#-------------------
#Function TempColour
#-------------------
"""
Changes the colour of the temperature display dependent on temperature. Conky dependent
in that returns are formatted for conky.
Parameters passed:
aTemp = a tempature such as "20"
colour = colour will be reset to this on return, so typically the starting
colour before the function is used and is in the format ${color xxxx}
Note colour codes used are X11 as defined by https://en.wikipedia.org/wiki/X11_color_names
"""
def TColour(aTemp,colour):
vHot = "${color red}"
Hot = "${color orange red}"
Warm = "${color gold}"
Average = "${color web green}"
Cold = "${color blue}"
Freezing = "${color white}"
#change the above to suit
temp = int(aTemp)
if temp <= 0:
return Freezing + aTemp + colour
else:
if temp <= 10:
return Cold + aTemp + colour
else:
if temp <= 15:
return Average + aTemp + colour
else:
if temp <= 20:
return Warm + aTemp + colour
else:
if temp < 25:
return Hot + aTemp + colour
else:
return vHot + aTemp + colour
#end function---------------------------------------------------------------
#-------------
#Weather codes
#-------------
TIME = '$'
TEMP = 'T'
WEATHER = 'W'
RAIN = 'Pp'
"""
There are others, these are ones used in my forecast, for other codes see
{SiteRep: {Wx: {Param:}}} in returned forecast.
Weather codes below see http://www.metoffice.gov.uk/datapoint/support/documentation/code-definitions
Weather types
Value Description
NA Not available
0 Clear night
1 Sunny day
2 Partly cloudy (night)
3 Partly cloudy (day)
4 Not used
5 Mist
6 Fog
7 Cloudy
8 Overcast
9 Light rain shower (night)
10 Light rain shower (day)
11 Drizzle
12 Light rain
13 Heavy rain shower (night)
14 Heavy rain shower (day)
15 Heavy rain
16 Sleet shower (night)
17 Sleet shower (day)
18 Sleet
19 Hail shower (night)
20 Hail shower (day)
21 Hail
22 Light snow shower (night)
23 Light snow shower (day)
24 Light snow
25 Heavy snow shower (night)
26 Heavy snow shower (day)
27 Heavy snow
28 Thunder shower (night)
29 Thunder shower (day)
30 Thunder
"""
#----------------------
#Site/personal specific
#----------------------
api_key = 'replace with your own'
mysite = 'numeric in the form 999999 for many sites in the UK'
Location = "Anytown anywherel"
#----------------------------------------------
#Lists that will be populated with weather data
#----------------------------------------------
TimeDay = [] #For today = time, future days = Mon, Tue etc.
Temperature = [] #Always in deg C
Precip = [] #Probability of rain/sleet/snow as a %
WeatherCode = [] #As defined by weather types to get a # to use in a filename to
#point to an icon
#-------------------------------
#Get Met Office forecast in json
#-------------------------------
M = metoffer.MetOffer(api_key)
"""
You can have three hourly or daily, but not hourly
if you want hourly you have to parse the hmtl output from the web pages,
a much bigger task
"""
x = M.loc_forecast(mysite, metoffer.THREE_HOURLY)
myperiod = x["SiteRep"]["DV"]["Location"]["Period"]
totalforecasts = len(myperiod)
#-----
#Today
#-----
Today = datetime.datetime.now()
Day = Today.strftime('%d')
Wday = Today.strftime('%a')
Month = Today.strftime('%b')
TimeNow = Today.strftime('%H') + Today.strftime('%M')
TimeNow = int(TimeNow)
#----------------
#Today's forecast
#----------------
todayforecast = myperiod[0].get("Rep")
#---------------
#Today's weather
#---------------
for k in range(len(todayforecast)):
#--------
#Get time
#--------
ptime = str(int(todayforecast[k].get(TIME,0))/60 + BST(datetime.datetime.now()))
if TimeNow - 300 < int(ptime) * 100: #dump the forecast, it's history, 300 = 3hrly forecast
#-----------
#Get weather
#-----------
pcode = int((todayforecast[k].get(WEATHER,0)))
ptemp = todayforecast[k].get(TEMP,0)
prain = todayforecast[k].get(RAIN,0)
#----------
#Parse time
#----------
if len(ptime) == 1:
ptime = "0" + ptime #now time is 2 digits, eg 07
TimeDay.append(ptime)
#----------------
#Get weather code
#----------------
WeatherCode.append(str(pcode))
#-----------------
#Parse temperature
#-----------------
ptemp = ptemp
Temperature.append(ptemp)
#-------------------
#Parse precipitation
#-------------------
prain = prain
Precip.append(prain)
#-------------------------------------------
#Future forecast - Get forecast for each day
#-------------------------------------------
for j in range(1, totalforecasts): #range from 1 because 0=today
#--------------------
#Get days of the week
#--------------------
days = myperiod[j].get('value',0)
wday = datetime.datetime(int(days[0:4]),int(days[5:7]),int(days[8:10])).strftime('%a')
TimeDay.append(wday)
#initialise variables
AMweather = 0
PMweather = 0
description = ""
Htemp = 0
Ltemp = 100
AMrain = 0
PMrain = 0
ftemp = ""
rain = ""
#-------------------------------------------------
#Get forecast for each time slot in the future day
#-------------------------------------------------
for k in range(len(myperiod[j].get("Rep"))):
ptime = myperiod[j].get("Rep")[k].get(TIME,0)
pcode = int(myperiod[j].get("Rep")[k].get(WEATHER,0))
ptemp = int(myperiod[j].get("Rep")[k].get(TEMP,0))
prain = myperiod[j].get("Rep")[k].get(RAIN,0)
#-------------------------------------------------------
#Parse time - we only need the time to check if AM or PM
#-------------------------------------------------------
ptime = int(ptime)/60*100 + BST(datetime.datetime(int(days[0:4]),int(days[5:7]),int(days[8:10])))
#----------------------------------------------------------
#Parse weather - want worst weather AM & PM = highest pcode
#----------------------------------------------------------
if ptime >= 600 and ptime < 1200: #morning forecast 6am to noon
if pcode > AMweather:
AMweather = pcode
if ptime >= 1200 and ptime < 2000 : #afternoon forecast noon to 8pm
if pcode > PMweather:
PMweather = pcode
#--------------------------------
#Parse temp - want highs and lows
#--------------------------------
if ptemp > Htemp:
Htemp = ptemp
if ptemp < Ltemp:
Ltemp = ptemp
#-------------------------------
#Parse rain - want worst AM & PM
#-------------------------------
if ptime >= 600 and ptime < 1200: #morning forecast 6am to noon
if int(prain) > AMrain:
AMrain = int(prain)
if ptime >= 1200 and ptime < 2000 : #afternoon forecast noon to 8pm
if int(prain) > PMrain:
PMrain = int(prain)
#----------------------------------
#Assemble forecast for a future day
#----------------------------------
#Weather
WeatherCode.append(str(AMweather) +"/" + str(PMweather))
#Temperature
temp = str(Ltemp) + "/" + str(Htemp)
Temperature.append(temp)
#Rain
rain = rain + str(AMrain) + "/" + str(PMrain)
Precip.append(rain)
#----------------------
#Output future forecast
#----------------------
#conky outputs - each will be a string formatted with font, offsets, colour, etc.
ConkyTime = "" #time today
ConkyMins = "" #minutes, always 00 but needs populating with offsets
ConkyTicon = "" #icons for today's weather
ConkyTempT = "" #temp in C for today
ConkyRainT = "" #prob of precip in % for today
ConkyDay = "" #future days of the week
ConkyAMicon = "" #icons for AM in future days
ConkyPMicon = "" #icons for PM in future days
ConkyTempMin = "" #min temp in future days
ConkyLow = "" #Always "lo"
ConkyHigh = "" #Always "hi"
ConkyAM = "" #Always "am"
ConkyPM = "" #Always "pm"
ConkyTempMax = "" #max temp in future days
ConkyRainAM = "" #worst prob of precip in future days morning
ConkyRainPM = "" #worst prob of precip in future days afternoon
width = 125
Vreset = "${voffset 0}" #add to each line of output
#-------------
#Icon settings
#-------------
IconFolder = "/home/andy/.conky/weathericons/w"
IconSuffix = ".png"
IconToffset = 15 #vertical offset for todays icons
IconAMoffset = 70 #vertical offset for AM forecasts for future days
IconPMoffset = 60 #vertical offset for PM forecasts for future days
IconHoffset = 35 #horizontal offset for today & AM forecasts to get right of time
IconHPMoffset = 65 #horizontal offset for PM forecasts to get right of AM forecast
#-----------------
#Time/day settings
#-----------------
TmVoffset = "${voffset -8}" #vertical offset for time in hrs
Mins = "00"
MinVoffset = "${voffset -18}" #vertical offset for minutes
MinHoffset = 26 #horizonatal offset for mins
DayVoffset = "${voffset 0}" #vertical offset for day, eg Wed
#-----------
#Temperature
#-----------
deg = "c" #would like to get the deg symbol in, tried, failed
TempVoffset = "${voffset -30}" #vertical offset for today's temperature, was -20
TempHoffset = 85 #horizonatal offset for today's temperature
MinTempVoffset = "${voffset -19}" #vertical offset for future min temp
MinTempHoffset = 55 #horizontal offset for future days min temp
Low = "lo"
High = "hi"
LowHoffset = 45 #horizontal offset for 'lo' against min temp
LowVoffset = "${voffset 0}"
MaxTempVoffset = "${voffset -20}" #vertical offset for future max temp, was -20
MaxTempHoffset = 55 #horizonatal offset for future days max temp
HighHoffset = 45 #horizontal offset for 'high' against max temp
HighVoffset = "${voffset -10}"
#-------------
#Precipitation
#-------------
#0
RainVoffset = "${voffset 0}" #vertical offset for today's rain
RainHoffset = 85 #horizonatal offset for today's rain
#45
RainAMVoffset = "${voffset -45}" #vertical offset for future days AM rain, was 40
RainAMHoffset = 50 #horizonatal offset for future days AM rain
RainPMVoffset = "${voffset 25}" #vertical offset for future days PM rain
RainPMHoffset = 85 #horizonatal offset for future days PM rain
#-------------
#Font settings
#-------------
font = "${font Sans:regular:size=10}" #everything else & default
font1 = "${font Sans:bold:size=12}" #used for hours
font2 = "${font Sans:regular:size=7}" #used for mins
font3 = "${font Sans:bold:size=12}" #used for location
#---------------
#Colour settings
#---------------
colour0 = "${color dark slate gray}" #default colour
Tforecasts = 0
for k in range (0, len(TimeDay)): #all weather lists have same length
if len(TimeDay[k]) == 2: #len = 2 is time, 3 = day of week
Tforecasts = Tforecasts + 1 #need to know how many to get hoffset right for future days
#Icons for the weather
Iconfile = IconFolder + WeatherCode[k] + IconSuffix
ix = IconHoffset + width * k
ConkyTicon = ConkyTicon + "${image " + Iconfile + " -p " + str(ix) + "," + str(IconToffset) + "}"
#Time as two digits
tx = "${goto " + str(width * k) + "}"
ConkyTime = ConkyTime + tx + TimeDay[k]
#Minutes always "00"
mx = "${goto " + str(MinHoffset + width * k) + "}"
ConkyMins = ConkyMins + mx + Mins
#Temperature
tpx = "${goto " + str(TempHoffset + width * k) + "}"
ConkyTempT = ConkyTempT + tpx + TColour(Temperature[k],colour0) + deg
#Rain - use same offsets as temp
rx = "${goto " + str(RainHoffset + width * k) + "}"
ConkyRainT = ConkyRainT + rx + Precip[k] + "%"
else: #tomorrow and beyond
#Icons for the weather - morning
ic = WeatherCode[k][0:WeatherCode[k].find("/")]
Iconfile = IconFolder + ic + IconSuffix
ix = IconHoffset + width * (k - Tforecasts)
ConkyAMicon = ConkyAMicon + "${image " + Iconfile + " -p " + str(ix) + "," + str(IconAMoffset) + "}"
#Icons for the weather - afternoon
ic = WeatherCode[k][WeatherCode[k].find("/") + 1:len(WeatherCode[k])]
Iconfile = IconFolder + ic + IconSuffix
ix = IconHPMoffset + width * (k - Tforecasts)
ConkyPMicon = ConkyPMicon + "${image " + Iconfile + " -p " + str(ix) + "," + str(IconPMoffset) + "}"
#Day of the week
tx = "${goto " + str(width * (k - Tforecasts)) + "}"
ConkyDay = ConkyDay + tx + TimeDay[k]
#Min temperature
it = Temperature[k][0:Temperature[k].find("/")]
tpx = "${goto " + str(MinTempHoffset + width * (k - Tforecasts)) + "}"
ConkyTempMin = ConkyTempMin + tpx + TColour(it,colour0) + deg
#Add in "Low"
tpx = "${goto " + str(LowHoffset + width * (k - Tforecasts)) + "}"
ConkyLow = ConkyLow + tpx + Low
#Max temperature
it = Temperature[k][Temperature[k].find("/") + 1:len(Temperature[k])]
tpx = "${goto " + str(MaxTempHoffset + width * (k - Tforecasts)) + "}"
ConkyTempMax = ConkyTempMax + tpx + TColour(it,colour0) + deg
#Add in "High"
tpx = "${goto " + str(HighHoffset + width * (k - Tforecasts)) + "}"
ConkyHigh = ConkyHigh + tpx + High
#Rain - morning
rx = "${goto " + str(RainAMHoffset + width * (k - Tforecasts)) + "}"
it = Precip[k][0:Precip[k].find("/")]
ConkyRainAM = ConkyRainAM + rx + it + "%"
rx = "${goto " + str(RainPMHoffset + width * (k - Tforecasts)) + "}"
ixt = Precip[k][Precip[k].find("/") + 1:len(Precip[k])]
ConkyRainPM = ConkyRainPM + rx + ixt + "%"
#---------------------
#Send outputs to Conky
#---------------------
print colour0 + font3 + Location + " ${hr 2}" + font #Location plus a horizontal line
#today's forecast
print ConkyTicon #Weather icons for today
print TmVoffset + font1 + ConkyTime + font + Vreset #Time slots for today in hrs
print MinVoffset + font2 + ConkyMins + font + Vreset #Time slots add in mins = 00
print TempVoffset + font + ConkyTempT + font + Vreset #Time slot temperature
print RainVoffset + font + ConkyRainT + font + Vreset #Time slot prob of precip %
#future days
print ConkyAMicon #Future days AM weather icons
print ConkyPMicon #Future days PM weather icons
print DayVoffset + font1 + ConkyDay + font + Vreset #Day of the week, e.g. Mon
print RainAMVoffset + font + ConkyRainAM + font + Vreset #Future days prob of rain AM max %
print RainPMVoffset + font + ConkyRainPM + font + Vreset #Future days prob of rain PM max %
print HighVoffset + font2 + ConkyHigh + font + Vreset #Future days print hi for temp
print MaxTempVoffset + font + ConkyTempMax + font + Vreset #Future days max temp
print LowVoffset + font2 + ConkyLow + font + Vreset #Future days print lo for temp
print MinTempVoffset + font + ConkyTempMin + font + Vreset #Future days min temp
also running brave beta and this and love it since brave doesn't like to play nice with flash so no yoweather.DAMIEN1307 wrote: ↑Mon Jan 07, 2019 4:07 pmfor what its worth, this is the weather ext. i use in my chromium based "brave browser"...its probably the best ive used yet...wouldnt hurt to try it...DAMIEN
https://chrome.google.com/webstore/deta ... ddahbeiglb
https://weatherextension.com/
curl wttr.in/mtl
Code: Select all
inxi -wxxx
i may try your code. you're right i don't post conky configs unless i give a disclaimer. "it works on my system but may not work on yours" on top of that i still use the old conky, never learned to code the new one. if i get a conky from someone, it's up to me to fix it so that my system is able to use it
shame YAKPOO! doesn't go down altogether as in their main offices going up in a massive explosion AFTER being completely evacuated though. i say this cause they are the worst of the worst in violating peeps right to privacy.
Thanks for the chromium extension. That'll do for me - at least for now!DAMIEN1307 wrote: ↑Mon Jan 07, 2019 4:07 pmfor what its worth, this is the weather ext. i use in my chromium based "brave browser"...its probably the best ive used yet...wouldnt hurt to try it...DAMIEN
https://chrome.google.com/webstore/deta ... ddahbeiglb
https://weatherextension.com/
mockturtle wrote:I won't have time to fix this in the foreseeable future. I'd be happy to see it adopted by the Mint team, or whoever is interested in maintenance.
I'm using the bbcwx@oak-wood.co.uk desklet (with OpenWeatherMap) as an alternative.