Skip to content

Instantly share code, notes, and snippets.

@isamert
Last active March 31, 2018 16:26
Show Gist options
  • Save isamert/55c6e6bfcd4c5d5375664e985152aa48 to your computer and use it in GitHub Desktop.
Save isamert/55c6e6bfcd4c5d5375664e985152aa48 to your computer and use it in GitHub Desktop.
ceng.sh
#!/bin/bash
base="http://ceng.anadolu.edu.tr/Ders.aspx?dersId="
courses=("120" "95" "105" "103" "24")
cache_folder="$HOME/.cache/ceng"
if [ ! -d "$cache_folder" ]
then
echo "First time usage."
echo "Downloading..."
mkdir "$cache_folder"
cd "$cache_folder"
for cid in "${courses[@]}"
do
url="$base$cid"
filename="$cid.html"
curl -sS -o "$filename" "$url"
# Remove bullshit
sed -i '/input type="hidden"/,+1 d' "$filename"
done
echo "Done."
else
cd "$cache_folder"
for cid in "${courses[@]}"
do
url="$base$cid"
filename="$cid.html"
html=`curl -sS "$url" | sed '/input type="hidden"/,+1 d'`
diff=`echo "$html" | diff "$filename" -`
if [ $? -eq 0 ]; then
echo "$cid: nothing new."
else
echo "$html" > "$filename"
echo "============================================================="
echo "$cid:"
echo "$diff"
echo "============================================================="
fi
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment