summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2018-03-08 12:00:12 +0100
committerBastien Nocera <hadess@hadess.net>2018-03-09 12:10:37 +0100
commit8ff27e6f2653c91261eda6b8ffb17115c8067598 (patch)
tree9a5e041b60a3793eee47ace872503f4b8f47ee35
parent7a313a8b372064a22bd40e82533fe4e9a387d75b (diff)
downloadlibgweather-8ff27e6f2653c91261eda6b8ffb17115c8067598.tar.gz
data: Add temporary script to move <location>s
Move <location>s to the administrative division above, be it <state> or <country> so that weather stations can be shared between multiple cities without the need to duplicate them. We can then use this to list major cities, and available airports/weather stations, without having to associate them too closely. https://bugzilla.gnome.org/show_bug.cgi?id=792328
-rw-r--r--data/locations-flatten.xsl32
-rw-r--r--data/locations-reorder.xsl42
-rwxr-xr-xdata/locations-to-country.sh10
3 files changed, 84 insertions, 0 deletions
diff --git a/data/locations-flatten.xsl b/data/locations-flatten.xsl
new file mode 100644
index 0000000..3eab604
--- /dev/null
+++ b/data/locations-flatten.xsl
@@ -0,0 +1,32 @@
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xsl:output indent="yes" encoding="utf-8" doctype-system="locations.dtd"/>
+ <xsl:strip-space elements="*"/>
+ <xsl:preserve-space elements="timezone"/>
+
+<!-- TODO:
+ - move locations to the top of their container, so
+ <state>
+ <location/>
+ <city/>
+ </state>
+
+ - de-duplicate locations
+ - don't rewrite <timezone id="Africa/Algiers" /> to
+ <timezone id="Africa/Algiers"/>
+-->
+
+ <xsl:template match="node()|@*">
+ <xsl:copy>
+ <xsl:apply-templates select="node()|@*"/>
+ </xsl:copy>
+ </xsl:template>
+
+ <xsl:template match="city[location]">
+ <xsl:apply-templates select="location"/>
+ <xsl:copy>
+ <xsl:apply-templates select="node()[not(self::location)]|@*"/>
+ </xsl:copy>
+ </xsl:template>
+
+</xsl:stylesheet>
diff --git a/data/locations-reorder.xsl b/data/locations-reorder.xsl
new file mode 100644
index 0000000..fdfc180
--- /dev/null
+++ b/data/locations-reorder.xsl
@@ -0,0 +1,42 @@
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xsl:output indent="yes" encoding="utf-8" doctype-system="locations.dtd"/>
+ <xsl:strip-space elements="*"/>
+ <xsl:preserve-space elements="timezone"/>
+
+ <xsl:template match="node()|@*">
+ <xsl:copy>
+ <xsl:apply-templates select="node()|@*"/>
+ </xsl:copy>
+ </xsl:template>
+
+ <xsl:template match="country">
+ <xsl:copy>
+ <xsl:apply-templates select="comment()[following-sibling::_name]"/>
+ <xsl:apply-templates select="_name"/>
+ <xsl:apply-templates select="comment()[not(following-sibling::_name)]"/>
+ <xsl:apply-templates select="iso-code"/>
+ <xsl:apply-templates select="fips-code"/>
+ <xsl:apply-templates select="timezones"/>
+ <xsl:apply-templates select="tz-hint"/>
+ <xsl:apply-templates select="location"/>
+ <xsl:apply-templates select="state"/>
+ <xsl:apply-templates select="city"/>
+ </xsl:copy>
+ </xsl:template>
+
+ <xsl:template match="state">
+ <xsl:copy>
+ <xsl:apply-templates select="comment()[following-sibling::_name]"/>
+ <xsl:apply-templates select="_name"/>
+ <xsl:apply-templates select="comment()[not(following-sibling::_name)]"/>
+ <xsl:apply-templates select="iso-code"/>
+ <xsl:apply-templates select="fips-code"/>
+ <xsl:apply-templates select="timezones"/>
+ <xsl:apply-templates select="tz-hint"/>
+ <xsl:apply-templates select="location"/>
+ <xsl:apply-templates select="city"/>
+ </xsl:copy>
+ </xsl:template>
+
+</xsl:stylesheet>
diff --git a/data/locations-to-country.sh b/data/locations-to-country.sh
new file mode 100755
index 0000000..632d468
--- /dev/null
+++ b/data/locations-to-country.sh
@@ -0,0 +1,10 @@
+#!/bin/sh -e
+
+
+git checkout Locations.xml
+TMPFILE=`mktemp`
+
+xsltproc --path `pwd` locations-flatten.xsl Locations.xml > $TMPFILE && \
+ xsltproc --path `pwd` locations-reorder.xsl $TMPFILE | \
+ sed 's,"/>," />,' | \
+ sed 's, <!-- Could not find information about the following stations:,<!-- Could not find information about the following stations:,' > Locations.xml