User:Randall

From The TV IV

Jump to: navigation, search

Hi, I'm Justin.

I'm not one to brag, but I am the one responsible for getting us slashdotted with A New Replacement for TV Tome. I'm always up for suggestions on how we can improve this site, and I think recently it's really been shaping up into quite an excelltent Television database. There is still a looooooong way to go, but editing has more then tripled in the past week alone, as well as user registration. We're editing our asses off! --Randall 01:02, 17 Sep 2005 (EDT)


***UPDATE*** added some C++ code that will make everyone's life easier, trust me you'll want to look at this --Randall 02:52, 18 Sep 2005 (EDT)

***UPDATE*** There is a new version of this code. What's new is that it will format the date correctly (from 1985 until 2006), as well as adding a page header to the output file. Email me if you would like a copy of the code, as it is now 25,000 lines long! and far too large to post to this page. (It also takes a few minutes to compile). My email is at the bottom of this page if you're interrested. --Randall 21:40, 18 Sep 2005 (EDT)

Contents

[edit] Article Accomplishments

[edit] Templates

Please feel free to use these templates whenever you are uploading an image, simply by typing the bracketed code in the "Comments" section of the upload dialog, as it will make for easier cataloging of images, etc.

{{GFDL}}
{{Logo}}
  • This is an image template for indicating that the image is a copyrighted logo, but you're using it under the Fair Usage clause of the United States Copyright Law... Don't know if that will hold up in court buddy ;)

[edit] C++ Code for Epguides.com

I wrote this C++ code this afternoon, and what it does is sweet. If you compile this code into an executable on your system using g++ or any cpp compiler (it should work on any computer OS). You will end up with a command line program called format.exe. What this does, is takes an input file that has a fixed width format, and outputs an episodes template for you to upload the TV IV Wiki! How does this work? Well you save your own input file by copying and pasting text from epguides.com in thier episode listing. You must do only one season at a time For example, I have this as my input file saved to my hard drive as SimpsonsS1.txt:

  1.   1- 1       7G08     17 Dec 89   The Simpsons Roasting on an Open Fire
  2.   1- 2       7G02     14 Jan 90   Bart The Genius
  3.   1- 3       7G03     21 Jan 90   Homer's Odyssey
  4.   1- 4       7G04     28 Jan 90   There's No Disgrace Like Home
  5.   1- 5       7G05      4 Feb 90   Bart The General
  6.   1- 6       7G06     11 Feb 90   Moaning Lisa
  7.   1- 7       7G09     18 Feb 90   The Call Of The Simpsons
  8.   1- 8       7G07     25 Feb 90   The Telltale Head
  9.   1- 9       7G11     18 Mar 90   Life On The Fast Lane
 10.   1-10       7G10     25 Mar 90   Homer's Night Out
 11.   1-11       7G13     15 Apr 90   The Crepes Of Wrath
 12.   1-12       7G12     29 Apr 90   Krusty Gets Busted
 13.   1-13       7G01     13 May 90   Some Enchanted Evening

So there is a list of the first season of The Simpsons right there. Now, here comes the fun part. Take this input file, and run the format.exe command from a Command Prompt like this:

format.exe "The Simpsons" SimpsonsS1.txt SimpsonsS1_Formatted.txt 

***UPDATE*** To get a complete page generation, you can also do this.

format.exe "The Simpsons" SimpsonsS1.txt SimpsonsS1_Formatted.txt 1 "December 17, 1989" "May 13, 1990" 13 n

And the result is this in the file SimpsonsS1_Formatted.txt:

{{Season| season = Season One
|showtitle = The Simpsons
|seasonimage = 
|premiere = December 17, 1989
|finale = May 13, 1990
|episodecount = 13
|notable = 
|previousseason = Season One
|nextseason = Season Two
|
}}
{{stub}}
The first season of The Simpsons premiered on December 17, 1989 and concluded on May 13, 1990 with 13 episodes.

==Episodes==
{{eptable-start}}
{{eptable-lt|The Simpsons|  1| 1 |The Simpsons Roasting on an Open Fire|December 17, 1989}}
{{eptable-dk|The Simpsons|  2| 2 |Bart The Genius|January 14, 1990}}
{{eptable-lt|The Simpsons|  3| 3 |Homer's Odyssey|January 21, 1990}}
{{eptable-dk|The Simpsons|  4| 4 |There's No Disgrace Like Home|January 28, 1990}}
{{eptable-lt|The Simpsons|  5| 5 |Bart The General|February 4, 1990}}
{{eptable-dk|The Simpsons|  6| 6 |Moaning Lisa|February 11, 1990}}
{{eptable-lt|The Simpsons|  7| 7 |The Call Of The Simpsons|February 18, 1990}}
{{eptable-dk|The Simpsons|  8| 8 |The Telltale Head|February 25, 1990}}
{{eptable-lt|The Simpsons|  9| 9 |Life On The Fast Lane|March 18, 1990}}
{{eptable-dk|The Simpsons| 10|10 |Homer's Night Out|March 25, 1990}}
{{eptable-lt|The Simpsons| 11|11 |The Crepes Of Wrath|April 15, 1990}}
{{eptable-dk|The Simpsons| 12|12 |Krusty Gets Busted|April 29, 1990}}
{{eptable-lt|The Simpsons| 13|13 |Some Enchanted Evening|May 13, 1990}}
|}

[[Category:The Simpsons/Episodes|*d]]

Which of course looks like this...

[edit] Episodes

# # Title Airdate
1 1 The Simpsons Roasting on an Open Fire December 17, 1989
2 2 Bart The Genius January 14, 1990
3 3 Homer's Odyssey January 21, 1990
4 4 There's No Disgrace Like Home January 28, 1990
5 5 Bart The General February 4, 1990
6 6 Moaning Lisa February 11, 1990
7 7 The Call Of The Simpsons February 18, 1990
8 8 The Telltale Head February 25, 1990
9 9 Life On The Fast Lane March 18, 1990
10 10 Homer's Night Out March 25, 1990
11 11 The Crepes Of Wrath April 15, 1990
12 12 Krusty Gets Busted Aprril 29, 1990
13 13 Some Enchanted Evening May 13, 1990

Pretty sweet! No more messing around with formatting, now you can just run this program. P.S. I hope to expand this from episode lists to much much more in the future, so stay tuned!

Just copy and paste this code below into a file named format.cpp...and get it compiled using g++ or Visual C++ or Borland or whatever compiler you want (this should work on any Operating System). The command to build it with g++ is:

g++ -Wall -g -O0 -c format.cpp -o format.o

But really any compiler should work with the default settings. Below is the code you need (save it as format.cpp)

[edit] The Code

// =============================================================================
//
//      Filename:  format.cpp
//
//   Description:  This will take an input file containing a list of episodes 
//                 from a show listed on epguides.com, and output an "episodes"
//                 file formatted for easy insertion into the TV IV Wiki.
//                 
//     IMPORTANT:  Make sure that the input file you use is formatted 
//                 correctly, as the program very much is dependent on the 
//                 formatting of the input file.
//
//       Version:  0.2
//       Created:  17 September 2005 05:25:31 EDT
//      Revision:  20 September 2005 fixed formatting and stack error
//      Compiler:  g++
//
//        Author:  Justin Randall, (jrrandall at gmail dot com)
//       Company:  TV IV Wiki
//
//    Copyright (c) 2005 by Justin Randall jrrandall at gmail dot com
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program; if not, write to the Free Software
//    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// =============================================================================
#include <fstream>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>

using namespace std;

int main(int argc, char **argv)
{
   // input file
   ifstream infile;
   // output file
   ofstream outfile;

   // test to make sure there is a correct amount of command line arguments
   if ((argc != 4) && (argc != 9))
   {
      cout << "Usage: format [show name] [input file] [output file]\n";
      cout << "OR:    format [show name] [input file] [output file] " \
         << "[Season#] [Premier] [Finale] [Episode Count] " \
         << "[Last Season?(y/n)]\n";
      cout << "Ex:    format \"The Simpsons\" infile.txt outfile.txt 1 " \
         <<"\"December 17, 1989\" \"May 13, 1990\" 13 n\n";
      cout << "The input file should be in your current working directory\n";
      cout << "If the destination file exists, it will be overwritten\n";
      return 0;
   }

   //Error checking for file input/output
   if ((argc == 4) || (argc == 9))
   {
      //make sure we can open the files
      infile.open(argv[2], ios::in);
      if (!infile)
      {
         cout << "Unable to open the file " << argv[2] << endl;
         return -1; //error
      }
      outfile.open(argv[3], ios::out);
      if (!outfile)
      {
         cout << "Unable to open the file " << argv[3] << endl;
         return -1; //error
      }
   }

   // count the number of lines in the infile (use in break for outfile)
   // Forward declaired variables for counting lines in file
   char value[1024] = {0};
   unsigned int count = 0;
   FILE *file = fopen(argv[2], "r");
   if(file == NULL)
   {
      //error
      return -1;
   }
   size_t read_count; // This stores the count of bytes read
   // Read 1024 bytes at a time
   while((read_count = fread(value, 1, 1024, file)) > 0) 
   {
      for(unsigned int i = 0; i < read_count; ++i)
      {
         // Increment count for each end of line character
         if(value[i] == '\n') 
            ++count;
      }
   }
   // output number of lines
   cout << "The input file has " << (count + 1) <<" lines." << endl;
   // close the file for line counting
   fclose(file);

   // header for outfile
   if (argc == 4) 
   {
      // build the header of the outfile
      outfile <<"==Episodes==" << endl;
      outfile <<"{{eptable-start}}" << endl;
   }
   else 
   {
      // compare the strings for argv[5], if they are between 1 and 20 (seasons)
      // then set the previous and next seasons accordingly
      std::string season = argv[4];
      std::string prev;
      std::string curr;
      std::string next;
      std::string ith;
      if ((strcmp(season.c_str(),"1")==0))
      {
         prev = "One";
         curr = "One";
         next = "Two";
         ith = "first";
      } else if ((strcmp(season.c_str(),"2")==0))
      {
         prev = "One";
         curr = "Two";
         next = "Three";
         ith = "second";
      } else if ((strcmp(season.c_str(),"3")==0))
      {
         prev = "Two";
         curr = "Three";
         next = "Four";
         ith = "third";
      } else if ((strcmp(season.c_str(),"4")==0))
      {
         prev = "Three";
         curr = "Four";
         next = "Five";
         ith = "fourth";
      } else if ((strcmp(season.c_str(),"5")==0))
      {
         prev = "Four";
         curr = "Five";
         next = "Six";
         ith = "fifth";
      } else if ((strcmp(season.c_str(),"6")==0))
      {
         prev = "Five";
         curr = "Six";
         next = "Seven";
         ith = "sixth";
      } else if ((strcmp(season.c_str(),"7")==0))
      {
         prev = "Six";
         curr = "Seven";
         next = "Eight";
         ith = "seventh";
      } else if ((strcmp(season.c_str(),"8")==0))
      {
         prev = "Seven";
         curr = "Eight";
         next = "Nine";
         ith = "eighth";
      } else if ((strcmp(season.c_str(),"9")==0))
      {
         prev = "Eight";
         curr = "Nine";
         next = "Ten";
         ith = "ninth";
      } else if ((strcmp(season.c_str(),"10")==0))
      {
         prev = "Nine";
         curr = "Ten";
         next = "Eleven";
         ith = "tenth";
      } else if ((strcmp(season.c_str(),"11")==0))
      {
         prev = "Ten";
         curr = "Eleven";
         next = "Tweleve";
         ith = "eleventh";
      } else if ((strcmp(season.c_str(),"12")==0))
      {
         prev = "Eleven";
         curr = "Twelve";
         next = "Thirteen";
         ith = "twelveth";
      } else if ((strcmp(season.c_str(),"13")==0))
      {
         prev = "Twelve";
         curr = "Thirteen";
         next = "Fifteen";
         ith = "thirteenth";
      } else if ((strcmp(season.c_str(),"14")==0))
      {
         prev = "Thirteen";
         curr = "Fourteen";
         next = "Fifteen";
         ith = "fourteenth";
      } else if ((strcmp(season.c_str(),"15")==0))
      {
         prev = "Fourteen";
         curr = "Fifteen";
         next = "Sixteen";
         ith = "fifteenth";
      } else if ((strcmp(season.c_str(),"16")==0))
      {
         prev = "Fifteen";
         curr = "Sixteen";
         next = "Seventeen";
         ith = "sixteenth";
      } else if ((strcmp(season.c_str(),"17")==0))
      {
         prev = "Sixteen";
         curr = "Seventeen";
         next = "Eighteen";
         ith = "seventeenth";
      } else if ((strcmp(season.c_str(),"18")==0))
      {
         prev = "Seventeen";
         curr = "Eighteen";
         next = "Nineteen";
         ith = "eighteenth";
      } else if ((strcmp(season.c_str(),"19")==0))
      {
         prev = "Eighteen";
         curr = "Ninteen";
         next = "Twenty";
         ith = "ninteenth";
      } else if ((strcmp(season.c_str(),"20")==0))
      {
         prev = "Nineteen";
         curr = "Twenty";
         next = "Twenty-One";
         ith = "twentith";
      }
      else // wow more then 20 seasons!
      {
         prev = "Unknown";
         curr = "Unknown";
         next = "Unknown";
         ith = "Unknown";
      }

      // check if this is the last season.
      std::string end = argv[8];
      if ((strcmp(end.c_str(),"y")==0))
      {
         next = "—";
      } else if ((strcmp(end.c_str(),"Y")==0))
      {
         next = "—";
      } else {
         // do nothing
      }

      // header info for the episode list
      outfile << "{{Season| season = Season " << curr << endl;
      outfile << "|showtitle = " << argv[1] << endl;
      outfile << "|seasonimage = " << endl;
      outfile << "|premiere = " << argv[5] << endl;
      outfile << "|finale = " << argv[6] << endl;
      outfile << "|episodecount = " << argv[7] << endl;
      outfile << "|notable = " << endl;
      outfile << "|previousseason = Season " << prev << endl;
      // is this the last season?
      if (((strcmp(end.c_str(),"y")==0)) || ((strcmp(end.c_str(),"y")==0)))
      {
         outfile << "|nextseason = " << next << endl;
      } else // nope, it's not
      {
         outfile << "|nextseason = Season " << next << endl;
      }
      outfile << "|" << endl;
      outfile << "}}" << endl;
      outfile << "{{stub}}" << endl;
      // final season output
      if (((strcmp(end.c_str(),"y")==0)) || ((strcmp(end.c_str(),"y")==0)))
      {
         outfile << "The " << ith << " and final season of " << argv[1] \
            << " premiered on " << argv[5] << " and concluded on " \
            << argv[6] << " with " << argv[7] << " episodes.\n" << endl;
      }
      else // normal output
      {
         outfile << "The " << ith << " season of " << argv[1] \
            << " premiered on " << argv[5] << " and concluded on " \
            << argv[6] << " with " << argv[7] << " episodes.\n" << endl;
      }
      // build the header of the outfile
      outfile <<"==Episodes==" << endl;
      outfile <<"{{eptable-start}}" << endl;
   }

   // set linenum for odd/even line processing
   int linenum = 0;

   // build the body of the outfile
   while(!infile.eof())
   {
      // declare line
      string Line;
      // get line
      std::getline(infile, Line);
      // increment linenum for file processing
      linenum++;
      // default if size of Line is less then position 40
      // NO BLANK LINES
      if ((Line.size() < 40) && (Line.size() > 1)) {  // set Line to garbage
         Line = "  0.   0- 0       0000      1 Jan 00   UNKNOWN EPISODE";
      } else if (Line.size() <= 1) { // break out because it's blank
         break;
      } else { // made it! now process the line
      }
      // get line positions on infile
      string title = Line.substr(39); //Get position 39 until end of string
      string date = Line.substr(27, 9); //Get position 27 plus 9 characters
      string ep1 = Line.substr(0, 3); //Get position 0 plus 3 characters
      string ep2 = Line.substr(9, 3); //Get position 9 plus 3 characters
      string prod = Line.substr(19, 4); //Get position 19 plus 4 characters

      // odd lines are built like this
      if (linenum % 2 != 0)
      {
         outfile << "{{eptable-lt|" << argv[1] << "|" << ep1 << "|" \
            << ep2 << "|" << title << "|" << date << "}}" << endl;
      }
      // otherwise, it's an even line, so it's built like this
      else 
      {
         outfile << "{{eptable-dk|" << argv[1] << "|" << ep1 << "|" \
            << ep2 << "|" << title << "|" << date << "}}" << endl;
      }
      // break out when we reach the end of file to avoid a stack error
      if (infile.eof()) break;
   }

   // build the footer of the outfile
   outfile << "|}\n" << endl;
   outfile << "[[Category:" << argv[1] << "/Episodes|*d]]" << endl;
   cout << "End of file processing" << endl;

   // close the files that we used
   infile.close();
   outfile.close();
   return 0;
}

Hope you have a good time using this code, and let me know how it goes for you! --Randall 03:15, 18 Sep 2005 (EDT)

[edit] Contact Information

  • aim: randall711
  • email: jrrandall at gmail dot com


Personal tools
sponsored links