Solved

Make a listing option while making the webpages

Posted on 2004-03-28
6
282 Views
Last Modified: 2010-04-17
ok, I want to edit this javascript and add a new Var/function. I'm going to create a perl script that looks at the htm files made from this javascript and finds on the very first line <!--_STATE__--> and automaticly adds a link to the page on the main section, for this case Venues. So what I want to do when I initiate the script I would like it to prompt me to ( Do you want to add the (Y)States or the (N)First Letter for the Artist/Venues?) so it would change the output of _STATE_, reason I'm using this script for making artist/events. And the new PERL program will either input a link to the venue under the right section(State) or a link to the artist page under the right letter. SAVING ME HOURS!!!!

I know there are better scripts/ways, but for this case i'm working with legancy. I do plan to move to asp.net, but the need it now. not when I learn asp.net.

Thank you,
Caiapfas


var template = "C:\\aa\\venuetemplate.htm";
var list = "C:\\aa\\venues2.csv";
var dstFolder = "C:\\aa\\venues\\";

var fso =new ActiveXObject("Scripting.FileSystemObject");

//read template
var templFile = fso.OpenTextFile(template, 1);
var templText = templFile.ReadAll();
templFile.close();
WScript.StdOut.WriteLine("Template length is: " + templText.length);

//process venue list
var listFile = fso.OpenTextFile(list, 1);
var head=listFile.ReadLine(); //skip header
WScript.StdOut.WriteLine("Header line: " + head);
while(!listFile.AtEndOfStream) {
  var line=listFile.ReadLine();
  WScript.StdOut.WriteLine("processing line: " + line);
  var fields=line.split(",");   // Comma Delimited
//var fields=line.split("\t");  // Tabs
  WScript.StdOut.WriteLine("fields#: " + fields.length);
  try {
    var VenueID=fields[0];
    WScript.StdOut.WriteLine("venue id: " + fields[0]);
    var VenueName=fields[1];    
    WScript.StdOut.WriteLine("venue name: " + fields[1]);
    var VenueState=fields[2];    
    WScript.StdOut.WriteLine("venue name: " + fields[1]);
    var fname=VenueName.toLowerCase().replace(/ /g, "_") + ".htm";
    WScript.StdOut.WriteLine("output filename: " + fname);
    var dstFileFullname=fso.BuildPath(dstFolder, fname);
    WScript.StdOut.WriteLine("dest filename: " + dstFileFullname);
    var dstFile = fso.CreateTextFile(dstFileFullname, true);    
    dstFile.write(templText.replace(/_VENUE_NAME_/g, VenueName).replace(/_VENUE_ID_/g, VenueID).replace(/_STATE_/g, VenueState));
    dstFile.close();
   }
   catch(e) {
    WScript.echo("Error processing venue id " + VenueID + " with name '" + VenueName + "'");
   }
               
}
listFile.close();
0
Comment
Question by:Caiapfas
  • 4
  • 2
6 Comments
 
LVL 2

Author Comment

by:Caiapfas
ID: 10701185
a footnote (N)First Letter for the Artist/Venues?) a.k.a NO, would ignore column 3 and take the first letter of the Venue Name/Artist name...
0
 
LVL 11

Accepted Solution

by:
lbertacco earned 500 total points
ID: 10702625
Not very clear, maybe you should add examples of your desired output.
Anyway my understanding is that you want the script to EITHERr substitute _STATE_ with cvs column 3 OR with first letter of VenueName, basing on user input. If this is what you want the following code should work.

var template = "C:\\aa\\venuetemplate.htm";
var list = "C:\\aa\\venues2.csv";
var dstFolder = "C:\\aa\\venues\\";

var fso =new ActiveXObject("Scripting.FileSystemObject");

//read template
var templFile = fso.OpenTextFile(template, 1);
var templText = templFile.ReadAll();
templFile.close();
WScript.StdOut.WriteLine("Template length is: " + templText.length);

var WshShell = WScript.CreateObject("WScript.Shell");
var indexSel=WshShell.Popup("Do you want to add the (Y)States or the (N)First Letter for the Artist/Venues?",0,"Choose one",4+32);

//process venue list
var listFile = fso.OpenTextFile(list, 1);
var head=listFile.ReadLine(); //skip header
WScript.StdOut.WriteLine("Header line: " + head);
while(!listFile.AtEndOfStream) {
  var line=listFile.ReadLine();
  WScript.StdOut.WriteLine("processing line: " + line);
  var fields=line.split(",");   // Comma Delimited
//var fields=line.split("\t");  // Tabs
  WScript.StdOut.WriteLine("fields#: " + fields.length);
  try {
    var VenueID=fields[0];
    WScript.StdOut.WriteLine("venue id: " + VenueID);
    var VenueName=fields[1];    
    WScript.StdOut.WriteLine("venue name: " + VenueName);
    var VenueState=fields[2];    
    WScript.StdOut.WriteLine("venue state: " + VenueState);
    var fname=VenueName.toLowerCase().replace(/ /g, "_") + ".htm";
    WScript.StdOut.WriteLine("output filename: " + fname);
    var dstFileFullname=fso.BuildPath(dstFolder, fname);
    WScript.StdOut.WriteLine("dest filename: " + dstFileFullname);
    var replState=indexSel==6 ? VenueState : fname.substr(0,1);
    var dstFile = fso.CreateTextFile(dstFileFullname, true);    
    dstFile.write(templText.replace(/_VENUE_NAME_/g, VenueName).replace(/_VENUE_ID_/g, VenueID).replace(/_STATE_/g, replState));
    dstFile.close();
   }
   catch(e) {
    WScript.echo("Error processing venue id " + VenueID + " with name '" + VenueName + "'");
   }
               
}
listFile.close();
0
 
LVL 2

Author Comment

by:Caiapfas
ID: 10704804
Thank you,

you hit it right on the head, a quick side question...is this just javascript? cause I see things i dont recongnize..
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 11

Expert Comment

by:lbertacco
ID: 10704840
Javascript and Windows Scripting Host
0
 
LVL 2

Author Comment

by:Caiapfas
ID: 10704952
cool, I'm learning perl right now, but I seem to be trying to much at once, altought the results are rolling in, now I have the means to make thousands of custom pages but I need a way to add them the a main section(page). I don't think javascript can do this, so I tried my infant perl skills, ouch would ya mind taking a look?

http://www.experts-exchange.com/Programming/Q_20935310.html

after this I'm on easy street just need to read, read, read and soon asp.net adventures begin..
0
 
LVL 2

Author Comment

by:Caiapfas
ID: 10709031
lbertacco,

Do you think I could get you email address, mine it support@cdatasolutions.com << you can email if you want to keep it off EE..I want to add you to the

// Version 1.3 - PageBuilder
// Script Design by lbertacco

before I hand it over to my friend and I wouldnt mind having it..=}
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
This code tracks birthdays 3 82
iframe detection of parent window scale 20 85
Help Required 2 39
C qsort compare function issue 6 17
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

838 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question