From OTRR Wiki

FirstLines: TemplateScript

Here is the script I use to create the First Line Templates out of the Otter Log Database Files.

Basically, an entry in the original Otter Log would look like this (Taken from Abbot and Costello):
* 42/10/08    14 Cousin Yugo Gets Married

The script turns that into:

Date Aired : 42/10/08
Episode Number : 14
Available : YES
Title/Plot/Host: Cousin Yugo Gets Married
First Line :

While fully functional, there is definitely room for improvement.

One thing that may improve the script would be to do some kind of pre-formatting on the episode entries (perhaps all the text before the ':' could be bold; maybe a different color to help it stand out when scrolling down the page.).

Also of vital importance. If someone can figure out how to automatically merge updates of the otter log into the template, that would be awesome.

If anyone is able to write shell scripts and would like to improve this one (or convert it to perl, etc.), be my guest.

 
#!/bin/bash
#
## Version 1.2 - Now use only gawk to create template. No longer need sed to change output if episode is unavailable. 
## 
#
# This script takes one argument, the name of the Otter Database file you wish to convert into a template.
# The template is named First Lines-NameOfOtterLog.txt (where NameOfOtterLog.txt is the name of the otter log)
#  
# It is based on the fact that the format for the otter files are fixed 
# (based on the file "Creating a Log File.txt" from groups.yahoo.com/groups/otter-project)
#
# What the script does:
# 1) replaces the blank space indicating the show is not known to exist with a hyphen. (makes a backup of the original)
# 2) replaces 6 blank lines ("      ") with 2 blank lines and 4 hyphens (" ---- ") 
#	-> This is for the programs that don't have episode numbers.
# 3) formats the information into the template (a file that starts with the words: "First Line-"
# 4) Trims fields from unavailable episodes. 
# 5) restores original log file
#
#
### Otter Database Format
#
#Column 1  * Indicates that the episode is known to exist
#         <space> Indicates that the episode is not known to exist
#
#Column 3-4  Two digit Year (yes we know it's not year 2000 compliant)
#
#Column 5   / (the slash character) or a <space>
#
#Column 6-7  Two digit Month
#
#Column 8  / (the slash character) or a <space>
#
#Column 9-10 Two digit Day
#
#Column 11 <space>
#
#Column 12-15  Episode number (if known). Use leading spaces.
#
#Column 16 <space>
#
#Column 17-45  Episode title 
#
### End Otter Database Format

# make sure a file to convert is used.

if [[ $# -lt 1 ]];then
	echo "Error: No file to convert."
	echo; echo "Use the program like this:" 
	echo "$0 otter_log.txt"
	echo "Where otter_log.txt is the name of the otter log you wish to convert."
	exit 1
fi

### set some variables for use throughout the script
OTTERLOG=""$*""
FIRSTLINETEMPLATE=First\ Lines-"${*}"

# replaces the blank space indicating the show is not known to exist with a hyphen.
# (makes a backup of the original).
sed -i~ s/^' '/'-'/ "$OTTERLOG"

# replaces 6 blank lines ("      ") with 2 blank lines and 4 hyphens (" ---- ") 
# This is for the programs that don't have episode numbers.
sed -i s/'      '/' ---- '/ "$OTTERLOG"


### Creating the template ###
# splits otter log into 8 fields:
# $1 --> episode availability (1 character)
# $2 --> blank space (1 character)
# $3 --> date (8 characters)
# $4 --> blank space (1 character)
# $5 --> episode number (4 characters)
# $6 --> blank space (1 character)
# $7 --> title (up to 280 characters)

# it is very easy to edit things into the template.
# Just add whatever you want (synopsis, AKA's, etc) before the line: {printf "\n\n"}' "$OTTERLOG" > "$FIRSTLINETEMPLATE"

# The format to add a line is as follows (without the quotes):
# - line must start with "{print"
# - any fixed text that you want to put in the line must be enclosed in quotes
# - to add the information from one of the fields, put the field number (with the dollar sign), outside the quotes.
# - end the line with a close braces --> }
#
# Example: to add a field for a Synopsis, just add this to the line before {printf "\n\n"}' "$OTTERLOG" > "$FIRSTLINETEMPLATE"
# {print "Synopsis       : "}

gawk 'BEGIN{ FIELDWIDTHS = "1 1 8 1 4 1 280" };
{if ( $1 == "'*'" )
	print "%PURPLE%Date Aired     : " $3
 else print "Date Aired     : " $3}
{print "Episode Number : " $5}
{if ( $1 == "'*'" )
	print "Available      : YES"
 else print "Available      : NO"}
{if (( $7 != "" ) || ( $1 == "'*'" ))
	print "Title/Plot/Host: " $7}
{if ( $1 == "'*'" )
	print "First Line     : "}
{printf "\n\n"}' "$OTTERLOG" > "$FIRSTLINETEMPLATE"

# restore original log file
if [[ $? == 0 ]];then
	bak="${OTTERLOG}~"
	mv "$bak" "$OTTERLOG"
fi

Attach:First_Line_Script_v1-2

Retrieved from http://www.otrr.org/pmwiki/pmwiki.php/FirstLines/TemplateScript
Page last modified on July 06, 2005, at 02:33 PM