1: #!/usr/local/bin/perl
2:
3: #
4: # lon-capa.pl
5: # Parse the LON-CAPA metadata
6: #
7: # Andy Dong <adong@smete.org> 10/23/2002
8: #
9: # Contact Gerd Kortemeyer (korte@lite.msu.edu)
10:
11: use strict;
12: use LWP::UserAgent;
13: use Getopt::Std;
14: use Digest::MD5 qw(md5_hex);
15:
16: my $pub_month;
17: my $pub_year;
18: my @loncapa;
19:
20: # HTTP requests
21:
22: my $content;
23: my $content_regex = 'File Not Found';
24:
25: # Configuration
26:
27: my $debug = 0;
28: my $url = 'http://s10.lite.msu.edu/cgi-bin/metadata_harvest.pl';
29: # The list of servers is from the LON-CAPA CVS repository in /loncapa/loncom/production_hosts.tab
30: my @servers = ( 'newscience.westshore.cc.mi.us', 's10.lite.msu.edu', 's12.lite.msu.edu', 'lon-capa.chem.sunysb.edu', 'schubert.tmcc.edu', 'dalton.chem.sfu.ca', 'capa2.phy.ohiou.edu', 'pollux.physics.fsu.edu', 'loncapa.physics.sc.edu', 'loncapa.math.ucf.edu', 'zappa.ags.udel.edu', 'loncapa.gwu.edu');
31:
32: # End Configuration
33:
34: my $ua = new LWP::UserAgent;
35: $ua->timeout(600);
36:
37: my $request = new HTTP::Request GET => $url;
38: $request->authorization_basic('reaper', 'cat4u');
39:
40: my $response = $ua->request( $request );
41:
42: if ( $response->is_success ) {
43: $content = $response->content;
44: # Delete all blank lines
45: $content =~ s/(?<!.)\n//g;
46: # Replace all ^M with spaces
47: $content =~ s/
/\s/g;
48: # Push the content into an array
49: @loncapa = split /\n/, $content;
50: } else {
51: die 'LON-CAPA request failed: ' . $response->message;
52: }
53:
54: #@loncapa=undef;
55: #open (LON_FILE, 'metadata_harvest.txt') || die;
56:
57: #while (<LON_FILE>) {
58: # chomp;
59: # push(@loncapa,$_);
60: #}
61:
62: my %records = ();;
63: print '<?xml version="1.0" encoding="UTF-8"?>'."\n\n";
64:
65: foreach my $metadata (@loncapa) {
66: chomp $metadata;
67: $metadata=~s/[^\w\d\s\.\;\:\,\|\/]/ /gs;
68: my @tkline = split('\|', $metadata);
69: my $title = $tkline[0];
70: next if ( $title eq '' );
71: my $author = $tkline[1];
72: next if ( $author eq '' );
73: my @authorname = split(' ', $author);
74: my $author_fname = $authorname[0];
75: my $author_lname = $authorname[1];
76: # We have to make an exception for Multimedia Physics which is an organization not a person
77: my $object_type;
78: if ( $author_lname eq 'Physics' ) {
79: $object_type = 'organization';
80: } else {
81: $object_type = 'person';
82: }
83: my $subject = $tkline[2];
84: next if ( ($subject eq 'Sample') || ($subject eq 'Something') );
85: my $resourceurl = 'http://nsdl.lon-capa.org' . $tkline[3];
86: my $baseid=$tkline[3];
87: $baseid=~s/\W/\_/g;
88: $baseid=~s/^\_res\_//g;
89:
90: next if ( $resourceurl =~ /(.*)\/demo\/(.*)/ );
91: my $keywords = $tkline[4];
92: my $version = $tkline[5];
93: my $notes = $tkline[6];
94: my $abstract = $tkline[7];
95: next if ($abstract eq '');
96: my $type = $tkline[8];
97: my $learning_resource_type;
98: if ( $type eq 'problem' ) {
99: $learning_resource_type = 114;
100: } elsif ( $type eq 'exam' ) {
101: $learning_resource_type = 114;
102: } elsif ( $type eq 'quiz' ) {
103: $learning_resource_type = 114;
104: } elsif ( $type eq 'assess' ) {
105: $learning_resource_type = 114;
106: } elsif ( $type eq 'survey' ) {
107: $learning_resource_type = 114;
108: } elsif ( $type eq 'form' ) {
109: $learning_resource_type = 114;
110: } elsif ( $type eq 'library' ) {
111: $learning_resource_type = 107;
112: } elsif ( $type eq 'page' ) {
113: $learning_resource_type = 104;
114: } elsif ( $type eq 'sequence' ) {
115: $learning_resource_type = 104;
116: } elsif ( $type eq 'spreadsheet' ) {
117: $learning_resource_type = 114;
118: } else {
119: $learning_resource_type = 0;
120: }
121:
122: my $media_format;
123: if ( ($type eq 'htm') || ($type eq 'gif') || ($type eq 'mov') || ($type eq 'xml') ) {
124: $media_format = 70;
125: } else {
126: $media_format = 0;
127: }
128:
129: my $language = $tkline[9]; # Look only for seniso
130: next if ( $language ne 'seniso');
131: my $primary_language='en-US';
132: my $creation_date = $tkline[10];
133: my ($pub_year,$pub_month,$pub_day) = ( $creation_date =~ /^(\d{4}) (\d{2}) (\d{2})\s(\d{2}):(\d{2}):(\d{2})$/ );
134: my $revision_date = $tkline[11];
135: my ($rev_year,$rev_month,$rev_day) = ( $revision_date =~ /^(\d{4}) (\d{2}) (\d{2})\s(\d{2}):(\d{2}):(\d{2})$/ );
136: my $owner = $tkline[12];
137: my $rights_description;
138: my $copyright = $tkline[13]; # public,domain,default,private (skip if private and domain)
139: # Public means no login required
140:
141: if ( $copyright eq 'public' ) {
142: $rights_description = 'LON-CAPA Public Resource. No login required.';
143: } elsif ($copyright eq 'domain') {
144: $rights_description = 'Restricted to certain LON-CAPA domains.';
145: } else {
146: $rights_description = 'LON-CAPA Default Use Restriction. Login required.';
147: }
148: # Domain means restricted to a particular LON-CAPA domain
149: # Defaults mean access open to any registered LON-CAPA user
150: # Private means open only to author of material
151: next if ( $copyright eq 'private');
152: my $platform = "5"; # HTML Browser (not specified but construed from metadata)
153: print (<<ENDMETA);
154: <oaidc:dc xmlns="http://purl.org/dc/elements/1.1/"
155: xmlns:oaidc="http://www.openarchives.org/OAI/2.0/oai_dc/"
156: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
157: xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/
158: http://www.openarchives.org/OAI/2.0/oai_dc.xsd"
159: >
160: <title>$title</title>
161: <creator>$author_fname $author_lname</creator>
162: <identifier>$resourceurl</identifier>
163: <subject>$keywords</subject>
164: <subject>$subject</subject>
165: <language>$primary_language</language>
166: <description>$abstract</description>
167: <date>$rev_year-$rev_month-$rev_day</date>
168: </oaidc:dc>
169:
170: ENDMETA
171: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>