Solved

Make a listing option while making the webpages

Posted on 2004-03-28
6
283 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Definitions and default visual studio colors 5 74
maven disable workspace resolution 1 41
VB.NET String Settings and Temp Folder Question 3 71
$_GET call between URL 3 43
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

733 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