Caiapfas
asked on
.js script edit/help, I need it to take the "STATE" column out of a .csv file and input it in every .htm file for a perl script..
Ok, Background:
With some excellant help, I was able to make a script that takes data out of columns in a .csv file and changes a htm template and then saves it under the venue name(all lower case and spaces replaced with _'s)
Now I need it to input the venue state in <!--VENUE STATE--> format at the VERY top of every page so a perl script can come through and read it and input it on this page as links( http://www.ticketstogo.com/venues/states/index.htm )under the appropriate state which will also have the <!--VENUE STATE--> for recognition and inserting of the link..
addendum : I know other scripting languages could do all this much quicker, and I know htm is a old and dying language, but for this project I have chosen it, so plz .js and .htm help only.
The .js file that reads the .csv file and changes the template.....All i need it to do now is insert <!--VENUE STATE--> at the top of all the pages it creates.
-------------------------- ---------- ---------- ---------- ---------- -------
var template = "C:\\aa\\venuetemplate.htm ";
var list = "C:\\aa\\venues.csv";
var dstFolder = "C:\\aa\\venues\\";
var fso =new ActiveXObject("Scripting.F ileSystemO bject");
//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.AtEndOfStr eam) {
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 fname=VenueName.toLowerCas e().replac e(/ /g, "_") + ".htm";
WScript.StdOut.WriteLine(" output filename: " + fname);
var dstFileFullname=fso.BuildP ath(dstFol der, fname);
WScript.StdOut.WriteLine(" dest filename: " + dstFileFullname);
var dstFile = fso.CreateTextFile(dstFile Fullname, true);
dstFile.write(templText.re place(/_VE NUE_NAME_/ g, VenueName).replace(/_VENUE _ID_/g, VenueID));
dstFile.close();
}
catch(e) {
WScript.echo("Error processing venue id " + VenueID + " with name '" + VenueName + "'");
}
}
listFile.close();
the .cvs file
http://www.ticketstogo.com/aadownload/venues.csv
and the template
http://www.ticketstogo.com/aadownload/venuetemplate.htm
With some excellant help, I was able to make a script that takes data out of columns in a .csv file and changes a htm template and then saves it under the venue name(all lower case and spaces replaced with _'s)
Now I need it to input the venue state in <!--VENUE STATE--> format at the VERY top of every page so a perl script can come through and read it and input it on this page as links( http://www.ticketstogo.com/venues/states/index.htm )under the appropriate state which will also have the <!--VENUE STATE--> for recognition and inserting of the link..
addendum : I know other scripting languages could do all this much quicker, and I know htm is a old and dying language, but for this project I have chosen it, so plz .js and .htm help only.
The .js file that reads the .csv file and changes the template.....All i need it to do now is insert <!--VENUE STATE--> at the top of all the pages it creates.
--------------------------
var template = "C:\\aa\\venuetemplate.htm
var list = "C:\\aa\\venues.csv";
var dstFolder = "C:\\aa\\venues\\";
var fso =new ActiveXObject("Scripting.F
//read template
var templFile = fso.OpenTextFile(template,
var templText = templFile.ReadAll();
templFile.close();
WScript.StdOut.WriteLine("
//process venue list
var listFile = fso.OpenTextFile(list, 1);
var head=listFile.ReadLine(); //skip header
WScript.StdOut.WriteLine("
while(!listFile.AtEndOfStr
var line=listFile.ReadLine();
WScript.StdOut.WriteLine("
var fields=line.split(","); // Comma Delimited
//var fields=line.split("\t"); // Tabs
WScript.StdOut.WriteLine("
try {
var VenueID=fields[0];
WScript.StdOut.WriteLine("
var VenueName=fields[1];
WScript.StdOut.WriteLine("
var fname=VenueName.toLowerCas
WScript.StdOut.WriteLine("
var dstFileFullname=fso.BuildP
WScript.StdOut.WriteLine("
var dstFile = fso.CreateTextFile(dstFile
dstFile.write(templText.re
dstFile.close();
}
catch(e) {
WScript.echo("Error processing venue id " + VenueID + " with name '" + VenueName + "'");
}
}
listFile.close();
the .cvs file
http://www.ticketstogo.com/aadownload/venues.csv
and the template
http://www.ticketstogo.com/aadownload/venuetemplate.htm
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, let me explain a little more, there are 3 columns in the .csv file
VenueID VenueName State
right now the script it taking(line by line) VenueID and looking in the template and replaceing _VEUNE_ID_
then it taking VeuneName and replaceing _VENUE_NAME_
Now, what I would like to add is State handleing..
Take State column 3 and replace _STATE_ in the htm/template file.
VenueID VenueName State
right now the script it taking(line by line) VenueID and looking in the template and replaceing _VEUNE_ID_
then it taking VeuneName and replaceing _VENUE_NAME_
Now, what I would like to add is State handleing..
Take State column 3 and replace _STATE_ in the htm/template file.
var i = 0;
while(!listFile.AtEndOfStr eam) {
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 fname=VenueName.toLowerCas e().replac e(/ /g, "_") + ".htm";
WScript.StdOut.WriteLine(" output filename: " + fname);
var dstFileFullname=fso.BuildP ath(dstFol der, fname);
WScript.StdOut.WriteLine(" dest filename: " + dstFileFullname);
var dstFile = fso.CreateTextFile(dstFile Fullname, true);
if(i==0){
dstFile.write("<!--VENUE STATE-->\n");
}
dstFile.write(templText.re place(/_VE NUE_NAME_/ g, VenueName).replace(/_VENUE _ID_/g, VenueID));
dstFile.close();
}
catch(e) {
WScript.echo("Error processing venue id " + VenueID + " with name '" + VenueName + "'");
}
i++;
}
while(!listFile.AtEndOfStr
var line=listFile.ReadLine();
WScript.StdOut.WriteLine("
var fields=line.split(","); // Comma Delimited
//var fields=line.split("\t"); // Tabs
WScript.StdOut.WriteLine("
try {
var VenueID=fields[0];
WScript.StdOut.WriteLine("
var VenueName=fields[1];
WScript.StdOut.WriteLine("
var fname=VenueName.toLowerCas
WScript.StdOut.WriteLine("
var dstFileFullname=fso.BuildP
WScript.StdOut.WriteLine("
var dstFile = fso.CreateTextFile(dstFile
if(i==0){
dstFile.write("<!--VENUE STATE-->\n");
}
dstFile.write(templText.re
dstFile.close();
}
catch(e) {
WScript.echo("Error processing venue id " + VenueID + " with name '" + VenueName + "'");
}
i++;
}
ASKER
no I dont want it to write <!--Venue state-->!!!!
I only want it to replace _STATE_ in the template, like it does _Venue_ID_ and _VENUENAME_, before it saves the file.
so it replaces _STATE_ with the correct state for that venue name and venue id....look at the csv file...
I only want it to replace _STATE_ in the template, like it does _Venue_ID_ and _VENUENAME_, before it saves the file.
so it replaces _STATE_ with the correct state for that venue name and venue id....look at the csv file...
ASKER
the benefit of having it find and replace _STATE_ is I can have it put the correct state , anywhere on the page, like I can for _VENUE_NAME_ and _VENUE_ID_
ASKER
so in effect, I dont want to change the script at all, just add a handling for column 3 a.k.a States..
the script searchs the .csv file and then takes the data from column 1 (Venue ID) and does a search and replace in the template for _VENUE_ID_
then
for column 2 (VenueName) does a search and replace for _VENUE_NAME_
and NOW for column 3 (STATES) does a search and replace for _STATES_ in the template(NOTE: unless there is no third column then it ingnores this VAR) then saves the template as the VENUE name in all lower case and replaces spaces with _'s
I don't want the original script changed, unless necessary... just the new var added..
the script searchs the .csv file and then takes the data from column 1 (Venue ID) and does a search and replace in the template for _VENUE_ID_
then
for column 2 (VenueName) does a search and replace for _VENUE_NAME_
and NOW for column 3 (STATES) does a search and replace for _STATES_ in the template(NOTE: unless there is no third column then it ingnores this VAR) then saves the template as the VENUE name in all lower case and replaces spaces with _'s
I don't want the original script changed, unless necessary... just the new var added..
ASKER
so the only thing I need help with is
column 3 (STATES) I want it to do search and replace for _STATES_ in the template(NOTE: unless there is no third column then it ingnores this VAR)
column 3 (STATES) I want it to do search and replace for _STATES_ in the template(NOTE: unless there is no third column then it ingnores this VAR)
ASKER
ok, fixed it
var template = "C:\\aa\\venuetemplate.htm ";
var list = "C:\\aa\\venues2.csv";
var dstFolder = "C:\\aa\\venues\\";
var fso =new ActiveXObject("Scripting.F ileSystemO bject");
//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.AtEndOfStr eam) {
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.toLowerCas e().replac e(/ /g, "_") + ".htm";
WScript.StdOut.WriteLine(" output filename: " + fname);
var dstFileFullname=fso.BuildP ath(dstFol der, fname);
WScript.StdOut.WriteLine(" dest filename: " + dstFileFullname);
var dstFile = fso.CreateTextFile(dstFile Fullname, true);
dstFile.write(templText.re place(/_VE NUE_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();
is this the proper way ???is the script ok?
var template = "C:\\aa\\venuetemplate.htm
var list = "C:\\aa\\venues2.csv";
var dstFolder = "C:\\aa\\venues\\";
var fso =new ActiveXObject("Scripting.F
//read template
var templFile = fso.OpenTextFile(template,
var templText = templFile.ReadAll();
templFile.close();
WScript.StdOut.WriteLine("
//process venue list
var listFile = fso.OpenTextFile(list, 1);
var head=listFile.ReadLine(); //skip header
WScript.StdOut.WriteLine("
while(!listFile.AtEndOfStr
var line=listFile.ReadLine();
WScript.StdOut.WriteLine("
var fields=line.split(","); // Comma Delimited
//var fields=line.split("\t"); // Tabs
WScript.StdOut.WriteLine("
try {
var VenueID=fields[0];
WScript.StdOut.WriteLine("
var VenueName=fields[1];
WScript.StdOut.WriteLine("
var VenueState=fields[2];
WScript.StdOut.WriteLine("
var fname=VenueName.toLowerCas
WScript.StdOut.WriteLine("
var dstFileFullname=fso.BuildP
WScript.StdOut.WriteLine("
var dstFile = fso.CreateTextFile(dstFile
dstFile.write(templText.re
dstFile.close();
}
catch(e) {
WScript.echo("Error processing venue id " + VenueID + " with name '" + VenueName + "'");
}
}
listFile.close();
is this the proper way ???is the script ok?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
lbertacco,
Thank you so much, I learned how to add it to the script from your examples, I learn best that way.
will you check out this question? https://www.experts-exchange.com/questions/20935392/Make-a-listing-option-while-making-the-webpages.html
Thank you so much, I learned how to add it to the script from your examples, I learn best that way.
will you check out this question? https://www.experts-exchange.com/questions/20935392/Make-a-listing-option-while-making-the-webpages.html
ASKER
ok
im trying to split the points betwen kavar and ibertaco, but i keep getting this error
Error
You may not Split Points for this question
im trying to split the points betwen kavar and ibertaco, but i keep getting this error
Error
You may not Split Points for this question
ASKER
and it actually places VENUS STATE with the right venues state.
example : <!-- Texas --> for Hobby Center