Advertisement
TheAtomicAss

generate_templates.sh

Nov 18th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.40 KB | None | 0 0
  1. #!/bin/bash
  2. #set -Eeuxo pipefail
  3.  
  4. # Get the next year
  5. make_year=`date -d "+1year" +%Y`
  6. # Start date
  7. cur=${make_year}0101
  8. # End date
  9. end=${make_year}1231
  10.  
  11. # Checks the difference between two dates for calculating the episode number
  12. # https://unix.stackexchange.com/a/24636
  13. episode_num()
  14. (
  15.     d2=$(date -d "$1" +%s)
  16.     d1=$(date -d "$2" +%s)
  17.     echo $(( (d1 - d2) / 86400 / 7 ))
  18. )
  19.  
  20. # Creates the seasonal directory if it doesn't exist,
  21. # then touches all .md files for that season.
  22. touch_file()
  23. (
  24.   # Arguments are
  25.   # 1. Which show
  26.   # 2. Year being generated
  27.   # 3. Which season for the individual show
  28.   # 4. Episode date
  29.   # 5. Episode number
  30.  
  31.   # Create the directory
  32.   seasonal_directory="$1/$2 - Season $3"
  33.   echo -e $seasonal_directory
  34.   if [[ ! -d "$seasonal_directory" ]]; then
  35.     echo -e "Created the directory $seasonal_directory"
  36.     mkdir -p "$seasonal_directory"
  37.   fi
  38.  
  39.   # Touch the file in it's naughty place
  40.   episode_date=`date -d "$4" +%Y%m%d`
  41.   episode_date_hr=`date -d $episode_date +%Y-%m-%d`
  42.   episode_name=$episode_date-$5.md
  43.   echo -e "Created the file $seasonal_directory/$episode_name"
  44.   #touch $seasonal_directory/$episode_name
  45.   echo -e "$5. \n     * $episode_date_hr\n        * [Showzen]()\n        * [Patreon]()\n        * [UNCUT Patreon]()\n     * <span style="color:red">LGC Weekly:</span> " >> "$seasonal_directory/$episode_name"
  46. )
  47.  
  48. # Loop through every day in the year, and create directories
  49. # and files as appropriate, stopping at the end of the year
  50.  
  51. echo -e "Are you sure you want to run?  Will be working on calendar year $make_year"
  52. read -n 1
  53. if [[ $REPLY =~ ^[Yy]$ ]]
  54.   then
  55.     # Loop until we reach the end of the year
  56.     while [ $cur -le $end ]
  57.       do
  58.         # Test if $cur is a Wednesday, then generate LWDW template
  59.         if [ $(date -d $cur +%w) == 3 ]
  60.           then
  61.             lwdw_episode=$( episode_num 20160210 $cur )
  62.             season=$(($make_year-2015))
  63.             touch_file LWDW $make_year $season $cur $lwdw_episode
  64.         # Test if $cur is a Saturday, then generate LGCW template
  65.         elif [ $(date -d $cur +%w) == 6 ]
  66.           then
  67.             lgcw_episode=$( episode_num 20120818 $cur )
  68.             season=$(($make_year-2011))
  69.             touch_file LGCW $make_year $season $cur $lgcw_episode
  70.         fi
  71.         cur=`date -d "$cur+1days" +%Y%m%d`
  72.     done
  73.   else
  74.     echo -e "Cancelling"
  75.     exit 1
  76. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement