]> www.vanbest.org Git - tv_grab_nl_java/commitdiff
Add scripts to count programmes per source
authorJan-Pascal van Best <janpascal@vanbest.org>
Sun, 12 Jan 2014 15:21:13 +0000 (16:21 +0100)
committerJan-Pascal van Best <janpascal@vanbest.org>
Sun, 12 Jan 2014 15:21:13 +0000 (16:21 +0100)
scripts/.gitignore [new file with mode: 0644]
scripts/count.sh [new file with mode: 0755]
scripts/grab_all.sh [new file with mode: 0755]
scripts/xml2sql.xslt [new file with mode: 0644]
scripts/xmltv.dtd [new file with mode: 0644]

diff --git a/scripts/.gitignore b/scripts/.gitignore
new file mode 100644 (file)
index 0000000..5fb4562
--- /dev/null
@@ -0,0 +1,6 @@
+tv.xml
+all.conf
+all.cache*
+out.html
+test.sqlite
+tv.sql
diff --git a/scripts/count.sh b/scripts/count.sh
new file mode 100755 (executable)
index 0000000..44e7f39
--- /dev/null
@@ -0,0 +1,68 @@
+#!/bin/sh
+
+TVFILE=tv.xml
+XSLT=xml2sql.xslt
+SQLFILE=tv.sql
+DB=test.sqlite
+
+echo "Converting xmltv data to SQL..." >&2
+saxonb-xslt -xsl:$XSLT  -s:$TVFILE -dtd:off >$SQLFILE
+echo "Reading data into database..." >&2
+rm $DB; sqlite3 $DB <$SQLFILE
+
+echo "Fetching available dates..." >&2
+DATES=$( sqlite3 $DB 'select distinct datum from programme order by datum asc' )
+
+echo "<html>"
+echo "<h2>Aantal kanalen per provider</h2>"
+
+echo "Fetching number of channels per provider..." >&2
+echo "<table>"
+sqlite3 -html -header $DB 'select source as provider,count(*) as aantal from channel group by source;'
+echo "</table>"
+
+SQL='SELECT source'
+for datum in $DATES
+do
+    SQL="$SQL , count(case when programme.datum=\"$datum\" then 1 end) as \`$datum\`"
+done
+SQL="$SQL from programme"
+SQL="$SQL group by source"
+
+echo "Fetching number of programmes per provider per day..." >&2
+echo "<h2>Aantal programmas in de gids per provider per dag</h2>"
+echo "<table>"
+sqlite3 -html -header $DB "$SQL"
+echo "</table>"
+
+SQL='SELECT p.source, c.name'
+for datum in $DATES
+do
+    SQL="$SQL , count(case when p.datum=\"$datum\" then 1 end) as \`$datum\`"
+done
+SQL="$SQL FROM programme p JOIN channel c ON c.id=p.channel"
+SQL="$SQL group by c.name,c.source"
+SQL="$SQL order by c.name"
+
+echo "Fetching number of programmes per provider, per channel, per day..." >&2
+echo "<h2>Aantal programmas in de gids per provider per kanaal per dag</h2>"
+echo "<table>"
+sqlite3 -html -header $DB "$SQL"
+echo "</table>"
+
+SQL='SELECT p.source, c.name'
+for datum in $DATES
+do
+    SQL="$SQL , count(case when p.datum=\"$datum\" then 1 end) as \`$datum\`"
+done
+SQL="$SQL FROM programme p JOIN channel c ON c.id=p.channel"
+SQL="$SQL group by c.name,c.source"
+SQL="$SQL order by c.source"
+
+echo "Fetching number of programmes per channel, per provider, per day..." >&2
+echo "<h2>Aantal programmas in de gids per kanaal per provider per dag</h2>"
+echo "<table>"
+sqlite3 -html -header $DB "$SQL"
+echo "</table>"
+
+echo "</html>"
diff --git a/scripts/grab_all.sh b/scripts/grab_all.sh
new file mode 100755 (executable)
index 0000000..0ded752
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+VERSION=$( xsltproc ../pom_version.xsl ../pom.xml )
+
+GRABBER="java -jar ../target/tv_grab_nl_java-$VERSION-dep.jar"
+CONFFILE="all.conf"
+CACHEFILE="all.cache"
+
+$GRABBER --configure --config-yes --config-file=${CONFFILE}
+$GRABBER --cache $CACHEFILE --config-file ${CONFFILE} --days 31 --output tv.xml
diff --git a/scripts/xml2sql.xslt b/scripts/xml2sql.xslt
new file mode 100644 (file)
index 0000000..1d77b0e
--- /dev/null
@@ -0,0 +1,88 @@
+<?xml version="1.0"?> 
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+xmlns:xs="http://www.w3.org/2001/XMLSchema"
+xmlns:fn="http://www.w3.org/2005/xpath-functions" 
+version="2.0" >
+<xsl:output method="text" omit-xml-declaration="yes" /> 
+
+<xsl:variable name="sources" as="element()*">
+    <Item>tvgids.nl</Item>
+    <Item>rtl.nl</Item>
+    <Item>horizon.tv</Item>
+    <Item>ziggogids.nl</Item>
+</xsl:variable>
+
+<xsl:variable name="today" select="current-date()" />
+<xsl:variable name="day" select="xs:duration('P1D')" />
+
+<xsl:variable name="dates" as="element()*">
+    <xsl:for-each select="0 to 21">
+        <date><xsl:value-of select="$today + .*xs:dayTimeDuration('P1D')"/></date>
+    </xsl:for-each>
+</xsl:variable>
+
+<xsl:template match="/"> 
+    <xsl:text>BEGIN TRANSACTION;&#10;</xsl:text> 
+    <xsl:text>CREATE TABLE channel (id varchar(30), source varchar(20), name varchar(255));&#10;</xsl:text> 
+    <xsl:for-each select="tv/channel"> 
+        <xsl:text>INSERT INTO channel (id,source,name) VALUES (&quot;</xsl:text> 
+        <xsl:value-of select="@id"/> 
+        <xsl:text>&quot;,&quot;</xsl:text> 
+        <xsl:value-of select="fn:substring-after(@id,'.')"/> 
+        <xsl:text>&quot;,&quot;</xsl:text> 
+        <xsl:value-of select="display-name"/> 
+        <xsl:text>&quot;);&#10;</xsl:text> 
+    </xsl:for-each> 
+<!--
+    <xsl:for-each select="tv"> 
+    <xsl:text>Total channels: </xsl:text>
+        <xsl:value-of select="count(channel)"/> 
+        <xsl:text>&#10;</xsl:text>
+
+        <xsl:for-each select="$sources"> 
+           <xsl:variable name="source" select="."/>
+           <xsl:text>Number of </xsl:text>
+           <xsl:value-of select="."/>
+           <xsl:text> channels: </xsl:text>
+           <xsl:value-of select="count(//channel[fn:ends-with(@id, $source)])"/> 
+           <xsl:text>&#10;</xsl:text>
+        </xsl:for-each>
+
+        <xsl:for-each select="$sources"> 
+            <xsl:variable name="source" select="."/>
+            <xsl:text>Source: </xsl:text>
+            <xsl:value-of select="$source"/>
+            <xsl:text>&#10;</xsl:text>
+
+            <xsl:for-each select="$dates"> 
+               <xsl:variable name="date" select="format-date(., '[Y0001][M01][D01]')"/>
+               <xsl:text>Date: </xsl:text>
+               <xsl:value-of select="$date"/>
+               <xsl:text>&#10;</xsl:text>
+
+               <xsl:text>Count: </xsl:text>
+               <xsl:value-of select="count(//programme[fn:starts-with(@start, $date) and fn:ends-with(@channel,$source)])"/>
+               <xsl:text>&#10;</xsl:text>
+            </xsl:for-each>
+        </xsl:for-each>
+
+    </xsl:for-each> 
+-->
+<!--    <xsl:text>Programmes:&#10;</xsl:text> -->
+    <xsl:text>CREATE TABLE programme(datum date, tijd time, channel varchar(30), source varchar(20), name varchar(255));&#10;</xsl:text> 
+    <xsl:for-each select="tv/programme"> 
+        <xsl:text>INSERT INTO programme(datum,tijd,channel,source,name) VALUES (&quot;</xsl:text> 
+        <xsl:value-of select="fn:concat(fn:substring(@start,1,4),'-',fn:substring(@start,5,2),'-',fn:substring(@start,7,2))"/> 
+        <xsl:text>&quot;, &quot;</xsl:text> 
+        <xsl:value-of select="fn:concat(fn:substring(@start,9,2),':',fn:substring(@start,11,2))"/> 
+        <xsl:text>&quot;, &quot;</xsl:text> 
+        <xsl:value-of select="@channel"/> 
+        <xsl:text>&quot;,&quot;</xsl:text> 
+        <xsl:value-of select="fn:substring-after(@channel,'.')"/> 
+        <xsl:text>&quot;,&quot;</xsl:text> 
+        <xsl:value-of select="fn:translate(title,'&quot;','')" /> 
+        <xsl:text>&quot;);&#10;</xsl:text> 
+    </xsl:for-each> 
+    <xsl:text>COMMIT TRANSACTION;&#10;</xsl:text> 
+</xsl:template> 
+</xsl:stylesheet>
diff --git a/scripts/xmltv.dtd b/scripts/xmltv.dtd
new file mode 100644 (file)
index 0000000..e69de29