#!/bin/sh # Written by Sean Smith # Date: 03/25/2021 # This program takes one search term and uses the MovieDB API to return # relevant information on the top 10 results. The program parses the data and compiles it into # an HTML document named index.html # This will run on any system with the GNU core utils (almost every unix system) # If you are having trouble running it then run "chmod +x midterm.sh" to give the file # execute permission #take one arg as the search term SEARCH=$1 if [ $# -eq 0 ] then echo "This program requires an argument!" echo "Please enter a search term with no spaces or special characters." echo "EXAMPLE: ./midterm.sh titanic" exit 1 fi #query the api wget "https://api.themoviedb.org/3/search/movie?api_key=1f2944e277cd20849744f1b752deb3f4&language=en-US&page=1&include_adult=false&query="$SEARCH #rename the JSON file mv "movie?api_key=1f2944e277cd20849744f1b752deb3f4&language=en-US&page=1&include_adult=false&query="$SEARCH result.json #format the JSON file and break it into seperate files for each search result sed -i 's/,"/,\n"/g' result.json sed -i 's/},{/}\n\nSPLITSYMBOL\n\n{/g' result.json csplit result.json --suppress-matched '/SPLITSYMBOL/' {*} CURRENT=0 while [ $CURRENT -le 9 ] do #replace JSON with html tags sed -i 's/"original_title":"/
/g' xx0$CURRENT #remove end of line ," sed -i 's/",//g' xx0$CURRENT #close html tags sed -i -e '/
/s/$/<\/p>/' xx0$CURRENT
sed -i -e '//' xx0$CURRENT
#remove unneeded lines
sed -i 's/^[^<].*//g' xx0$CURRENT
sed -i '/^[[:space:]]*$/d' xx0$CURRENT
CURRENT=$((CURRENT+1))
done
#remove previous search result page
rm index.html
#generate new search result page
cat header xx00 xx01 xx02 xx03 xx04 xx05 xx06 xx07 xx08 xx09 footer > index.html
#remove temporary files
CURRENT=0
while [ $CURRENT -le 9 ]
do
rm xx0$CURRENT
CURRENT=$((CURRENT+1))
done
while [ $CURRENT -le 19 ]
do
rm xx$CURRENT
CURRENT=$((CURRENT+1))
done
echo "index.html has been generated in this directory"
echo "Done!"
exit 1