Solved

Make a listing option while making the webpages

Posted on 2004-03-28
6
271 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Reading variable length EBCDIC in SAS 9 78
noX challenge 17 76
VB6 Compile Compatibility Issue 4 38
Hide vba in gp 7 48
Purpose To explain how to place a textual stamp on a PDF document.  This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent.  Watermark’s may be text or graph…
This is about my first experience with programming Arduino.
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 …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

762 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now