File:
[LON-CAPA] /
loncom /
cgi /
metadata_harvest.pl
Revision
1.3:
download - view:
text,
annotated -
select for diffs
Mon Sep 1 03:37:27 2003 UTC (21 years, 1 month ago) by
albertel
Branches:
MAIN
CVS tags:
version_2_7_X,
version_2_7_1,
version_2_7_0,
version_2_6_X,
version_2_6_99_1,
version_2_6_99_0,
version_2_6_3,
version_2_6_2,
version_2_6_1,
version_2_6_0,
version_2_5_X,
version_2_5_99_1,
version_2_5_99_0,
version_2_5_2,
version_2_5_1,
version_2_5_0,
version_2_4_X,
version_2_4_99_0,
version_2_4_2,
version_2_4_1,
version_2_4_0,
version_2_3_X,
version_2_3_99_0,
version_2_3_2,
version_2_3_1,
version_2_3_0,
version_2_2_X,
version_2_2_99_1,
version_2_2_99_0,
version_2_2_2,
version_2_2_1,
version_2_2_0,
version_2_1_X,
version_2_1_99_3,
version_2_1_99_2,
version_2_1_99_1,
version_2_1_99_0,
version_2_1_3,
version_2_1_2,
version_2_1_1,
version_2_1_0,
version_2_0_X,
version_2_0_99_1,
version_2_0_2,
version_2_0_1,
version_2_0_0,
version_1_99_3,
version_1_99_2,
version_1_99_1_tmcc,
version_1_99_1,
version_1_99_0_tmcc,
version_1_99_0,
version_1_3_X,
version_1_3_3,
version_1_3_2,
version_1_3_1,
version_1_3_0,
version_1_2_X,
version_1_2_99_1,
version_1_2_99_0,
version_1_2_1,
version_1_2_0,
version_1_1_X,
version_1_1_99_5,
version_1_1_99_4,
version_1_1_99_3,
version_1_1_99_2,
version_1_1_99_1,
version_1_1_99_0,
version_1_1_3,
version_1_1_2,
version_1_1_1,
version_1_1_0,
version_1_0_99_3,
version_1_0_99_2,
version_1_0_99_1,
version_1_0_99,
HEAD
- adding more GPL headers
1: #!/usr/bin/perl
2: # Inserts metadata from .meta files into the mysql database
3: # $Id: metadata_harvest.pl,v 1.3 2003/09/01 03:37:27 albertel Exp $
4: #
5: # Copyright Michigan State University Board of Trustees
6: #
7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
8: #
9: # LON-CAPA is free software; you can redistribute it and/or modify
10: # it under the terms of the GNU General Public License as published by
11: # the Free Software Foundation; either version 2 of the License, or
12: # (at your option) any later version.
13: #
14: # LON-CAPA is distributed in the hope that it will be useful,
15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: # GNU General Public License for more details.
18: #
19: # You should have received a copy of the GNU General Public License
20: # along with LON-CAPA; if not, write to the Free Software
21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22: #
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27:
28:
29: ###############################################################################
30: ## ##
31: ## ORGANIZATION OF THIS PERL CGI SCRIPT ##
32: ## ##
33: ## 1. Status of this code ##
34: ## 2. Purpose and description of program ##
35: ## 3. Modules used by this script ##
36: ## 4. Print MIME Content-type and other initialization ##
37: ## 5. Make sure database can be accessed and that this is a library server ##
38: ## 6. Loop through database records and print out keywords ##
39: ## ##
40: ###############################################################################
41:
42: # --------------------------------------------------------- Status of this code
43: #
44: # 1=horrible 2=poor 3=fair 4=good 5=excellent
45: # Organization 5
46: # Functionality 4
47: # Has it been tested? 4
48: #
49:
50: # ------------------------------------------ Purpose and description of program
51: #
52: # This program outputs one line per database entry.
53: # The line is to be a list of keywords separated by commas.
54: # The file is to be output as a text file on a browser (text/plain).
55: # This provides initial data by which to study common and uncommon
56: # keywords being used.
57: # Note that the authoritative copy of metadata "keywords" is in the
58: # .meta files that are native to the library server. We rely
59: # on the assumption that it is okay to use the MySQL server (which
60: # should reflect this information) instead. This is a speedier approach.
61:
62: # ------------------------------------------------- Modules used by this script
63:
64: use lib '/home/httpd/lib/perl/';
65: use LONCAPA::Configuration;
66:
67: use strict;
68: use DBI;
69:
70: # ---------------------------- Print MIME Content-type and other initialization
71: $|=1;
72: print 'Content-type: text/plain'."\n\n";
73:
74: # --- Make sure that database can be accessed and that this is a library server
75: # library server test
76:
77: # By default, loncapa_apache.conf is also read by the read_conf subroutine.
78: my $perlvarref=LONCAPA::Configuration::read_conf('loncapa.conf');
79: my %perlvar=%{$perlvarref};
80: undef($perlvarref);
81:
82: unless ($perlvar{'lonRole'} eq 'library') {
83: print "This can only be run on a library server!\n";
84: exit;
85: }
86: # database test
87: my $dbh;
88: {
89: unless (
90: $dbh = DBI->connect("DBI:mysql:loncapa","www",
91: $perlvar{'lonSqlAccess'},
92: { RaiseError =>0,PrintError=>0})
93: ) {
94: print "Cannot connect to database!\n";
95: exit;
96: }
97: }
98: %perlvar=(); # undefine it
99:
100: # ------------------------ Loop through database records and print out keywords
101: my $sth=$dbh->prepare("select * from metadata");
102: $sth->execute();
103: my @row;
104: while (@row=$sth->fetchrow_array) {
105: for (my $i=0;$i<=$#row;$i++) {
106: $row[$i]=~s/\n/ /g;
107: $row[$i]=~s/\|/ /g;
108: }
109: print join('|',@row)."\n";
110: }
111:
112: # --------------------------------------------------- Close database connection
113: $dbh->disconnect();
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>