User:Kuratkoo/Skript Veřejná hromadná doprava v ČR

From OpenStreetMap Wiki
Jump to navigation Jump to search

Generovaní stránky Cs:Veřejná hromadná doprava v ČR

Pustíme skript ids.sh:

 sh ids.sh

Použité skripty:

ids.sh

#!/bin/sh
wget -q http://download.geofabrik.de/europe/czech-republic-latest.osm.bz2
bunzip2 czech-republic-latest.osm.bz2
osmosis -q --read-xml czech-republic-latest.osm --tag-filter accept-relations route=tram,bus,train,subway,trolleybus --tag-filter reject-ways --tag-filter reject-nodes --write-xml ids.osm
xsltproc xsl.xsl ids.osm | awk -f relan.awk > output.txt

xsl.xsl

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<!-- Global template -->
	<xsl:template match="/osm">
		<xsl:text>== Linky v ČR ==
Níže uvedené tabulky se generují ručně pomocí [https://wiki.openstreetmap.org/wiki/User:Kuratkoo/Skript_Veřejná_hromadná_doprava_v_ČR skriptu]

Data OSM ke dni D. M. YYYY.

</xsl:text>
		<xsl:apply-templates select="relation[(tag/@v = 'tram' or tag/@v = 'train' or tag/@v = 'bus' or tag/@v = 'trolleybus' or tag/@v = 'subway') and tag[@k = 'network']]" mode="all">
			<xsl:sort select="tag[@k='network']/@v" data-type="text" order="ascending"/>
		</xsl:apply-templates>
		<xsl:text>=== Ostatní ===
</xsl:text>
		<xsl:apply-templates select="relation[not(tag[@k = 'network']/@v)]" mode="network">
			<xsl:with-param name="network" />
			<xsl:sort select="tag[@k='operator']/@v" data-type="text" order="ascending"/>
		</xsl:apply-templates>
		<xsl:text>

[[Category:Cs:Česká dokumentace|Verejna hromadna doprava v CR]]
</xsl:text>
	</xsl:template>

	<xsl:template match="relation" mode="all">
		<xsl:if test="current()[not(tag[@k = 'network']/@v = preceding-sibling::relation/tag[@k = 'network']/@v)]/tag[@k = 'network']/@v">
			<xsl:text>
=== </xsl:text><xsl:value-of select="tag[@k = 'network']/@v" /><xsl:text> ===
</xsl:text>
			<xsl:variable name='network' select="tag[@k = 'network']/@v" />

			<xsl:apply-templates select="../relation[tag[@k = 'network']/@v = $network]" mode="network">
				<xsl:with-param name="network"><xsl:value-of select="tag[@k = 'network']/@v" /></xsl:with-param>
				<xsl:sort select="tag[@k='operator']/@v" data-type="text" order="ascending"/>
			</xsl:apply-templates>

		</xsl:if>
	</xsl:template>

	<xsl:template match="relation" mode="network">
		<xsl:param name="network" />
		<xsl:if test="current()[not(tag[@k = 'operator']/@v = preceding-sibling::relation/tag[@k = 'operator']/@v)]/tag[@k = 'operator']/@v">
			<xsl:text>==== </xsl:text><xsl:value-of select="tag[@k = 'operator']/@v" /><xsl:text> ====
</xsl:text>
			<xsl:variable name='operator' select="tag[@k = 'operator']/@v" />
			<xsl:apply-templates select="../relation[tag[@k = 'operator']/@v = $operator]" mode="operator">
				<xsl:with-param name="network"><xsl:value-of select="$network" /></xsl:with-param>
				<xsl:with-param name="operator"><xsl:value-of select="$operator" /></xsl:with-param>
				<xsl:sort select="tag[@k='route']/@v" data-type="text" order="ascending"/>
			</xsl:apply-templates>
		</xsl:if>
	</xsl:template>

	<xsl:template match="relation" mode="operator">
		<xsl:param name="network" />
		<xsl:param name="operator" />
		<xsl:if test="current()[not(tag[@k = 'route']/@v = preceding-sibling::relation[tag[@k = 'operator']/@v = $operator]/tag[@k = 'route']/@v)]">
			<xsl:choose>
				<xsl:when test="tag[@k = 'route']/@v = 'bus'">
					<xsl:text>===== Autobusy =====
</xsl:text>
				</xsl:when>
				<xsl:when test="tag[@k = 'route']/@v = 'train'">
					<xsl:text>===== Vlaky =====
</xsl:text>
				</xsl:when>
				<xsl:when test="tag[@k = 'route']/@v = 'tram'">
					<xsl:text>===== Tramvaje =====
</xsl:text>
				</xsl:when>
				<xsl:when test="tag[@k = 'route']/@v = 'trolleybus'">
					<xsl:text>===== Trolejbusy =====
</xsl:text>
				</xsl:when>
				<xsl:when test="tag[@k = 'route']/@v = 'subway'">
					<xsl:text>===== Metro =====
</xsl:text>
				</xsl:when>
			</xsl:choose>

			<xsl:text>{| class="wikitable sortable" style="width: auto; text-align: center; font-size: smaller; table-layout: fixed;"
|-
! Linka
! Relace
! Síť
! Dopravce
! Verze
! Délka [km]
! Segmentů
! Kompletní
</xsl:text>
			<xsl:variable name='route' select="tag[@k = 'route']/@v" />
			<xsl:apply-templates select="../relation[tag[@k = 'operator']/@v = $operator and tag[@k = 'route']/@v = $route]" mode='route'>
				<xsl:with-param name='operator'><xsl:value-of select="$operator" /></xsl:with-param>
				<xsl:with-param name='route'><xsl:value-of select="tag[@k = 'route']/@v" /></xsl:with-param>
				<xsl:sort select="tag[@k='ref']/@v" data-type="number" order="ascending"/>
			</xsl:apply-templates>
			<xsl:text>|}
</xsl:text>
		</xsl:if>
	</xsl:template>

	<xsl:template match='relation' mode='route'>
<xsl:text>|-
| </xsl:text><xsl:value-of select="tag[@k = 'ref']/@v" /><xsl:text>
| {{Relation|</xsl:text><xsl:value-of select="@id" /><xsl:text>}}
| </xsl:text><xsl:value-of select="tag[@k = 'network']/@v" /><xsl:text>
| </xsl:text><xsl:value-of select="tag[@k = 'operator']/@v" /><xsl:text>
| </xsl:text><xsl:value-of select="@version" /><xsl:text>
| $Length$ </xsl:text><xsl:value-of select="@id" /><xsl:text>
| $Segments$ </xsl:text><xsl:value-of select="@id" /><xsl:text>
| </xsl:text>
	<xsl:choose>
		<xsl:when test="tag[@k = 'complete']/@v= 'yes'">ano</xsl:when>
		<xsl:when test="tag[@k = 'complete']/@v = 'no'">ne</xsl:when>
	</xsl:choose><xsl:text>
</xsl:text>
	</xsl:template>
</xsl:stylesheet>

relan.awk

#!/usr/bin/env awk -f
/\$Length\$/ {
	system("curl -s -H 'Accept-Language: en' 'http://ra.osmsurround.org/analyzeRelation?noCache=true&_noCache=on&relationId="$3"' -o temp.html")

	t = "cat temp.html | grep 'Length in KM: <' | sed 's/.*>\\(.*\\)<\\/span>/\\1/'"

	s = "cat temp.html | grep -c 'Graph ' | sed -E 's/^0?$//'"

	a = ""
	b = ""
	t | getline a
	s | getline b
	close(t)
	close(s)
	print "| "a
	print "| "b
}
/^[^$]*$/