#!/usr/bin/perl #------------------------------------------------------------------------ # eric richardson _ _ _ _ grab articles # __ ___ _ _ __)) __ _ _ )L ))_ _ _ _ )) __ with images # (| ((_( ((\( ((_( ((_)((`1( (( ((`( ((_( ((`1( ((_)_)) #------------------------------------------------------------------------ # $Id: random_thumbs,v 1.5 2000/09/19 12:44:04 eric Exp $ # # random_thumbs: print out random thumbnails # Copyright (C) 2000 Eric Richardson # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA. # # Grab stories and randomly go through them, printing out an image # thumbnail linking into the story # #------------------------------------------------------------------------ use strict; use vars qw($db %cfg $core %stored); use eGold::core; use DBI; #----------------# # Initialization # #----------------# $core = eGold::core->start("random_thumbs"); ($cfg{input}{file}) = @ARGV; MAIN: { my $html = $core->get_template("home-thumbs.html"); # figure out how many images we need my $count; $count++ while ($html =~ m!#{img.*}!g); warn "count: $count\n"; # first we find articles with attached images my $get_img_articles = $db->prepare(" select article.id,art_image_lnk.image_id from art_image_lnk,article where article.id = art_image_lnk.article_id and article.state != 'WITHDRAWN' and article.released != 0 "); $get_img_articles->execute; warn "got ".$get_img_articles->rows." images\n"; my (@ids,$aid,$iid); $get_img_articles->bind_columns(\$aid,\$iid); push @ids, [$aid,$iid] while ($get_img_articles->fetch); my $i; for ($i = @ids; --$i;) { my $j = int rand ($i+1); next if $i == $j; @ids[$i,$j] = @ids[$j,$i]; } $i = 0; my (@good, %t); while (my $ref = shift @ids) { if ($t{s}{${$ref}[0]} || $t{i}{${$ref}[1]}) { # discard it warn "throwing out story: ${$ref}[0]\timage: ${$ref}[1]\n"; } else { $t{s}{${$ref}[0]} = ${$ref}[1]; $t{i}{${$ref}[1]} = ${$ref}[0]; push @good, $ref; } } warn "good: ".scalar(@good)."\n"; # chop @good to the number of thumbnail spots we found #@good = splice @good, 0, $count; my $get_image = $db->prepare(" select image from image where id = ? "); my $get_story = $db->prepare(" select article.id,article.headline,article.locale, art_topic_lnk.topic_id from article,image,art_topic_lnk where article.id = art_topic_lnk.article_id and article.id = ? "); my %s; my $num = 1; foreach my $ref (@good) { $get_story->execute(${$ref}[0]); $get_image->execute(${$ref}[1]); my ($id,$head,$locale,$topic) = $get_story->fetchrow_array; if ($cfg{exclude}{$topic}) { warn "have to get rid of exlucded: $id\t$topic\n"; next; } my $img = $get_image->fetchrow_array; $core->write_file( name => "photos/".${$ref}[1].".jpg", data => $img, ); $core->thumbnail( image => "photos/".${$ref}[1].".jpg", thumb => "photos/".${$ref}[1]."-hpthumb.jpg", width => 64, height => 64, letterbox => 1, ); warn "$num is image ${$ref}[1]\n"; %{$s{$num++}} = ( id => $id, head => $head, locale => $locale, topic => $topic, img => "/realgold/photos/".${$ref}[1]."-hpthumb.jpg", link => $core->clean_up( "/realgold/".$locale."/".$topic."/".$id.".shtml" ), ); last if ($num == ($count+1)); } while (my ($tag,$num) = $html =~ m!#{(img|link|head) ([^}]*)}!gi) { $html =~ s!#{$tag $num}!$s{$num}{$tag}!; } $core->write_file( name => $cfg{input}{file}, data => $html, ); $core->upload(@files); $core->save_memory(\%stored); } #-------------# # Change Logs # #-------------# # $Log: random_thumbs,v $ # Revision 1.5 2000/09/19 12:44:04 eric # * turned on letter boxing in random_thumbs # # Revision 1.4 2000/09/19 12:43:22 eric # * changed determination of publish state # * added letterboxing code to core::thumbnail # # Revision 1.3 2000/09/17 11:05:40 eric # * changed the way for determining published stories # * finished more functionality in make_archives # # Revision 1.2 2000/09/15 12:38:09 eric # * random_thumbs now works correctly # # Revision 1.1 2000/09/15 12:12:22 eric # * added random_thumb script for generating home page thumbnails # * added thumbnail code to eGold::core # # Revision 1.4 2000/09/11 09:38:42 eric # * first working revision of todays_stories # * updates to eGold::core # # Revision 1.3 2000/09/08 11:32:00 eric # * moved get_template into eGold::core # # Revision 1.2 2000/09/08 11:20:56 eric # * it would be cool if there was a way to make ascii art out of valid # Perl. Unfortunately, my ascii art doesn't compile. # * fixed a little bug in where the package tag was placed in eGold::core # # Revision 1.1 2000/09/08 11:08:38 eric # * small fixes # * got rid of a couple warns # * added start of core module and todays_stories script # #----------