Skip to content

Instantly share code, notes, and snippets.

@fraktik
Last active February 18, 2021 12:45
Show Gist options
  • Save fraktik/2ed507db28ad7dc5dada5a428edb0b2f to your computer and use it in GitHub Desktop.
Save fraktik/2ed507db28ad7dc5dada5a428edb0b2f to your computer and use it in GitHub Desktop.
Ereading (palmknihy.cz) skripty pro import nových položek ze serveru do vufindu Ustí nad Orlicí
#!/bin/bash
cd data/ereading
rm nkc.mrc
echo "open aleph.nkp.cz:9991" > commands.yaz
echo "base SKC-UTF" >> commands.yaz
echo "set_marcdump nkc.mrc" >> commands.yaz
echo "Zjistuji jiz importovane knihy..."
for xmlfile in $(ls *.xml)
do
isbn="${xmlfile%.*}"
#solr=$(curl "http://localhost:8080/solr/biblioUO/select?q=isbn:$isbn+AND+NOT+building:eReading&rows=0&indent=true" | grep "numFound")
solr=$(curl "http://localhost:8080/solr/biblioUO/select?q=isbn:$isbn&rows=0&indent=true" | grep "numFound")
pocet=$(echo $solr | sed 's/.*numFound="\([0-9]*\)".*/\1/')
if [ $pocet != "0" ] ; then
echo "Mazu soubor $xmlfile"
rm $xmlfile;
else
echo "Pridavam ke stazeni isbn $isbn"
echo "find @attr 1=7 \"$isbn\"" >> commands.yaz
echo "show" >> commands.yaz
#rm $xmlfile
fi
done
echo "quit" >> commands.yaz
echo "Stahuji zaznamy z Narodni knihovny..."
yaz-client -f commands.yaz
cd ../..
"Importuji zaznamy..."
./import-marc.sh -p ./local/import/ereading.properties data/ereading/nkc.mrc
#!/bin/bash
cd /usr/local/vufind2/data2
mkdir ereading
rm xml_rent.php
wget "http://www.ereading.cz/xml/xml_rent.php"
rm ereading/*.xml
mv xml_rent.php ereading/ereading.xml
cd ereading
echo "Rozdeluji soubory..."
xml_split ereading.xml
rm ereading.xml
rm ereading-00.xml
echo "Prejmenovavam a odstranuji nepotrebne soubory..."
for xmlfile in $(ls)
do
vypujcka=$(tail -n 1 $xmlfile | sed 's/.*<VYPUJCKA>\([0-9]*\).*/\1/')
if [ "$vypujcka" = "0" ] ; then
rm $xmlfile
else
filename=$(tail -n 1 $xmlfile | sed 's/.*<ISBN_TISTENE>\(.*\)<\/ISBN_TISTENE>.*/\1/' | sed 's/[^0-9]*//g')
if [ "$filename" = "" ] ; then
filename=$(tail -n 1 $xmlfile | sed 's/.*<EAN>\(.*\)<\/EAN>.*/\1/' | sed 's/[^0-9]*//g')
fi;
if [ "$filename" != "" ] ; then
mv $xmlfile $filename.xml
else
rm $xmlfile
fi;
fi;
done;
cd ../..
echo "Vytvarim Solr index..."
./import-marc.sh $@
cd data2/ereading
rm nkc.mrc
echo "open aleph.nkp.cz:9991" > commands.yaz
echo "base SKC-UTF" >> commands.yaz
echo "set_marcdump nkc.mrc" >> commands.yaz
echo "Zjistuji jiz importovane knihy..."
for xmlfile in $(ls *.xml)
do
isbn="${xmlfile%.*}"
solr=$(curl "http://localhost:8080/solr/biblioUO/select?q=isbn:$isbn+AND+NOT+building:eReading&rows=0&indent=true" | grep "numFound")
# solr=$(curl "http://localhost:8080/solr/biblioUO/select?q=isbn:$isbn&rows=0&indent=true" | grep "numFound")
pocet=$(echo $solr | sed 's/.*numFound="\([0-9]*\)".*/\1/')
if [ $pocet != "0" ] ; then
echo "Mazu soubor $xmlfile"
rm $xmlfile;
else
echo "Pridavam ke stazeni isbn $isbn"
echo "find @attr 1=7 \"$isbn\"" >> commands.yaz
echo "show" >> commands.yaz
#rm $xmlfile
fi
done
echo "quit" >> commands.yaz
echo "Stahuji zaznamy z Narodni knihovny..."
yaz-client -f commands.yaz
cd ../..
"Importuji zaznamy..."
./import-marc.sh -p ./local/import/ereading.properties data2/ereading/nkc.mrc
#!/bin/bash
cd data
mkdir ereading
rm xml_rent.php
wget "http://www.ereading.cz/xml/xml_rent.php"
rm ereading/*.xml
mv xml_rent.php ereading/ereading.xml
cd ereading
echo "Rozděluji soubory..."
xml_split ereading.xml
rm ereading.xml
rm ereading-00.xml
echo "Přejmenovávám a odstraňuji nepotřebné soubory..."
for xmlfile in $(ls *.xml)
do
vypujcka=$(tail -n 1 $xmlfile | sed 's/.*<VYPUJCKA>\([0-9]*\).*/\1/')
if [ "$vypujcka" = "0" ] ; then
rm $xmlfile
else
filename=$(tail -n 1 $xmlfile | sed 's/.*<EAN>\(.*\)<\/EAN>.*/\1/' | sed 's/[^0-9]*//g')
if [ "$filename" = "" ] ; then
filename=$(tail -n 1 $xmlfile | sed 's/.*<ISBN_TISTENE>\(.*\)<\/ISBN_TISTENE>.*/\1/' | sed 's/[^0-9]*//g')
fi;
if [ "$filename" != "" ] ; then
mv $xmlfile $filename.xml
else
rm $xmlfile
fi;
fi;
done;
cd ../..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment