Solved

I need a AUTOMATIC webpage maker..FAST

Posted on 2004-03-26
35
1,229 Views
Last Modified: 2013-12-03
Ok, A little background : My site http://www.ticketstogo.com is a Online Event Ticket Website.
I need to have pages to every venue.. (But making everypage is slowwwwwww)
I have TRIED , TRIED and RETRIED to do this with Batch files, and javascript files which I'm a novice at..
I have a template at http://www.ticketstogo.com/venues/hobby_center.html
-----------------------------------------
and  a .cvs file with ALL(4000+) the link/venue ID's in (column A)
Example :
here is the link that displays the tickets in an IFrame
http://www.eventinventory.com/search/byevent.cfm?client=1555&restart=yes&v=2562
the VERY end is the link/venue ID >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-----------------------------------------
Also, the .cvs file has ALL the venues names(4000+)..in (column B)

So I need a Javascript file...or make be a Batch file that will do a find and replace on my template
c:\web\venuetemplate.htm
and find "XOX" and replace it with the venue name(Column B)
then change the end of the link in the IFrame with the VenueID(Column A)
and then copy and rename the venuetemplate.htm to c:\web\venues\VENUENAME.HTM
the rename needs to be in all lower case and spaces replaced with _ .... All tries to make this script has failed with errors, I'm to new to javascript..(extrnal file .js)

I'll give 1000 points easy!!

Thank YOU so much!!!!
Caiapfas
0
Comment
Question by:Caiapfas
  • 19
  • 12
  • 3
  • +1
35 Comments
 
LVL 3

Expert Comment

by:aflat362
Comment Utility
Good lord.

You are in need of a real web programming language like ASP, JSP / Java, ColdFusion.

0
 
LVL 2

Author Comment

by:Caiapfas
Comment Utility
I'm sure jsp = .js can do it. I need this to be a stand alone script. This is not for the web, only for the page creation on my pc.
0
 

Expert Comment

by:jodyman
Comment Utility
Perl would work great at this.  I used to create 7000 dynamically static webpages a day in only 4 minutes using a .csv file from Excel.  You can do this on your local machine and then FTP your files to the server.
0
 
LVL 2

Author Comment

by:Caiapfas
Comment Utility
GREAT, can you help me write this script i'm ok in jsp(novice). but perl = 0
0
 

Expert Comment

by:jodyman
Comment Utility
I need a template, and the .csv file.
0
 
LVL 2

Author Comment

by:Caiapfas
Comment Utility
ok, np....but how will i run the perl file? I rather it be .js file...I dont have perl installed...
email address?
0
 

Expert Comment

by:jodyman
Comment Utility
What you need:
        Download Perl: http://downloads.activestate.com/ActivePerl/src/5.8/AP809_source.zip
        Load it on your computer

Then we can get started.
0
 
LVL 2

Author Comment

by:Caiapfas
Comment Utility
ok, where do i send the files?
0
 
LVL 11

Expert Comment

by:lbertacco
Comment Utility
Yes it can be done in .js. And also in Perl which is surely a nicer and more powerful language, however it doesn't come standard with Windows but that's not an issue here. You can even just write a VBA macro in excel for this.

Anyway, can you make the cvs and html template available for download on some of your web sites?
0
 
LVL 2

Author Comment

by:Caiapfas
Comment Utility
Thank you lbertacco!!!! You always the person I look for when it comes to .js
I really want it in .js its the language I'm most conformtable with...althought I know their are better ways and faster...

here is the .cvs file!
http://www.ticketstogo.com/aadownload/venues.csv

and the template
http://www.ticketstogo.com/aadownload/venuetemplate.htm
0
 
LVL 11

Expert Comment

by:lbertacco
Comment Utility
Something like this should do it:

var template = "C:\\template.htm";
var list = "C:\\cvs.txt";
var dstFolder = "E:\\tmp\\";

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

//read template
var templFile = fso.OpenTextFile(template, 1);
var templText = templFile.ReadAll();
templFile.close();

//process venue list
var listFile = fso.OpenTextFile(list, 1);
while(!listFile.AtEndOfStream) {
      var line=listFile.ReadLine();
      var fields=line.split(";");
      var venueID=fields[0];
      var venueName=fields[1];      
      var fname=venueName.toLowerCase().replace(/ /g, "_") + ".htm";
      var dstFile = fso.CreateTextFile(fso.BuildPath(dstFolder, fname), true);
      dstFile.write(templText.replace(/_VENUE_NAME_/g, venueName).replace(/_VENUE_ID_/g, venueID));
      dstFile.close();
}
listFile.close();


Assumptions (that can be easily modified, anyway):
- the cvs file has venueID in first column, venueName in second column, separated by semicolon
- all cvs lines are data lines (no header, no empty lines)
- the strings searched in the template are _VENUE_NAME_ and _VENUE_ID_ (replaced with repsective values) and not XOX.
0
 
LVL 11

Expert Comment

by:lbertacco
Comment Utility
I posted the code before seeing you file, so there are a few things to be changed...give me a few minutes
0
 
LVL 11

Expert Comment

by:lbertacco
Comment Utility
Well almost there. Add line:
listFile.ReadLine(); //skip header
just before the "while" line.
Then replace ; with , in the line: var fields=line.split(";");
Set proper filenames in the first 3 lines
And finally modify your template using macros _VENUE_NAME_ and _VENUE_ID_ where you want them replaced.
Does it work?
What about the third cvs column (the state) ?
0
 
LVL 2

Author Comment

by:Caiapfas
Comment Utility
Also,  I save the .cvs file as text right?
and I made the request changes to the .html file.._VENUE_NAME_ and _VENUE_ID_

do you mind if we open 3 questions after this, 500 a peice?


Thank you
Caiapfas
0
 
LVL 2

Author Comment

by:Caiapfas
Comment Utility
i'm getting runtime error ... VenueName is null or not a object?


var template = "C:\\web\\AutoPageBuilder\\Templates\\venuetemplate.htm";
var list = "C:\\web\\AutoPageBuilder\\Data\\venues.txt";
var dstFolder = "C:\\web\\AutoPageBuilder\\Template\\venues\\";

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

//read template
var templFile = fso.OpenTextFile(template, 1);
var templText = templFile.ReadAll();
templFile.close();

//process venue list
var listFile = fso.OpenTextFile(list, 1);
listFile.ReadLine(); //skip header
while(!listFile.AtEndOfStream) {
     var line=listFile.ReadLine();
     var fields=line.split(",");
     var VenueID=fields[0];
     var VenueName=fields[1];    
     var fname=VenueName.toLowerCase().replace(/ /g, "_") + ".htm";
     var dstFile = fso.CreateTextFile(fso.BuildPath(dstFolder, fname), true);
     dstFile.write(templText.replace(/_VENUE_NAME_/g, VenueName).replace(/_VENUE_ID_/g, VenueID));
     dstFile.close();
}
listFile.close();
0
 
LVL 2

Author Comment

by:Caiapfas
Comment Utility
lbertacco,

i'm getting runtime error ... VenueName is null or not a object?...

any help my friend..

Thank you,
Caiapfas
0
 
LVL 2

Author Comment

by:Caiapfas
Comment Utility
DrWarezz, I read the user agareement
http://www.experts-exchange.com/memberAgreement.jsp


I didnt see anything about not posting scripts?
could you point it out for me, knowing my dumba** i misread/over read it

Thank you,
Caiapfas
0
IT, Stop Being Called Into Every Meeting

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
Comment Utility
What's the full error information? Do you get any file created?

Beware that you have a few venues that translates to invalid filenames.
Among these:
first one: has empty name
second one: *** All Venues ***. Stars are not allowed in filenames
venue id 2128:colons are not allowed in filenames
How do you want to handle these? Either we skip them or change the naming convention or you fix them in the csv file.
0
 
LVL 11

Expert Comment

by:lbertacco
Comment Utility
Maybe this helps:
...
//process venue list
var listFile = fso.OpenTextFile(list, 1);
listFile.ReadLine(); //skip header
while(!listFile.AtEndOfStream) {
  var line=listFile.ReadLine();
  var fields=line.split(",");
  try {
    var VenueID=fields[0];
    var VenueName=fields[1];    
    var fname=VenueName.toLowerCase().replace(/ /g, "_") + ".htm";
    var dstFile = fso.CreateTextFile(fso.BuildPath(dstFolder, fname), true);
    dstFile.write(templText.replace(/_VENUE_NAME_/g, VenueName).replace(/_VENUE_ID_/g, VenueID));
    dstFile.close();
   }
   catch(e) {
    WScript.echo("Error processing venue id " + VenueID + " with name '" + VenueName + "'");
   }
                 
}
listFile.close();
0
 
LVL 2

Author Comment

by:Caiapfas
Comment Utility
skip the bad lines,

error message :

(20,2)Microsoft Jscript runtime error : "VenueName" is null or not an object
0
 
LVL 2

Author Comment

by:Caiapfas
Comment Utility
ok now, its getting stuck in a loop going so fast i cant read it

Error processing venue id (numder) (name) (state) with name 'undifined'
over and over and over and over untill its all the way throught the csv file
0
 
LVL 11

Expert Comment

by:lbertacco
Comment Utility
If you still get the error, try adding after line: var line=listFile.ReadLine();
WScript.StdOut.WriteLine("processing line: " + line);
then run the script with
CSCRIPT scripname.js
What output do you get? Do you get any file correctly created?
(maybe we have a different cscript version. I have cscript v5.6. Run cscript/? to find out)

0
 
LVL 11

Expert Comment

by:lbertacco
Comment Utility
Do you see the venue IDs? Just not the venue names?
Do you use commas to separate the values in the csv files?
0
 
LVL 2

Author Comment

by:Caiapfas
Comment Utility
no its tab delimited.
 yes, i see the names and id's in the errors...
0
 
LVL 11

Expert Comment

by:lbertacco
Comment Utility
Well the script assumed commas as separators (your file from http://www.ticketstogo.com/aadownload/venues.csv used commas).
For tabs replace
  var fields=line.split(",");
with
  var fields=line.split("\t");
0
 
LVL 2

Author Comment

by:Caiapfas
Comment Utility
so do i make it read the .csv file or save it as a text file?
not instead of this
Error Proccing Venue Id (whatever) with name '(whatever)' with name 'undifined'
I'm geeting
Error Proccing Venue Id (whatever) with name '(whatever)'

it goes through EVERYLINE , before it stops


i'm running cscript 5.6 also
0
 
LVL 2

Author Comment

by:Caiapfas
Comment Utility
i saved it as a text file , and right now making it read the .txt file, should i make it read the .csv?
0
 
LVL 11

Expert Comment

by:lbertacco
Comment Utility
The csv file you posted online was fine (it used commas as sperator so you need to use split(",") for it).
If you keep getting errors, please post online exactly the files you are using (template, csv, script).


0
 
LVL 2

Author Comment

by:Caiapfas
Comment Utility
0
 
LVL 2

Author Comment

by:Caiapfas
Comment Utility
lbertacco,

Any progress? I have been trying on this end ,but keep getting the same errors..

Caiapfas
0
 
LVL 2

Author Comment

by:Caiapfas
Comment Utility
lbertacco, Also is it possible to have a .js file to resize images and save them making them smaller? If it is I will open a new question.

Thank you, for all you help.
any luck on the script?
0
 
LVL 11

Accepted Solution

by:
lbertacco earned 500 total points
Comment Utility
Caiapfas,
It worked perfectly on my machine with your files.
Just a few thoghts:
- did you create the destination folder C:\web\AutoPageBuilder\Template\venues\ (the script won't do it) ?
- do you run the script with CSCRIPT? If you keep the line "WScript.StdOut.WriteLine.." and just run the script without CSSCRIPT you would get error : "The handle is invalid" on line 17. You need to run it with cscript when you have wscript.stdout...
- normal output of the script (when run with cscript and keeping line wscript.stdout.writeline) is:
processing line: 3254,,
processing line: 2012,*** All Venues ***,
Error processing venue id 2012 with name '*** All Venues ***'
processing line: 1980,14th Street Playhouse,Georgia
processing line: 135,1st Mariner Arena,Maryland
processing line: 3001,20th Century Theater,Ohio
processing line: 1986,2345 E. Colorado Blvd.,California
processing line: 2437,300 Commerce Street,Texas
....
- if you still get errors with your script, please report the WHOLE message including error description, line number, char and code. Also, since we might have slightly different scripts, please tell me which line is causing the errror.
- another version of the script follows with much more debugging output
- if with image resize you mean just specifying a different width/height in an html file it should be possible. if you want to actually modify the image that's almost not possible.

var template = "C:\\web\\AutoPageBuilder\\Templates\\venuetemplate.htm";
var list = "C:\\web\\AutoPageBuilder\\Data\\venues.csv";
var dstFolder = "C:\\web\\AutoPageBuilder\\Template\\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(",");
  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.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));
    dstFile.close();
   }
   catch(e) {
    WScript.echo("Error processing venue id " + VenueID + " with name '" + VenueName + "'");
   }
               
}
listFile.close();

Output of this script is:
C:\>cscript venuePageBuilder.js
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

Template length is: 10536
Header line: VenueID,VenueName,State
processing line: 3254,,
fields#: 3
venue id: 3254
venue name:
output filename: .htm
dest filename: E:\tmp\.htm
processing line: 2012,*** All Venues ***,
fields#: 3
venue id: 2012
venue name: *** All Venues ***
output filename: ***_all_venues_***.htm
dest filename: E:\tmp\***_all_venues_***.htm
Error processing venue id 2012 with name '*** All Venues ***'
processing line: 1980,14th Street Playhouse,Georgia
fields#: 3
venue id: 1980
venue name: 14th Street Playhouse
output filename: 14th_street_playhouse.htm
dest filename: E:\tmp\14th_street_playhouse.htm
...
0
 
LVL 2

Author Comment

by:Caiapfas
Comment Utility
It works perfect, thanks again, my friend
0
 
LVL 2

Author Comment

by:Caiapfas
Comment Utility
3400 pages in 1 min, oo yea....thank you, thank you
I can change the templates layout anytime as long as i keep
_VENUE_NAME_ and _VEUNE_ID_
right?

0
 
LVL 11

Expert Comment

by:lbertacco
Comment Utility
Sure :-)
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

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.
A short article about problems I had with the new location API and permissions in Marshmallow
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 …

743 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

10 Experts available now in Live!

Get 1:1 Help Now