-
2011/12/12 - 17:28
News
The section "Nas/Router" has been added
Current page: Home > Tech
Fetch news
The script I use to fetch the daily news broadcast for my handy
I use this script after I connected my phone to my computer. It chekcs if the daily news broadcast is on the phones memory card. If not, it downloads the latest 20:00 news from http://www.tagesschau.de and transmitts it to a predefined directory on the phone.
#! /bin/bash
tmp_dir="/tmp/fetch_news"
tmp_source_file="news_source.tmp"
destination_dir="/Speicherkarte/Filme"
destination_file="_nachrichten.mp4"
mount_dir="$tmp_dir/news_mount_pda"
# wait for device to come up
sleep 10
killall "$0" &> /dev/null
mkdir -p "$tmp_dir" &> /dev/null
wget "http://www.tagesschau.de/application/download/podcast.jsp" -O "$tmp_dir/$tmp_source_file" &> /dev/null
today=`date +%Y%m%d`
yesterday=`date --date='1 day ago' +%Y%m%d`
news_url=`cat $tmp_dir/$tmp_source_file | grep -A 4 "tagesschau 20:00 Uhr" | grep "h264.mp4" | grep -e "$today" | sed -e s'/.*href="//' -e s'/".*//'`
if [ -z "$news_url" ]; then
news_url=`cat $tmp_dir/$tmp_source_file | grep -A 4 "tagesschau 20:00 Uhr" | grep "h264.mp4" | grep -e "$yesterday" | sed -e s'/.*href="//' -e s'/".*//'`
destination_file="_$yesterday$destination_file"
else
destination_file="_$today$destination_file"
fi
if [ -z "$news_url" ]; then
echo "ERROR: URL empty!"
exit 1
else
if [ "http://" != `echo $news_url | sed -e s'/\(.......\).*/\1/'` ]; then
echo "ERROR: Wrong url prefix!"
exit 1
fi
if [ ".h264.mp4" != `echo $news_url | sed -e s'/.*\(.........\)/\1/'` ]; then
echo "ERROR: Wrong url suffix!"
exit 1
fi
fi
rm -f "$tmp_dir/$tmp_source_file" &> /dev/null
mkdir -p "$mount_dir" &> /dev/null
umount "$mount_dir" &> /dev/null
Fur "$mount_dir"
if [ ! -s "$mount_dir$destination_dir/$destination_file" ]; then
if [ ! -s "$tmp_dir/$destination_file" ]; then
echo -n "Fetching news ... "
wget "$news_url" -O "$tmp_dir/$destination_file" 2> /dev/null
positiv
fi
echo -n "Transmitting news to PDA ... "
mv "$tmp_dir/$destination_file" "$mount_dir$destination_dir/$destination_file.tmp" &> /dev/null
rm "$mount_dir$destination_dir/"*_nachrichten.mp4 &> /dev/null
mv "$mount_dir$destination_dir/$destination_file.tmp" "$mount_dir$destination_dir/$destination_file" &> /dev/null
positiv
fi
umount "$mount_dir" &> /dev/null && rmdir "$mount_dir" &> /dev/null && rmdir "$tmp_dir" &> /dev/null
last updated: May 4, 2020 17:36:28