Skip to content

Instantly share code, notes, and snippets.

@xmorave2
Last active September 27, 2016 10:47
Show Gist options
  • Select an option

  • Save xmorave2/373327348118e15cb679d7dedece2aa7 to your computer and use it in GitHub Desktop.

Select an option

Save xmorave2/373327348118e15cb679d7dedece2aa7 to your computer and use it in GitHub Desktop.
Stahování Zákony pro lidi
<!-- rozšíření schématu solru o specifické pole -
pro funkčnost není nutné, ale pokud se nepoužije, je třeba odpovídajícím
způsobem upravit šablonu
-->
<!-- Zakony pro lidi -->
<field name="law_doctype" type="string" indexed="true" stored="true" multiValued="true"/>
#!/bin/bash
apikey=test
collection=cs
cd harvest
mkdir zakony
#výchozí začátek je rok 1945, pokud už se stahovalo, naváže posledním staženým rokem...
start=1945
if [ -f zakony-date ]
then
start=$(date -r zakony-date +'%Y')
fi
end=$(date +'%Y')
# časová značka posledního stahování
touch zakony-date
cd zakony
rm *.xml
for (( i=$start; i<=$end; i++ ))
do
wget "http://www.zakonyprolidi.cz/api/v1/data.xml/YearDocList?apikey=$apikey&Collection=$collection&Year=$i" -O "zakony$i.xml"
echo "Rozděluji soubor pro rok $i"
xml_split -l 2 zakony$i.xml
rm "zakony$i.xml"
rm "zakony$i-00.xml"
done
echo "Mažu zrušené zákony"
for xmlfile in $(ls)
do
zruseno=$(tail -n 1 $xmlfile | sed 's/.*\(EffectTill\).*/1/')
if [ "$zruseno" = "1" ] ; then
rm $xmlfile
fi;
done;
cd ..
./batch-import-xsl.sh zakony zakony.properties
cd ..
; local/import/zakony.properties
; předpis pro importér
; XSLT Import Settings for Directory of Open Access Journals' doajArticle format
; (see http://www.doaj.org/schemas/doajArticle.xsd for details)
[General]
; REQUIRED: Name of XSLT file to apply. Path is relative to the import/xsl directory
; of the VuFind installation (or your local override directory).
xslt = zakony.xsl
; OPTIONAL: PHP function(s) to register for use within XSLT file. You may repeat
; this line to register multiple PHP functions.
;php_function[] = str_replace
; OPTIONAL: PHP class filled with public static functions for use by the XSLT file.
; The class must live within a PHP namespace. You may specify a fully-qualified
; name; if you do not include a namespace, the class will automatically be assumed
; to live in the \VuFind\XSLT\Import namespace.
custom_class[] = VuFind
; OPTIONAL: If true, all custom_class settings above will be passed to the XSLT with
; their namespaces stripped off; for example, \VuFind\XSLT\Import\VuFind would be
; treated as \VuFind in XSLT files. This allows more compact syntax within XSLT
; files, but it can lead to name conflicts if used carelessly. If set to false, you
; must use fully-qualified names in your XSLT. The false setting is recommended, but
; the current default is "true" for compatibility with legacy configurations.
truncate_custom_class = true
; XSLT parameters -- any key/value pairs set here will be passed as parameters to
; the XSLT file, allowing local values to be set without modifying XSLT code.
[Parameters]
institution = "ZakonyProLidi"
collection = "Law"
<!-- local/import/xsl/zakony.xsl
šablona pro transformaci xml dodaného ze zakonyprolidi.cz API
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:php="http://php.net/xsl"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xlink="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="xml" indent="yes" encoding="utf-8"/>
<xsl:param name="institution">ZakonyProLidi</xsl:param>
<xsl:param name="collection">Law</xsl:param>
<xsl:template match="DocInfo">
<add>
<doc>
<!-- ID -->
<field name="id">zakony<xsl:value-of select="/DocInfo/@DocId"/></field>
<!-- RECORDTYPE -->
<field name="recordtype">law</field>
<!-- FULLRECORD -->
<field name="fullrecord">
<xsl:copy-of select="php:function('VuFind::xmlAsText', /DocInfo)"/>
</field>
<!-- ALLFIELDS -->
<field name="allfields">
<xsl:value-of select="normalize-space(string(/DocInfo))"/>
</field>
<!-- INSTITUTION -->
<field name="institution">
<xsl:value-of select="$institution" />
</field>
<!-- BUILDING -->
<field name="building">zakony</field>
<!-- COLLECTION -->
<field name="collection">
<xsl:value-of select="$collection" />
</field>
<!-- ITEMTYPE -->
<field name="itemtype">LG</field>
<!-- LANGUAGE -->
<field name="language">Czech</field>
<!-- FORMAT -->
<field name="format">Legislative document</field>
<!-- LAW DOCTYPE -->
<field name="law_doctype">
<xsl:value-of select="/DocInfo/@DocType"/>
</field>
<!-- AUTHOR -->
<field name="author">Česká Republika</field>
<!-- TITLE -->
<field name="title"><xsl:value-of select="/DocInfo/@Title"/>. <xsl:value-of select="/DocInfo/@Quote"/></field>
<field name="title_short"><xsl:value-of select="/DocInfo/@Title[normalize-space()]"/>. <xsl:value-of select="/DocInfo/@Quote"/></field>
<field name="title_full"><xsl:value-of select="/DocInfo/@Title[normalize-space()]"/>. <xsl:value-of select="/DocInfo/@Quote"/></field>
<field name="title_sort"><xsl:value-of select="php:function('VuFind::stripArticles', string(/DocInfo/@Title[normalize-space()]))"/>. <xsl:value-of select="php:function('VuFind::stripArticles', string(/DocInfo/@Quote[normalize-space()]))"/></field>
<!-- PUBLISHER -->
<field name="publisher">Česká Republika</field>
<!-- PUBLISHDATE -->
<field name="publishDate">
<xsl:value-of select="/DocInfo/@Year"/>
</field>
<field name="publishDateSort">
<xsl:value-of select="/DocInfo/@Year"/>
</field>
<!-- URL -->
<field name="url">http://www.zakonyprolidi.cz<xsl:value-of select="/DocInfo/@Href[normalize-space()]"/></field>
</doc>
</add>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment