Changeset 2386
- Timestamp:
- 01/06/08 22:29:29 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
Trunk/Scripts/Mirroring_scripts/WebGUIForumUpdate.pm
r2385 r2386 2 2 #################################################################### 3 3 ### 4 ### script name : WebGUIForumUpdate.p l4 ### script name : WebGUIForumUpdate.pm 5 5 ### version: 0.1 6 6 ### created by: Ken MacLean 7 7 ### mail: contact@voxforge.org 8 8 ### Date: 2007.1.05 9 ### Command: perl ./WebGUIForumUpdate.p l9 ### Command: perl ./WebGUIForumUpdate.pm ($parms, $ProcessedUserSubmissions) 10 10 ### 11 11 ### Copyright (C) 2007 Ken MacLean … … 31 31 ### Declarations 32 32 #################################################################### 33 my $url ='http://www.scout.org/home/downloads/audio/model-repository/audio-speech-files'; 33 my $LoginURL ='http://www.scout.org'; 34 my $UploadURL ='http://www.scout.org/home/downloads/audio/model-repository/audio-speech-files'; 35 my $RepositoryURL ='http://www.repository.voxforge1.org/downloads/SpeechCorpus/Trunk/Audio/Original'; 34 36 my $command; 35 37 #################################################################### … … 37 39 #################################################################### 38 40 sub Main { 39 my ($parms, $ProcessedUserSubmissions) = @_;41 my ($parms,%ProcessedUserSubmissions) = @_; 40 42 my $debug = $$parms{"debug"}; 41 42 43 Login($parms); 43 foreach my $AudioDirName (keys % $ProcessedUserSubmissions) {44 my $path_original = $ $ProcessedUserSubmissions{$AudioDirName};45 print "Update Forum with AudioDirName:$path_original/$AudioDirName\n";44 foreach my $AudioDirName (keys %ProcessedUserSubmissions) { 45 my $path_original = $ProcessedUserSubmissions{$AudioDirName}; 46 print STDERR "Update Forum with AudioDirName:$path_original/$AudioDirName\n" if $debug; 46 47 my ($content,$title)= getContentsofZipFile($parms,$path_original, $AudioDirName); 47 48 Upload($parms,$content,$title); 48 49 } 49 $command = ("rm my_cookies.txt"); print "$command\n" ;system($command) == 0 or die "system $command failed: $?";50 $command = ("rm my_cookies.txt"); print "$command\n" if $debug;system($command) == 0 or die "system $command failed: $?"; 50 51 } 51 52 … … 56 57 my ($parms,$path_original, $AudioDirName) = @_; 57 58 my $debug = $$parms{"debug"}; 58 59 my ($content, $title); 59 60 my ($content, @readme, @prompts, @license); 61 my $title=$AudioDirName; 62 print STDERR "Extracting :$path_original/$AudioDirName\n" if $debug; 60 63 my $ae = Archive::Extract->new( archive => "$path_original/$AudioDirName" ); 61 64 if ( $ae->extract( to => "$AudioDirName-temp" ) ) { 62 $title=$AudioDirName; 63 open(README, "<zipcontents/readme.txt") or confess ("can't find readme.txt"); 64 $content .= <README>; 65 open(PROMPTS, "<zipcontents/prompts.txt") or confess ("can't find prompts.txt"); 66 $content .= <PROMPTS>; 67 open(LICENSE, "<zipcontents/license.txt") or confess ("can't find license.txt"); 68 $content .= <LICENSE>; 65 open(README, "<$AudioDirName-temp/readme.txt") or confess ("can't find readme.txt"); 66 @readme = <README>; 67 open(PROMPTS, "<$AudioDirName-temp/prompts.txt") or confess ("can't find prompts.txt"); 68 @prompts = <PROMPTS>; 69 open(LICENSE, "<$AudioDirName-temp/license.txt") or confess ("can't find license.txt"); 70 @license = <LICENSE>; 69 71 } else { 70 72 confess ("can't extract file:$path_original/$AudioDirName") 71 73 } 72 74 $title =~ s/\.zip//; 75 $content = join(" ",@readme); 76 $content .= "<h2>Prompts:</h2>"; 77 $content .= join(" ", @prompts); 78 $content .= "<h2>License:</h2>"; 79 $content .= join(" ", @license); 80 $content =~ s/\n/<br>\n/g; 81 $content =~ s/WARRANTY;/WARRANTY,/; # WebGUI does not like CAPITALS followed by semi-colons ...? 82 $content =~ s|<http://www.gnu.org/licenses/>|http://www.gnu.org/licenses/|; # more WebGUI arcana 83 $content .= "<br><img src=\"http://www.repository.voxforge1.org/spicons/compressed.gif\">"; 84 $content .= "<a href=\"$RepositoryURL/48kHz_16bit/$title.tgz\">$title.tgz</a><br>"; 85 # $content = join(" ", 86 # @readme, 87 # "<h2>Prompts:</h2>", @prompts, 88 # "<h2>License:</h2>", @license, 89 # "<br> <img src=\"http://www.repository.voxforge1.org/spicons/compressed.gif\" alt=\"[ ]\" border=\"0\">", 90 # "<a href=\"http://www.repository.voxforge1.org/downloads/SpeechCorpus/Trunk/Audio/Original/48kHz_16bit/$title.tgz\">$title.tgz</a><br>" 91 # ); 92 93 print $content; 73 94 return (\$content,\$title); 74 95 } … … 78 99 my $debug = $$parms{"debug"}; 79 100 101 my ($result, $err); 80 102 my $post = "op=auth;method=login;username=test;identifier=test;submit=login"; 81 103 82 104 my $curl = new WWW::Curl::Easy; 83 $curl->setopt(CURLOPT_URL, $ url);105 $curl->setopt(CURLOPT_URL, $LoginURL); 84 106 $curl->setopt(CURLOPT_COOKIEJAR, "my_cookies.txt"); 85 107 $curl->setopt(CURLOPT_COOKIEFILE, "my_cookies.txt"); … … 89 111 $curl->setopt(CURLOPT_POST, 1); 90 112 $curl->setopt(CURLOPT_POSTFIELDS, $post); 91 my $result = $curl->perform; 92 my $err; 113 $curl->setopt(CURLOPT_WRITEFUNCTION, \&chunk ); 114 $curl->setopt(CURLOPT_FILE, \$result); 115 $curl->perform; 93 116 if ($err = $curl->errbuf) { 94 117 confess ("ERROR: login failed with error: $err\n"); 95 118 } 96 119 if ($result) { 97 ParseLoginResult($parms, $result);120 ParseLoginResult($parms, \$result); 98 121 } else { 99 122 confess ("ERROR: login failed, no result\n") … … 101 124 102 125 if ($debug) { 103 print '---------';104 my $info = $curl->getinfo(CURLINFO_HTTP_CODE);105 print "err: $err\n";106 print "info: $info\n";126 print "---------\n"; 127 print "err: $err\n" ; 128 print "info: $curl->getinfo(CURLINFO_HTTP_CODE\n"; 129 # print "\n\nresult:\n$result\n"; 107 130 } 131 print "==============================================\n"; 108 132 } 109 133 … … 111 135 my ($parms, $result) = @_; 112 136 my $debug = $$parms{"debug"}; 113 if ($ result =~ /(Hello) <a href=".+">(.+)<\/a>/i) {114 print "login status: $1\n";137 if ($$result =~ /(Hello) <a href=".+">(.+)<\/a>/i) { 138 print "login status: successful\n"; 115 139 } else { 116 confess ("ERROR: cannot parse login result; login probably failed\n ");140 confess ("ERROR: cannot parse login result; login probably failed\nresult:$$result\n"); 117 141 } 118 142 } … … 122 146 my $debug = $$parms{"debug"}; 123 147 124 my $post = "func=editSave;assetId=new;class=WebGUI::Asset::Post::Thread;proceed=showConfirmation;title=\$title;content=\$content;subscribe=1;submit=save"; 148 my ($result, $err); 149 my $post = "func=editSave;assetId=new;class=WebGUI::Asset::Post::Thread;proceed=showConfirmation;title=$$title;content=$$content;contentType=text,subscribe=1;submit=save"; 125 150 126 151 my $curl = new WWW::Curl::Easy; 127 $curl->setopt(CURLOPT_URL, $ url);152 $curl->setopt(CURLOPT_URL, $UploadURL); 128 153 $curl->setopt(CURLOPT_COOKIEJAR, "my_cookies.txt"); 129 154 $curl->setopt(CURLOPT_COOKIEFILE, "my_cookies.txt"); … … 133 158 $curl->setopt(CURLOPT_POST, 1); 134 159 $curl->setopt(CURLOPT_POSTFIELDS, $post); 135 my $result = $curl->perform; 136 my $err; 160 $curl->setopt(CURLOPT_WRITEFUNCTION, \&chunk ); 161 $curl->setopt(CURLOPT_FILE, \$result); 162 $curl->perform; 137 163 if ($err = $curl->errbuf) { 138 164 confess ("ERROR: login failed with error: $err"); 139 165 } 140 166 if ($result) { 141 ParseUploadResult($parms, $result);167 ParseUploadResult($parms, \$result); 142 168 } else { 143 169 confess ("ERROR: Upload failed, no result\n") … … 145 171 146 172 if ($debug) { 147 print '---------'; 148 my $info = $curl->getinfo(CURLINFO_HTTP_CODE); 149 print "err: $err\n" ; 150 print "info: $info\n" ; 173 print "---------\n"; 174 print "err: $err\n" ; 175 print "info: $curl->getinfo(CURLINFO_HTTP_CODE\n"; 151 176 } 152 177 } … … 155 180 my ($parms, $result) = @_; 156 181 my $debug = $$parms{"debug"}; 157 if ($result =~ /(Your post has been received)/i) { 158 print "upload status: $1\n"; 159 } else { 160 confess ("ERROR: cannot parse upload result; upload probably failed\n"); 161 } 182 if ($$result =~ /(Your post has been received)/i) { 183 print "upload status: $1\n"; 184 } elsif ($$result =~ /<h1>(Permission Denied!)<\/h1>/i) { 185 print "ERROR: $1\n\nresult:\n$$result\n"; 186 } else { 187 confess ("ERROR: cannot parse upload result; upload probably failed\nresult:$$result\n"); 188 } 189 } 190 191 sub chunk { 192 my ($data,$pointer)=@_; 193 $$pointer .= $data; 194 return length($data); 162 195 } 163 196 1;