Created
February 1, 2021 17:48
-
-
Save suidroot/d22c6fd45e3801caf31943b9eea86b4d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# | |
FILE_LOCATION="$HOME/SynologyDrive/Drive/Documents/Police Logs" | |
TEMP_LOCATION="$HOME/Temp/PPD-DOWNLOADS-$(date +%Y%m%d%H%M)" | |
# | |
### Daily Media Logs | |
# https://www.portlandmaine.gov/739/Daily-Media-Logs | |
DAYS_OF_WEEK=("monday" "tuesday" "wednesday" "thursday" "friday" "saturday" "sunday") | |
MEDIA_LOG_URLS=("https://www.portlandmaine.gov/DocumentCenter/View/2263" | |
"https://www.portlandmaine.gov/DocumentCenter/View/2267" | |
"https://www.portlandmaine.gov/DocumentCenter/View/2268" | |
"https://www.portlandmaine.gov/DocumentCenter/View/2266" | |
"https://www.portlandmaine.gov/DocumentCenter/View/2262" | |
"https://www.portlandmaine.gov/DocumentCenter/View/11641" | |
"https://www.portlandmaine.gov/DocumentCenter/View/2265") | |
ARRESTLOG_URL="https://www.portlandmaine.gov/DocumentCenter/View/5911" | |
mkdir $TEMP_LOCATION | |
cd $TEMP_LOCATION | |
for COUNTER in ${!DAYS_OF_WEEK[*]} | |
do | |
#echo "${MEDIA_LOG_URLS[$COUNTER]} -O ${DAYS_OF_WEEK[$COUNTER]}.pdf" | |
echo -n "Downloading ${DAYS_OF_WEEK[$COUNTER]}... " | |
wget ${MEDIA_LOG_URLS[$COUNTER]} -O ${DAYS_OF_WEEK[$COUNTER]}.pdf -o ${DAYS_OF_WEEK[$COUNTER]}.log | |
#CREATE_DATE=$(pdfinfo ${DAYS_OF_WEEK[$COUNTER]}.pdf | grep CreationDate | cut -d" " -f4 | cut -d"T" -f1).pdf | |
CREATE_DATE=$(pdfinfo ${DAYS_OF_WEEK[$COUNTER]}.pdf | grep CreationDate | cut -d":" -f 2-4 | xargs) | |
NEWFILE_NAME=$(date -j -f "%a %b %d %H:%M:%S %Y" "$CREATE_DATE" +%F).pdf | |
if [ ! -f "$FILE_LOCATION/Media Logs/$NEWFILE_NAME" ]; | |
then | |
mv ${DAYS_OF_WEEK[$COUNTER]}.pdf "$FILE_LOCATION/Media Logs/$NEWFILE_NAME" | |
echo "Downloaded: ${DAYS_OF_WEEK[$COUNTER]}" | |
else | |
echo "already downloaded" | |
#rm ${DAYS_OF_WEEK[$COUNTER]}.pdf | |
#rm "$FILE_LOCATION/Media Logs/$NEWFILE_NAME" | |
fi | |
done | |
# | |
### Get Arrest Log | |
# | |
echo -n "Downloading Arrestlog.... " | |
wget $ARRESTLOG_URL -O arrestlog.pdf -o arrestlog_${DAYS_OF_WEEK[$COUNTER]}.log | |
#NEWFILE_NAME="arrestlog_$(pdfinfo arrestlog.pdf | grep CreationDate | cut -d" " -f4 | cut -d"T" -f1).pdf" | |
CREATE_DATE=$(pdfinfo arrestlog.pdf | grep CreationDate | cut -d":" -f 2-4 | xargs) | |
NEWFILE_NAME="arrestlog_$(date -j -f "%a %b %d %H:%M:%S %Y" "$CREATE_DATE" +%F).pdf" | |
if [ -f "$FILE_LOCATION/$NEWFILE_NAME" ]; | |
then | |
echo "already Downloaded" | |
else | |
mv arrestlog.pdf "$FILE_LOCATION"/$NEWFILE_NAME | |
echo "Downloaded: $NEWFILE_NAME" | |
fi | |
rm -rf $TEMP_LOCATION | |
rm "$FILE_LOCATION"/lastdl_* | |
touch "$FILE_LOCATION/lastdl_$(date +%A_%Y%m%d%H%M)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment