SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#26 2013-05-02 17:30:32

ohnonot
...again
Registered: 2012-05-22
Posts: 2,205

Re: Weather Conky - Finnish and International - Ilmatieteen Laitoksen Sää

the "weather now" part depends on a command named hxselect, which comes with a package called html-xml-utils.
i did not state that clearly enough previously.
i just had a hard time myself finding it, trying to use the script under arch linux (html-xml-utils is in the AUR).
also it seems that the minecraft font gets rendered differently under archlinux; i had to set the size to 8 instead of 6, and adjust some voffsets....
future developments: conky in it's own window, forced to the tray with alltray and updating weather icon in the tray. so you don't have to stare at the full forecast all the time  cool

Offline

Be excellent to each other!

#27 2013-07-19 22:37:17

eyemonen
New Member
From: Finland
Registered: 2012-12-11
Posts: 4
Website

Re: Weather Conky - Finnish and International - Ilmatieteen Laitoksen Sää

Offline

#28 2013-10-17 19:30:38

ohnonot
...again
Registered: 2012-05-22
Posts: 2,205

Re: Weather Conky - Finnish and International - Ilmatieteen Laitoksen Sää

Offline

#29 2014-03-05 08:46:51

ohnonot
...again
Registered: 2012-05-22
Posts: 2,205

Re: Weather Conky - Finnish and International - Ilmatieteen Laitoksen Sää

the website has changed its layout some time ago and all the scripts stopped working.
it took me a while to get around to it, but here's a new version.
i think it's quite stable, but has at least one known bug: if your locality has only one weather station, its name is not recognized.
anyway i consider it a beta, a pre-release.
help and collaboration is of course welcome.
see post #1.

Offline

#30 2014-03-06 22:17:31

ohnonot
...again
Registered: 2012-05-22
Posts: 2,205

Re: Weather Conky - Finnish and International - Ilmatieteen Laitoksen Sää

small changes, trying to improve the looks, but also functionality is improved.
fmi provides very fine-grained forecast information and to get more days into less space, i took away one night forecast.

Offline

#31 2014-03-07 19:32:03

ohnonot
...again
Registered: 2012-05-22
Posts: 2,205

Re: Weather Conky - Finnish and International - Ilmatieteen Laitoksen Sää

... and added a hack that recognizes the weather station's name even if there's only one.
there's 3 versions now, one with bitmap fonts, 2 with Droid Sans.
i'm usually just using the pixelfont version with a transparent background, but i'm trying to cater to the masses... of maybe 2 finns on this forum actually interested in this script.
plus a proper README an an alternative download link in post #1 - maybe not everyone is happy with dA.

I consider this the last important update - the one that allows me to not call it a pre-release anymore.

i will try not to bump this thread anymore and rather concentrate on the finnish forums (see post #1).

Last edited by ohnonot (2014-03-07 19:33:58)

Offline

#32 2014-07-02 05:03:05

ohnonot
...again
Registered: 2012-05-22
Posts: 2,205

Re: Weather Conky - Finnish and International - Ilmatieteen Laitoksen Sää

Last edited by ohnonot (2014-07-02 06:23:01)

Offline

#33 2014-07-04 03:25:08

ohnonot
...again
Registered: 2012-05-22
Posts: 2,205

Re: Weather Conky - Finnish and International - Ilmatieteen Laitoksen Sää

omg, i rewrote it again.

i noticed that conky was using too many resources (cpu), with dozens of ${exec sed...} calls with every update and using templates, so i made the shell script produce actual conky syntax, so now it's just a few calls per update.

it's something i had wanted to make for a long time, because it makes conky so fast that i can assign an openbox hotkey to quickly change layouts (e.g. long/short forecast).

whatever, käyttääkö tätä edes joku?

Offline

#34 2014-07-04 11:45:34

nore
>2^9
From: Lakeland
Registered: 2009-11-28
Posts: 740

Re: Weather Conky - Finnish and International - Ilmatieteen Laitoksen Sää

Offline

#35 2014-07-05 07:25:26

ohnonot
...again
Registered: 2012-05-22
Posts: 2,205

Re: Weather Conky - Finnish and International - Ilmatieteen Laitoksen Sää

Last edited by ohnonot (2014-07-05 07:27:02)

Offline

#36 2014-08-17 09:48:54

ohnonot
...again
Registered: 2012-05-22
Posts: 2,205

Re: Weather Conky - Finnish and International - Ilmatieteen Laitoksen Sää

there's been a couple of smaller updates.
just keeping you informed... so if you're one of the select few who've been using this, get the newest version from post #1.
check the changelog.

i also added bigger icons - for some screens 50x50px might be too small.

Offline

#37 2015-01-13 20:50:09

ohnonot
...again
Registered: 2012-05-22
Posts: 2,205

Re: Weather Conky - Finnish and International - Ilmatieteen Laitoksen Sää

some more small updates, cleaning up, bugfixing.
check the first post in this thread.

tried to change the look slightly, but not much...
this one's not exactly a beauty, there's just too much info to be displayed at once.
i might go the interactive (expand on click) conky/lua way some day...

Offline

#38 2015-01-14 07:35:10

ohnonot
...again
Registered: 2012-05-22
Posts: 2,205

Re: Weather Conky - Finnish and International - Ilmatieteen Laitoksen Sää

quite some "ooops" crept into yesterdays version. fixed that now, also updated the READMEs.

Offline

#39 2015-01-15 22:10:46

ohnonot
...again
Registered: 2012-05-22
Posts: 2,205

Re: Weather Conky - Finnish and International - Ilmatieteen Laitoksen Sää

...and again, fixing bugs that popped up while fixing other bugs...
download links in post #1.

Offline

#40 2015-01-23 08:20:15

ohnonot
...again
Registered: 2012-05-22
Posts: 2,205

Re: Weather Conky - Finnish and International - Ilmatieteen Laitoksen Sää

Offline

#41 2015-01-23 17:49:00

nore
>2^9
From: Lakeland
Registered: 2009-11-28
Posts: 740

Re: Weather Conky - Finnish and International - Ilmatieteen Laitoksen Sää

./itl-2015-01-23/itl.sh: 39: ./itl-2015-01-23/itl.sh: Bad substitution
./itl-2015-01-23/itl.sh: 43: ./itl-2015-01-23/itl.sh: [[: not found
./itl-2015-01-23/itl.sh: 54: ./itl-2015-01-23/itl.sh: [[: not found
./itl-2015-01-23/itl.sh: 148: ./itl-2015-01-23/itl.sh: function: not found
cp: tiedoston ”/home/nore/backup/” tilaa ei voi lukea: Tiedostoa tai hakemistoa ei ole
./itl-2015-01-23/itl.sh: 152: ./itl-2015-01-23/itl.sh: Syntax error: "}" unexpected

Offline

#42 2015-01-24 19:57:17

ohnonot
...again
Registered: 2012-05-22
Posts: 2,205

Re: Weather Conky - Finnish and International - Ilmatieteen Laitoksen Sää

Offline

#43 2015-01-24 21:42:51

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Weather Conky - Finnish and International - Ilmatieteen Laitoksen Sää

Offline

#44 2015-01-24 23:07:29

ohnonot
...again
Registered: 2012-05-22
Posts: 2,205

Re: Weather Conky - Finnish and International - Ilmatieteen Laitoksen Sää

thanks for the mention!
getting some attention means i'm going to have to clean up my code...

Offline

#45 2015-01-24 23:19:57

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Weather Conky - Finnish and International - Ilmatieteen Laitoksen Sää

lol  lol  lol LOVE IT!!!!

Offline

#46 2015-01-25 07:42:11

ohnonot
...again
Registered: 2012-05-22
Posts: 2,205

Re: Weather Conky - Finnish and International - Ilmatieteen Laitoksen Sää

thanks.
i know it's not a beauty - design-wise, there is much better stuff floating around - but i'm proud of its functionality.
most customization takes place in the shell script. right now it's a mess, nearly impossible to understand the options. major cleanup required.
but it works.
and the internationalization wasn't so tricky, thanks to the design of the web page.
does it provide proper forecast for your corner of the world?
for finland, i think it's the best.

some feedback on how it works on debian-based systems would be nice.
while testing on crunchbang yesterday i fixed one glitch, it seems that xmllint and/or bash behave differently.

and to nore, i'd really like to get to the bottom of your error. you know how they say, if you could provide a little more info...?

Last edited by ohnonot (2015-01-25 07:47:58)

Offline

#47 2015-01-25 11:33:23

nore
>2^9
From: Lakeland
Registered: 2009-11-28
Posts: 740

Re: Weather Conky - Finnish and International - Ilmatieteen Laitoksen Sää

You have to wait a bit, I'm busy today, but I was running it in Jessie, so the errors might be version related. I'll try it in Waldorf next week.

Offline

#48 2015-01-25 13:41:08

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Weather Conky - Finnish and International - Ilmatieteen Laitoksen Sää

"http://en.ilmatieteenlaitos.fi/weather/argentina/buenos%2520aires"

Offline

#49 2015-01-25 16:21:35

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Weather Conky - Finnish and International - Ilmatieteen Laitoksen Sää

Tmpdir='/tmp/itl'

Offline

Help fund CrunchBang, donate to the project!

#50 2015-01-25 17:22:56

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Weather Conky - Finnish and International - Ilmatieteen Laitoksen Sää

#!/bin/bash

# SORRY FOR THE MESS.
# I HOPE YOUR TEXT EDITOR SUPPORTS SYNTAX HIGHLIGHTING!
# OTHERWISE READING THIS FILE WILL BE MUCH, MUCH HARDER.
# geany IS GENERALLY A GOOD CHOICE. CHOOSE:
# Document => Set Filetype => Scripting => Shell

# This script extracts weather data from ilmatieteenlaitos.fi
# and processes it so that it can be easily read with conky.

################################### SOFTWARE DEPENDENCIES ###
# it depends on html-xml-utils and libxml2 (xmllint)
# (these packages might have slightly different names in your distro)
# it also depends on a few other utilities that are usually already
# installed by default: sed, wget, join, pkill (provided by procps-ng),
# ping (provided by iputils)

# just a meaningless aside: here's a very simple oneliner solution
# to provide fairly readable text-only output:
# w3m -dump -T text/html -cols 100 "http://ilmatieteenlaitos.fi/saa/helsinki"
# (-cols 100 is optional to make output wider)
# try it! can also be used with the "$timerange"-meteogram files that
# are generated in this script.

#############################################################
Debug=1
# when set to 1, MORE debug messages are collected to the "debug"
# file in the conky directory.
DeleteNot=0
# leaves raw and temporary files undeleted when set to 1.
if [[ $Debug = 1 ]] ; then
        MKDIR="mkdir"
        RM="rm"
        rst="" #[0m"
        col=":: " #[35m! "
    else
        MKDIR="mkdir -p"
        RM="rm -f"
fi

##################################################################

# USE BACKUP FUNCTION: SO WE HAVE SOMETHING TO LOOK AT EVEN WITHOUT INTERNET CONNECTION
function UseBackup {
   # CAN WE SAFELY ASSUME THAT, IF $Tmpdir EXISTS,
   # IT CONTAINS USABLE DATA?
   [ -d $Tmpdir ] || cp -r $CurDir/backup/ $Tmpdir
}
# ECHOING DEBUG MESSAGES
function Debugmsg {
  [[ $Debug = 1 ]] && echo -e "$col$@$rst"
}
# DELETE FILES (BUT DON'T DELETE IF WE'RE DEBUGGING)
function Delete {
   [[ $DeleteNot != 1 ]] && $RM "$@"
}

# pass weather URL when calling the script from conky
# helsinki is a failsafe.
if [[ "x$1" == "x" ]] ; then
    URL="http://en.ilmatieteenlaitos.fi/weather/helsinki"
else
    URL="$1"
fi

if echo $URL | grep -q 'en.ilmatieteenlaitos.fi'
then
	Lang="en"
else
	if echo $URL | grep -q 'sv.ilmatieteenlaitos.fi'
	then
		Lang="sv"
	else
		Lang="fi"
	fi
fi
Debugmsg "Language is $Lang"

##################################################################
# SOME COMMON VARIABLES
#
# hex code for non-breaking space. sed will need it sometimes.
Nbsp='\xC2\xA0'
#
#Tmpdir='/tmp/itl'
Tmpdir='/media/5/Conky/ohnonot/itl-2015-01-24/cache'
# change weather image directory names here, so you can have multiple
# icon themes in the script's base directory
# forecast image dir:
FcImgDir="fc-img"
# precipitation bars directory:
PrecBarDir="prec-bar-sharp-corners"
# CURRENT WORKING DIRECTORY, NEEDED FOR SYMLINKS FURTHER DOWN.
CurDir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

################################################################
# CONKY-SPECIFIC VARIABLES
ConkyVar=1
# this means: process conky-specific stuff.
# i never tried to actually set this to 0.
# FIXME?
#
# international weather forecast does not have current conditions.
# for those the final design has to be changed a little, if this
# variable is assigned a value later.
NoStation=""
#
# SET THIS TO 1 WHEN NOT USING XFT WITH CONKY
EncodeISO8859=0
#
# RULE FOR BUILDING THE ROWS OF FORECASTS:
firstshortline=1
# firstshortline can only be 1, which means:
# the first forecast block is from the short range group (lähituntien
# ennuste) which is followed by $midlines lines from the mid range group
# (starting with line 1 of the mid range group)
# if firstshortline is 0 (or in fact anything but 1),
# only $midlines mid range forecasts will be used.
midlines=10
# (SHOULD NOT EXCEED 18 ALTOGETHER)
#
# THESE COLORS ARE USED/DEFINED IN conky-itl
############################## Normal colors
col_ge70='${color4}' # blue
col_lt30='${color2}' # white
############################## Bold colors
col_pos='${color5}'
col_3070='${color3}'
col_neg='${color6}'
#	color and color1 are already in use.
#	color2: whitish (precipitation less than 30%)
#	color3: light blue (precipitation 30%-70%)
#	color4: dark blue  (precipitation more than 70%)
#	color5: dark yellow(ish) for positive temperatures
#	color6: dark cyan for negative temperatures
################################################
# if draw_shades is yes in conky-itlv
dark_shade="\${shadecolor 737373}" # for bold text
light_shade="\${shadecolor 969696}" # for normal text
bold_font="\${font monofur:bold:size=12}"
#
# CONKY TABS AND EXTRA PARAMETERS
# THERE'S 4 COLUMNS (LEFT TO RIGHT):
# Tab1: WIND + WEATHER
# Tab2: PRECIPITATION
# Tab3: TIME + TEMPERATURE
# Tab4: WEEKDAY
Tab1="\${goto 58}"
Extra1="\${color}\${font}"
Tab2="\${goto 150}"
#\${voffset -2}
Extra2="${dark_shade}$bold_font"
Line2Tab2="\${voffset 1}"
Tab3="\${goto 207}"
Extra3="${light_shade}\${color1}$bold_font"
Tab4="\${alignr}"
Extra4=""
# LAST = AT THE VERY END OF THE LINE
Last="\${voffset -5}"
####################################################################################
### FONT CHANGE, LAYOUT MESSED? CHANGING voffset HERE MIGHT PROVIDE A QUICK FIX! ###
####################################################################################
Separator="\${color1}\${hr 1}\${color}"
ForecastSeparator="\${voffset -6}$Separator"
FeelsLikeExtra="\${font} \${color} ${light_shade}\${voffset 9}\${goto 230}"
TempExtra="${dark_shade}\${font monofur:bold:size=12}\${voffset -9}"
#
MaxTextWidth=44
# PSOITIONING OF IMAGES
# FORECAST
FcImgX=3
FcImgYInit=24
# PRECIPITATION BAR
PbImgX=149
PbImgYInit=44
PbImgStretch="42x30" # should always be 30px high
# FEELSLIKE
FlImgX=229
FlImgYInit=50
# SAME Y-INCREMENT FOR ALL IMG
ImgYIncr=53  ## 49

########################################
########## OK, HERE WE GO! #############
########################################

Debugmsg "WILL ATTEMPT TO FETCH WEATHER DATA FOR $URL ..."

if wget -O $CurDir/raw "$URL"
then

  if [ "x$(hxextract div.mid $CurDir/raw)" = "x" ]
  then
	 echo "(EE) HTML document $CurDir/raw
	 (EE) does not contain enough weather data.
	 (EE) Using data from previous fetch. Exiting."
	 rm -f $CurDir/raw
	 exit 1
  fi

  Debugmsg "STOP CONKY NOW"
  pkill -STOP -f 'conky -c conky-itlv'
  # stop conky to avoid wrong output

  if [ -d $Tmpdir ] ; then
	 $RM -r $Tmpdir/*
	 Debugmsg "REMOVING ALL FILES IN $Tmpdir"
  else
	 Debugmsg "CREATING DIRECTORY $Tmpdir "
	 $MKDIR $Tmpdir
  fi

  mv $CurDir/raw $Tmpdir/raw-utf
  # I HAVEN'T FIGURED OUT HOW TO TELL XMLLINT TO USE PROPER UTF-8
  # SO WE CONVERT TO "ASCII"
  xml2asc < $Tmpdir/raw-utf > $Tmpdir/raw-asc

  for timerange in short mid
  do
	 Debugmsg "EXTRACTING TIMERANGE $timerange TO meteogram"
	 #########################################################
	 $MKDIR $Tmpdir/$timerange
	 hxextract div.$timerange $Tmpdir/raw-asc > $Tmpdir/$timerange/meteogram

	 Debugmsg "CREATING days (WEEKDAYS + EMPTY LINES)"
	 #########################################################
	 # THIS BLOCK WILL CREATE A FILE OF WEEKDAYS + EMPTY LINES
	 count=0
	 old_IFS=$IFS      # save the field ForecastSeparator
	 IFS=$'\n'     # new field ForecastSeparator, the end of line
	 for line in $(xmllint --html --xpath '//colgroup/col/@class' $Tmpdir/$timerange/meteogram | sed 's/class=// ; s/class=/\n/g ; s/\"//g')
	 do
		if [[ $line = *first-daily-step* ]]
		   then
			  count=$(( count + 1 ))
			  echo $(xmllint --html --xpath "//thead/tr[1]/td[$count]/div/span/text()" $Tmpdir/$timerange/meteogram) >> $Tmpdir/$timerange/days
		   else echo ' ' >> $Tmpdir/$timerange/days
		fi
	 done
	 IFS=$old_IFS     # restore default field ForecastSeparator
	 # DONE
	 ########################################################

	 Debugmsg "CREATING hours"
	 ########################################################
	 # WE CREATE A SIMILAR FILE FOR HOURS
	 xmllint --html --xpath '//tr[@class="meteogram-times"]/td/div/span/text()' $Tmpdir/$timerange/meteogram | sed "s/../&\n/g" > $Tmpdir/$timerange/hours
	 ########################################################

	 Debugmsg "CREATING weather-txt-daynight, weather-txt-forecast and weather-img "
	 ########################################################
	 # NEXT: WEATHER SYMBOLS - TEXT + IMAGES
	 xmllint --html --xpath '//tr[@class="meteogram-weather-symbols"]/td/div/@title' $Tmpdir/$timerange/meteogram \
	  | hxunent | sed 's/title=// ; s/title=/\n/g ; s/"//g ; s/^ *//g' > $Tmpdir/$timerange/weather-txt
	 sed 's/.*, //g' $Tmpdir/$timerange/weather-txt > $Tmpdir/$timerange/weather-txt-daynight
	 sed 's/,.*//g' $Tmpdir/$timerange/weather-txt > $Tmpdir/$timerange/weather-txt-forecast
	 xmllint --html --xpath '//tr[@class="meteogram-weather-symbols"]/td/div/@class' $Tmpdir/$timerange/meteogram \
	  | sed 's/class=// ; s/class=/\n/g ; s/\"//g ; s/weather-symbol//g ; s/code-//g ; s/ *//g' > $Tmpdir/$timerange/weather-img
	 ########################################################
	 # weather-txt HAS BEEN DIVIDED INTO 2 FILES - WE CAN DELETE IT NOW:
	 Delete $Tmpdir/$timerange/weather-txt

	 Debugmsg "CREATING temp-plusminus, temp-value "
	 ########################################################
	 # TEMPERATURES - ABOVE ZERO OR BELOW
		xmllint --html --xpath '//tr[@class="meteogram-temperatures"]/td/span/@class' $Tmpdir/$timerange/meteogram \
	  | sed 's/class=// ; s/class=/\n/g ; s/\"//g ; s/ *//g' > $Tmpdir/$timerange/temp-plusminus
	 # THEN, ACTUAL TEMPERATURE VALUES
	 xmllint --html --xpath '//tr[@class="meteogram-temperatures"]/td/span/text()' $Tmpdir/$timerange/meteogram \
	  | sed 's/deg;/deg;\n/g' | hxunent > $Tmpdir/$timerange/temp-value
	 ########################################################

	 Debugmsg "CREATING wind-txt "
	 ########################################################
	 # WIND IMAGES + TEXT
	 xmllint --html --xpath '//tr[@class="meteogram-wind-symbols"]/td/div/@title' $Tmpdir/$timerange/meteogram \
	  | sed 's/title=// ; s/title=/\n/g ; s/\"//g ; s/^ *//g' | hxunent > $Tmpdir/$timerange/wind-txt
	 ########################################################

	 Debugmsg "CREATING feelslike-txt "
	 ########################################################
	 # "FEELS LIKE" TEMPERATURES - TEXT + IMAGES (=different color?)
	 xmllint --html --xpath '//tr[@class="meteogram-apparent-temperatures"]/td/div/span/text()' $Tmpdir/$timerange/meteogram \
	  | sed 's/deg;/deg;\n/g'| hxunent > $Tmpdir/$timerange/feelslike-txt
	 ########################################################

	 Debugmsg "CREATING pop-txt, pop-img "
	 ########################################################
	 # POP - PROBABILITY OF PRECIPITATION - TEXT + IMAGES (=different color?)
	 xmllint --html --xpath '//tr[@class="meteogram-probabilities-of-precipitation"]/td/div/@class' $Tmpdir/$timerange/meteogram \
	  | sed 's/class=// ; s/class=/\n/g ; s/\"//g ; s/^ *//g' > $Tmpdir/$timerange/pop-img
	 xmllint --html --xpath '//tr[@class="meteogram-probabilities-of-precipitation"]/td/div/span' $Tmpdir/$timerange/meteogram \
	  | sed 's/<span>// ; s/<span>/\n/g ; s/<\/span>//g ; s/ *//g' | hxunent > $Tmpdir/$timerange/pop-txt
	 ########################################################

	 Debugmsg "CREATING prec-bar "
	 ###############################################################################
	 # THIS BLOCK WILL CREATE A FILE WITH PRECIPITATION BARS + THE RIGHT EMPTY LINES
	 old_IFS=$IFS      # save the field ForecastSeparator
	 IFS=$'\n'     # new field ForecastSeparator, the end of line
	 for line in $(xmllint --html --xpath '//tr[@class="meteogram-hourly-precipitation-bars"]/td' $Tmpdir/$timerange/meteogram | sed 's/<\/td>/<\/td>\n/g' )
	 do
		echo $line | xmllint --html --xpath '//td/div/@style' - | sed 's/style=//g ; s/height//g ; s/[\:\"\; ]*//g' >> $Tmpdir/$timerange/prec-bar
		echo >> $Tmpdir/$timerange/prec-bar
	 done
	 IFS=$old_IFS     # restore default field ForecastSeparator
	 ######################################################
	 # SMALL CORRECTION: EMPTY LINES BECOME "0px" (FOR IMAGE SYMLINKS)
	 sed -i 's/^$/0px/g' $Tmpdir/$timerange/prec-bar
	 ######################################################

	 Debugmsg "CREATING prec-value "
	 ########################################################
	 # CREATE HOURLY PRECIPITATION VALUE FILE
	 xmllint --html --xpath '//tr[@class="meteogram-hourly-precipitation-values"]/td/span/*' $Tmpdir/$timerange/meteogram \
	  | sed 's/<\/[a-z]*>/\n/g ; /^$/!{s/<[^>]*>//g;}' > $Tmpdir/$timerange/prec-value
	 ########################################################
	 Delete $Tmpdir/$timerange/meteogram

	 Debugmsg "done with $timerange\n!"

  done # for timerange in short mid

  #############################################################

  Debugmsg "CREATING COMMON DATA INDEPENDENT OF SHORT AND MID FORECAST\nCREATING Celestial variable (to be appended to finalconkyoutput)"

  # CELESTIAL: SUNRISE/SET
  Celestial="$(hxextract div.celestial-text $Tmpdir/raw-asc | sed 's/<\/[a-z]*>//g ; /^$/!{s/<[^>]*>//g;}' | hxunent)"
  Celestial="$(echo $Celestial | sed 's/^ *//g ; s/Päivän/\nPäivän/g ; s/Dagens/\nDagens/ ; s/Length/\nLength/g ; s/tänään //g ; s/today //g ; s/i dag //g ; s/ on/:/g ; s/ is/:/g ; s/ är/:/g')"

  Debugmsg "CREATING Advisory variable (to be appended to finalconkyoutput)"
  ##########################################
  # ADVISORY: WARNINGS
  Advisory="$(hxextract div.advisory-text $Tmpdir/raw-utf | sed \
  '/^$/!{s/<[^>]*>//g;} ; s/^ *// ; s/ Katso koko Suomen varoitukset »// ; s/ See all warnings »// ; s/ Kolla alla varningar i Finland »//'\
   | fold -s -w $MaxTextWidth)"

  Debugmsg "CREATING observation "
  #######################################
  # CURRENT CONDITIONS - OBSERVATION TEXT
  hxextract table.observation-text $Tmpdir/raw-utf | hxselect -c span | hxselect -c -s '\n' span | \
  sed 's/&Nbsp;/ /g ; /^$/!{s/<[^>]*>//g;} ; s/mm&nbsp;([0-9]\{1,2\}.00)/mm/' | hxunent > $Tmpdir/observation

  Debugmsg "CREATING weather Station variable"
  ###########################################

  # OBSERVATION STATION FOR CURRENT CONDITIONS
  Station=$(xmllint --html --xpath  '//div[@class="station-status"]/form/select/option[@selected="selected"]/text()' $Tmpdir/raw-asc | hxunent )
  # WORKAROUND FOR LOCATIONS THAT HAVE ONLY 1 OBSERVATION STATION
  # (IN WHICH CASE stationtest REMAINS EMPTY):
  if [[ "x$Station" = "x" ]]
  then
	 Station=$( xmllint --html --xpath  '//div[@class="station-status"]/h3[1]/text()' $Tmpdir/raw-asc | sed 's/^.*:// ; s/^\xC2\xA0// ; s/^ *//' | hxunent )
  fi

  Debugmsg "CREATING current conditions ObservationTimestamp Variable"
  ##################################################
  ObservationTimestamp="$(xmllint --html --xpath  '//table[@class="observation-text"]/caption/span[@class="time-stamp"]/text()' $Tmpdir/raw-asc)"
  case "$Lang" in
  "en")
	  ObservationTimestamp="$(echo $ObservationTimestamp | sed 's/local time// ; s/[0-9]\{1,2\} [A-Z][a-z]\{1,2\} [0-9]\{4\}// ; s/\xC2\xA0//g ; s/ //g')"
	  ;;
  "sv")
	  ObservationTimestamp="$(echo $ObservationTimestamp | sed 's/lokal tid// ; s/[0-9]\{1,2\}.[0-9]\{1,2\}.[0-9]\{4\}// ; s/\xC2\xA0//g ; s/ //g')"
	  ;;
  "fi")
	  ObservationTimestamp="$(echo $ObservationTimestamp | sed 's/Suomen aikaa//; s/[0-9]\{1,2\}.[0-9]\{1,2\}.[0-9]\{4\}// ; s/\xC2\xA0//g ; s/ //g')"
	  ;;
  esac

  Debugmsg "CREATING ForecastTimestamp variable"
  ################################################
  ForecastTimestamp="$(cat $Tmpdir/raw-utf | hxselect -c .deterministic | \
  sed "s/Meteorologin e/E/; s/Meteorologist's f/F/; s/Meteorologens p/P/ ; s/[0-9]\{1,2\}.[0-9]\{1,2\}.[0-9]\{4\} //")"
  ##############################################

  Debugmsg "GENERAL FILE PARSING FINISHED"
  #############################################################
  #############################################################

  # CONKY SPECIFIC STUFF
  if [[ $ConkyVar = 1 ]] ; then

	  Debugmsg "NOW STARTING WITH CONKY-SPECIFIC STUFF"

	  ################################################
	  # CONKY-SPECIFIC FOR BOTH TIMERANGES
	  for timerange in short mid
	  do
		  Debugmsg "CONKY-SPECIFIC FOR $timerange"

		  Debugmsg "CREATING symlinks for $timerange forecast images "
		  for (( i=1; i<=18; i++ ))
			  do
			  ln -f -s $CurDir/$FcImgDir/$(sed -n "${i}"p $Tmpdir/$timerange/weather-img).png $Tmpdir/$timerange/.fc${i}.png
			  ln -f -s $CurDir/$PrecBarDir/$(sed -n "${i}"p $Tmpdir/$timerange/prec-bar).png $Tmpdir/$timerange/.pb${i}.png
		  done
		  Delete $Tmpdir/$timerange/weather-img $Tmpdir/$timerange/prec-bar

		  Debugmsg "CREATING LINE1\nPERCENTAGE OF PRECIP: PUTTING IN CONKY-PARSEABLE COLORS"
		  ##################################################################################################
		  sed -i -e "s/ *//g" -e "s/pop-ge-30-lt-70/$col_3070/g" -e "s/pop-ge-70/$col_ge70/g" -e "s/pop-lt-30/$col_lt30/g" $Tmpdir/$timerange/pop-img

		  Debugmsg "PERCENTAGE OF PRECIP: JOINING 2 FILES "
		  ##################################################################################################
		  paste -d '' $Tmpdir/$timerange/pop-img $Tmpdir/$timerange/pop-txt | sed "s/^/$Tab2$Extra2/g" > $Tmpdir/$timerange/pop

		  Debugmsg "PASTE POP AND HOURS AND DAYS TOGETHER => $timerange pophourday "
		  ###########################################################################################
		  case "$Lang" in
		  "en")
			  Debugmsg "This is an English language forecast"
			  Extra4="\${font monofur:size=12}"
			  sed -i "s/$/$Last/g;/^[A-Z][a-z][a-z]/s|^|$Extra4$Tab4|g" $Tmpdir/$timerange/days
			  ;;
		  "sv")
			  Debugmsg "This is a Swedish language forecast"
			  sed -i 's/&auml;/ä/g ; s/&ouml;/ö/g ; s/&uuml;/ü/g ; s/&aring;/å/g' $Tmpdir/$timerange/days
			  sed -i "s/$/$Last/g;/^[a-z,ä,ö,å][a-z,ä,ö,å]/s|^|$Tab4$Extra4|g" $Tmpdir/$timerange/days
			  ;;
		  "fi")
			  Debugmsg "This is a Finnish language forecast"
			  sed -i "s/$/$Last/g;/^[a-z][a-z]/s|^|$Tab4$Extra4|g" $Tmpdir/$timerange/days
			  ;;
		  esac
		  sed "s/$/.00/g ; s/^/$Tab3$Extra3/g" $Tmpdir/$timerange/hours | paste -d '' - $Tmpdir/$timerange/days > $Tmpdir/$timerange/hourday
		  paste -d '' $Tmpdir/$timerange/pop $Tmpdir/$timerange/hourday > $Tmpdir/$timerange/pophourday
		  sed "s/^/$Tab1$Extra1/g" $Tmpdir/$timerange/weather-txt-daynight | paste -d '' - $Tmpdir/$timerange/pophourday > $Tmpdir/$timerange/line1
		  # LINE1 IS READY. DELETE NOW USELESS FILES
		  Delete $Tmpdir/$timerange/hours $Tmpdir/$timerange/days $Tmpdir/$timerange/weather-txt-daynight $Tmpdir/$timerange/pop*

		  Debugmsg "\nCREATING LINE2"
		  #######################################################################
		  sed "s/^/$Tab1$Extra1/g ; s/$/$Line2Tab2/g" $Tmpdir/$timerange/weather-txt-forecast > $Tmpdir/$timerange/line2
		  ####################################################################################

		  Debugmsg "\nCREATING LINE3"
		  ########################################################################
		  Debugmsg "temp-plusminus: putting in conky-parseable colors and pasting it together with temp-value and tempfeel"
		  # REPLACE "positive" AND "negative" WITH CONKY-STYLE COLORS (BLUE AND GREEN)
		  sed "s/positive/$col_pos/g ; s/negative/$col_neg/g" $Tmpdir/$timerange/temp-plusminus \
		  | paste -d '' - $Tmpdir/$timerange/temp-value | sed "s/^/$TempExtra/g" > $Tmpdir/$timerange/temp

		  sed "s/^/$FeelsLikeExtra/" $Tmpdir/$timerange/feelslike-txt | paste -d '' $Tmpdir/$timerange/temp - > $Tmpdir/$timerange/tempfeel
		  sed "s/tuulta//g ; s/.ind //g ; s/lig//g ; s/north/N/g ; s/east/E/g ; s/south/S/g ; s/west/W/g ; s/$/$Tab2/" $Tmpdir/$timerange/wind-txt \
		  | paste -d '' - $Tmpdir/$timerange/prec-value > $Tmpdir/$timerange/windprec
		  sed "s/^/$Tab1/g ; s/$/mm$Tab3/g" $Tmpdir/$timerange/windprec | paste -d '' - $Tmpdir/$timerange/tempfeel > $Tmpdir/$timerange/line3

		  Delete \
		  $Tmpdir/$timerange/temp-* $Tmpdir/$timerange/temp $Tmpdir/$timerange/feelslike-txt $Tmpdir/$timerange/windprec $Tmpdir/$timerange/tempfeel

		  Debugmsg "ALL 3 LINES CREATED\n"

	 done # CONKY-SPECIFIC FOR BOTH TIMERANGES

	 Debugmsg "NOW PUTTING IT ALL TOGETHER"

	 Debugmsg "The language for the header is $LANG"
	 case "$Lang" in
	  "en")
		echo "${Tab1}\${offset -1}Weather/Wind${Tab2}\${offset -1}Rain${Tab3}\${offset -1}Temp" > $Tmpdir/finalconkyoutput
		;;
	  "sv")
	    echo "${Tab1}\${offset -1}Väder/Vind${Tab2}\${offset -1}Regn${Tab3}\${offset -1}Temperatur" > $Tmpdir/finalconkyoutput
	    ;;
	  "fi")
	    echo "${Tab1}\${offset -1}Sää ja Tuuli${Tab2}\${offset -1}Sade${Tab3}\${offset -1}Lämpö" > $Tmpdir/finalconkyoutput
	    ;;
	 esac
	 echo "\${voffset -6}$Separator" >> $Tmpdir/finalconkyoutput

	 Debugmsg "HAVE WE CHOSEN TO USE firstshortline?"
	 if [[ $firstshortline = 1 ]] ; then
		   Debugmsg "YES! BUT WE WILL USE IT ONLY IF IT IS NOT IDENTICAL WITH THE FIRST MID RANGE LINE"

		   if [[ "$(grep -om1 '.*.00' $Tmpdir/short/line1)" != "$(grep -om1 '.*.00' $Tmpdir/mid/line1)" ]] ; then

			  Debugmsg "IT ISN'T! SO: CREATING FIRST LINE = FIRST SHORTRANGE LINE"
			  echo "\${image $Tmpdir/short/.fc1.png -p $FcImgX,$FcImgYInit -n}\${image $Tmpdir/short/.pb1.png -s $PbImgStretch -p $PbImgX,$PbImgYInit -n}\${image img/tk.png -p $FlImgX,$FlImgYInit -n}#"  >> $Tmpdir/finalconkyoutput
			  sed -n 1p $Tmpdir/short/line1 >> $Tmpdir/finalconkyoutput
			  sed -n 1p $Tmpdir/short/line2 >> $Tmpdir/finalconkyoutput
			  sed -n 1p $Tmpdir/short/line3 >> $Tmpdir/finalconkyoutput
			  echo $ForecastSeparator >> $Tmpdir/finalconkyoutput
			  echo "#================================================================" >> $Tmpdir/finalconkyoutput

			  Debugmsg "CREATING SECOND LINE = FIRST MIDRANGE LINE (HAVE TO CHECK FOR WEEKDAY DUPLICATES)"
			  if [[ "$(sed 's/^.*.00//; s/\${[^}]*}//g' $Tmpdir/short/line1 | head -1)" == "$(sed  's/^.*.00//; s/\${[^}]*}//g' $Tmpdir/mid/line1 | head -1)" ]]
			  then
				 Debugmsg "YES, THE WEEKDAY IN THE SECOND LINE IS A DUPLICATE AND SHOULD BE REMOVED"
				 sed -i "1 s/\.00.*$Last/.00$Last/" $Tmpdir/mid/line1
			  else
				 Debugmsg "NOTHING TO DO."
			  fi

		   else
			  Debugmsg "IT IS. ADJUSTING VARIABLES AND CONTINUING"
			  midlines=$(( midlines + 1 ))
			  firstshortline=0
		   fi
	 fi

	 timerange='mid'

	 Debugmsg "PUTTING TOGETHER $midlines MIDRANGE FORECASTS..."
	 for (( line=1; line<=midlines; line++ )) ; do

		helper=$(( ImgYIncr * ( line - 1 + firstshortline ) ))

		echo "\${image $Tmpdir/$timerange/.fc$line.png -p $FcImgX,$(( FcImgYInit + helper )) -n}\${image $Tmpdir/$timerange/.pb$line.png -s $PbImgStretch -p $PbImgX,$(( PbImgYInit + helper )) -n}\${image img/tk.png -p $FlImgX,$(( FlImgYInit + helper )) -n}#"  >> $Tmpdir/finalconkyoutput
		sed -n ${line}p $Tmpdir/$timerange/line1 >> $Tmpdir/finalconkyoutput
		sed -n ${line}p $Tmpdir/$timerange/line2 >> $Tmpdir/finalconkyoutput
		sed -n ${line}p $Tmpdir/$timerange/line3 >> $Tmpdir/finalconkyoutput
		echo $ForecastSeparator >> $Tmpdir/finalconkyoutput
		echo "#================================================================" >> $Tmpdir/finalconkyoutput

	 done

	 # A TEXT FILE WITH THE TIME WHEN THIS WAS FETCHED SUCCESFULLY
	 case "$Lang" in
	 "en")
		Fetched="fetched"
		;;
	 "sv")
	    Fetched="hämtad"
	    ;;
	 "fi")
	    Fetched="haettu"
	    ;;
	 esac
	 ForecastTimestamp="$ForecastTimestamp$Tab4($Fetched $(date +%R))"

	 # It's time to test this now.
	 if [[ $(grep -om1 'class=\"station-status\"' $Tmpdir/raw-asc) == "class=\"station-status\"" ]]
	 then
		NoStation=0
		Debugmsg "We have an observation station to get data from"
		echo -e "$ForecastTimestamp\n\${voffset 6}\${color7}$Advisory\${color} \n$Celestial" >> $Tmpdir/finalconkyoutput
	 else
		NoStation=1
		Debugmsg "There's NO observation station to get data from"
		echo -e "\${color7}$(xmllint --html --xpath  \
		'//h1[@class="local-weather-main-title"]/text()' $Tmpdir/raw-utf 2>/dev/null)\${color} \n\${voffset 6}$Celestial\n\${voffset 6}$ForecastTimestamp"\
		 >> $Tmpdir/finalconkyoutput
	 fi

	 if [[ "$NoStation" == "0" ]]
	 then
		 Debugmsg "APPENDING ObservationTimestamp AND Station TO finalconkyoutput"
		 ##############################################################
		 echo -e "\${voffset -6}$Separator\n\${voffset 3}\${color7}$Station$Tab4$ObservationTimestamp\${color} " >> $Tmpdir/finalconkyoutput

		 Debugmsg "FORMAT CURRENT OBSERVATION INTO A TABLE WITH TABSTOPS"
		 # USING THE HASH '#' AS A MARKER, ONLY TO REMOVE IT WITH sed STRAIGHT AWAY
		 paste -s -d "#\n" $Tmpdir/observation | sed "s/#/$Tab4/" >> $Tmpdir/finalconkyoutput
	 fi

	 Delete $Tmpdir/observation
     Delete $Tmpdir/raw-*


	 if [[ $EncodeISO8859 = 1 ]] ; then
		Debugmsg "CONVERTING finalconkyoutput TO ISO-8859-1 ENCODING (SAME WITH ALL FILES FOR CONKY)"
		##############################################################
		iconv --from-code=UTF-8 --to-code=ISO-8859-1 $Tmpdir/finalconkyoutput > $Tmpdir/finalconkyoutput.tmp
		mv $Tmpdir/finalconkyoutput.tmp $Tmpdir/finalconkyoutput
	 fi

  else # ConkyVar

	Debugmsg "ToDo: if ConkyVar is 0, save to files those values that exist only in variables"

  fi # ConkyVar

  Debugmsg "WE'RE DONE. CONTINUING CONKY"
  ####################################################
  pkill -CONT -f 'conky -c conky-itlv'
  # continue conky

  Debugmsg "DELETING PREVIOUS BACKUP & CREATING NEW"
  $RM -r $CurDir/backup
  cp -r $Tmpdir $CurDir/backup

else # wget

  Debugmsg "COULD NOT FETCH DATA. USING BACKUP FILES."
  $RM $CurDir/raw
  UseBackup
  exit 1

fi # wget

exit 0

Last edited by Sector11 (2015-01-25 17:30:17)

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: bleh

Debian Logo