Avatar of Caiapfas
Caiapfas asked on

help : Making a automatic link maker

Ok, heres what I'm trying to do, I have thousands of htm, webpages in diffrent directories and I have to link to them on main pages...I'm trying to make a PERL script to steam line my work..

Example http://www.ticketstogo.com/venues/  directory has 3000+ pages and I have to manually add links to
http://www.ticketstogo.com/venues/states/index.htm    <<< one by one , under the correct state.
One each page in the venue section I have the state that that page/venue belongs in example : <!-- Texas --> on the first line of every page. so I need the script to take that data and make links on the http://www.ticketstogo.com/venues/states/ under the right state.

And for the concerts section I would like it to scan the http://www.ticketstogo.com/concerts/ directory and at the top of everypage on the first line I have the first letter of the artist name ..example : <!-- F --->, then take that and input a link to that page under the right letter on page : http://www.ticketstogo.com/concerts/

And there should be a Admin panel where I can add new directories/urls and pick, by state, by first letter. then the location of the links/main page , where the links will be added.

So what I need is a PERL program that can scan the directory and make links to the the pages on a main page, by seeing <!-- "STATE NAME--> or <!--- "LETTER"--> and inserting the link, one after another, on and on, untill its done, saving me hours in the progress...
example of a script that scans and see a <!-- bla bla bla --> and inserts a link..http://www.ccds.addr.com/wrc/links/addalink.htm
My script ended in ruins, I read half of my Perl : A Beginners Guide and I think I'm a perl god...I feel painfully crushed by my attempt..j/k

I know there are better scripting laguages out there, meaning having thousands of htm files, but right now i need this to work , untill our asp.net venture is rdy..which could be months, so please just help with this issues ..
Programming

Avatar of undefined
Last Comment
Caiapfas

8/22/2022 - Mon
ASKER
Caiapfas

in effect the only thing this PERL script would do is scan a directory, and then a page(main page) for matching <!-- blablabla, blabla --> tags then insert a link to the page , under the right <!-- -->.

Example , scaning concert/ <folder finds Greenday, greenday.htm has <!-- G, Greenday --> so after its done scanning the entire directory and making a flat file database, it now scans the page(main links page) and finds G's and there is the <!-- G --> so it inserts a link the greenday, Greenday (http://www.mysite.com/concerts/greenday.htm) and it gets the title for the link from the <!-- G, Greenday --> the second part of the hidden comment at the top of the page.
lbertacco

This a small perl script to do it:

#!/usr/bin/perl

$dir="/win/tmp";
$wdir="ven";
$indextpl = "/win/indextpl.htm";
$indexhtm = "/win/index.htm";

# read venue files
opendir(DH, $dir) or die "Can't open $dir for reading: $!";
while(defined($file=readdir(DH))) {
  next unless $file =~ /\.htm$/i;
  open(FILE, "<$dir/$file") or die "Can't open $file for reading: $!";
  $ven{$1}{$2} = "$wdir/$file" if <FILE> =~ /^\<\!-- (.*), (.*) --\>$/;
  close(FILE);
}

# process template
open(STDIN, "<$indextpl") or die "Can't open $indextpl for reading: $!";
open(STDOUT, ">$indexhtm") or die "Can't open $indexhtm for writing: $!";
while(<>) {
  if(/^\<\!-- (.*) --\>$/) {
    print map {"<A href=\"$ven{$1}{$_}\">$_</A><BR>\n"} sort keys %{$ven{$1}};
  } else {
    print;
  }
}

$dir is the directory with the html pages (e.g. c:\\concert)
$wdir is a path the path to be inserted in the URLs (e.g. /whatever/concerts)
$indextpl is the index template file (e.g. C:\\test\\index.tpl)
$indexhtm is the final index file (e.g. c:\\test\\index.htm)
The script has been tested under unix. For WIn32 you might need to change the slashes in paths from / to \\, and also the perl path in the first line.
ASKER
Caiapfas

lbertacco,

does it only match
example
<-- anything, right here -->

also is this the flat file database? $indextpl is the index template file (e.g. C:\\test\\index.tpl)

and can it be a txt file?
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER
Caiapfas

and if it does match the <!-- whatever, to whatever --> I can use it for many diffrent app.
right?

Thank you,
Caiapfas
lbertacco

It expects the first line of each htm file to be like
<!-- index key, full name -->

then it inserts all the "full names" asscoiated with a given "index key" in the template whenever it finds a line (exactly like)
<!-- index key -->
in the template
the matching of index key is case sensitive (this can be changed) and there must be nothing else in the line (not even extra blanks) (this can be improved).

It doesn't store any flat file index, just keeps it in RAM. All files are expected to be text files.
ASKER
Caiapfas

explain..

All files are expected to be text files?

also, i tired making it non case sensitive  , but failed any help

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
lbertacco

text, that is you can e.g.open them in notepad. This includes html files of course.
To make it case insensitive, change line
$ven{$1}{$2} = "$wdir/$file" if <FILE> =~ /^\<\!-- (.*), (.*) --\>$/;
to
$ven{lc($1)}{$2} = "$wdir/$file" if <FILE> =~ /^\<\!-- (.*), (.*) --\>$/;

and line
print map {"<A href=\"$ven{$1}{$_}\">$_</A><BR>\n"} sort keys %{$ven{$1}};
to
print map {"<A href=\"$ven{lc($1)}{$_}\">$_</A><BR>\n"} sort keys %{$ven{lc($1)}};
ASKER
Caiapfas

I'm about to crank it up, i have my fingers crossed...
ASKER
Caiapfas

lbertacco,

I'm getting a 500 error, I'm running this one a server, remote

$dir="/usr7/home/ttgo/public_html/venues";
$wdir="http://www.ticketstogo.com/veunes/";
$indextpl = "/usr7/home/ttgo/public_html/venues/states/index22.htm";
$indexhtm = "/usr7/home/ttgo/public_html/venues/states//index22.htm";


????
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER
Caiapfas

also,

i don't understand


# $indextpl is the index template file (e.g. C:\\test\\index.tpl) <<<< what template
# $indexhtm is the final index file (e.g. c:\\test\\index.htm)

I chmod the script to 777
and the directory 777
and the index file 777
ASKER
Caiapfas

its erasing the page...


the index file
http://www.ticketstogo.com/venues/states/index22.htm


the script
http://www.ticketstogo.com/cgi-bin/erase.adder.pl

also, what does the script do with the ones it doesn't find a home for?
ASKER
Caiapfas

here is the new template...i made half of the <!-- --> on the page and the other half in the html


http://www.ttgo.addr.com/venues/states/tempindex.htm
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
lbertacco

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Caiapfas

holy crap o roo, lol..
took a 2 - 4 day job and made it 1min....
thank you..
ASKER
Caiapfas


I'm trying to make the script , display how many links for each catogroy now..
example : it found and linked 300 <!-- whatever, Texas -->

Show after its done it makes a text file and says...

Index/Linked :

300 : Texas
200 : whatever
1000 : whatever also

here
https://www.experts-exchange.com/Programming/Q_20940315.html