Changeset 2464
- Timestamp:
- 03/03/08 15:00:42 (10 months ago)
- Files:
-
- Trunk/Scripts/Mirroring_scripts/Single_WebGUIForum.pm (modified) (4 diffs)
- Trunk/Scripts/Mirroring_scripts/WebGUIForum.pm (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
Trunk/Scripts/Mirroring_scripts/Single_WebGUIForum.pm
r2459 r2464 24 24 use diagnostics; 25 25 use Carp; 26 use Archive::Extract; 27 use File::Basename; 26 28 #################################################################### 27 29 use VoxForge_config; … … 37 39 ### Directory 38 40 #################################################################### 39 my $AudioDirName="ruth-20080302-rhb";41 #my $AudioDirName="NL-JohanLingen-20080302-das[1496202351].zip"; 40 42 my $path_original ="/home/kmaclean/temp2"; 43 my $tarfile ="DE-anonymous-20080303-svq[186061628].zip"; # if undef than attachment does not get processed by LWP! 44 my $prefix ="DE-"; # prefix to remove from submission 45 #################################################################### 46 print "tarfile1:$path_original/$tarfile\n"; 47 if ($tarfile =~ /\[.*\]/) { 48 # can't get this to work with Archive::Extract??: 49 my $newDirectoryName = $tarfile; 50 $newDirectoryName =~ s/$prefix//; 51 $newDirectoryName =~ s/\[.*\]//; 52 rename("$path_original/$tarfile", "$path_original/$newDirectoryName") || confess "error:tar file not found, cannot rename: $?"; 53 $tarfile = $newDirectoryName; 54 } 55 print "tarfile2:$path_original/$tarfile\n"; 56 my @suffixlist = ("tgz", "tar\.gz", "zip"); 57 my ($AudioDirName,$path,$suffix) = fileparse($tarfile,@suffixlist); 58 $AudioDirName =~ s/\.$//; # remove trailing period that fileparse does not remove for some reason?? 59 print "AudioDirName:$AudioDirName\n"; 60 61 my $ae = Archive::Extract->new( archive => "$path_original/$tarfile" ); 62 $ae->extract( to => "$path_original/$AudioDirName") or die $ae->error;; 41 63 ##########submission with tarfile as attachment: 42 64 my $promptspath = "$path_original/$AudioDirName/prompts.txt"; 43 65 my $readmepath = "$path_original/$AudioDirName/readme.txt"; 44 66 my $licensepath = "$path_original/$AudioDirName/license.txt"; 45 my $tarfile ="$path_original/$AudioDirName.zip"; # if undef than attachment does not get processed by LWP! 46 ##########fix submission that did not work properly; no ttarfile to upload since linking to voxforge1.org67 68 ##########fix submission that did not work properly; no tarfile to upload since linking to voxforge1.org 47 69 #my $readmepath = "$path_original/$AudioDirName/etc/README"; 48 70 #my $promptspath = "$path_original/$AudioDirName/etc/prompts-original"; … … 59 81 60 82 if (defined $tarfile) { 61 if ( -e "$path_original/$AudioDirName.zip") {83 if ((-e "$path_original/$tarfile") and (-e "$path_original/$AudioDirName")) { 62 84 print "path $path_original/$AudioDirName.zip\n"; 63 85 Update($parms, \%ProcessedUserSubmissions, 'speechsubmission', 'n@wp@$$') || confess "Single_WebGUIForumUpdate error: $?"; … … 94 116 #my $licensepath = "$path_original/$AudioDirName/LICENSE"; 95 117 my ($content,$title)= WebGUIForum::getSubmissionContents($parms,$readmepath,$promptspath,$licensepath,$AudioDirName, $readme,$tarfile); 96 WebGUIForum::Upload($parms,$browser,$content,$title,$readme, $tarfile);118 WebGUIForum::Upload($parms,$browser,$content,$title,$readme,"$path_original/$tarfile"); 97 119 #} else { 98 120 # print "No WebGUI Forum Update - not submitted using VoxForge Speech Submission Application, or flagged for webgui forum update\n"; Trunk/Scripts/Mirroring_scripts/WebGUIForum.pm
r2459 r2464 28 28 use Carp; 29 29 use strict; 30 # !!!!!!31 #use WWW::Curl::Easy;32 30 use LWP::UserAgent; 33 31 use URI::Escape; 34 32 #use Archive::Extract; 35 # !!!!!! 33 use Encode; 36 34 #################################################################### 37 35 ### Declarations … … 41 39 my $englishURL = 'http://www.voxforge.org/home/downloads/speech/english'; 42 40 my $dutchURL = 'http://www.voxforge.org/home/downloads/speech/dutch'; 41 #my $germanURL = 'http://www.voxforge.org/home/downloads/speech/german-speech-files'; 43 42 #my $englishURL = 'http://www.voxforge.org/home/downloads/speech/voxforgeivr'; # for testing 44 43 #my $dutchURL = 'http://www.voxforge.org/home/downloads/speech/voxforgeivr'; # for testing 44 my $germanURL = 'http://www.voxforge.org/home/downloads/speech/voxforgeivr'; # for testing 45 45 my $tarfile = undef; # not uploading a tarfile to WebGUI forum 46 46 #################################################################### … … 52 52 print "\nWebGUIForumUpdate.pm starting****************************************************\n\n"; 53 53 my $counter; 54 # !!!!!!55 # Login($parms, $username, $identifier);56 54 my $browser = LWP::UserAgent->new(keep_alive => 1 ); 57 55 $browser->cookie_jar( {} ); 58 56 Login($parms, $browser, $username, $identifier); 59 # !!!!!!60 57 foreach my $AudioDirName (keys %$ProcessedUserSubmissions) { 61 58 $counter++; … … 91 88 } elsif ($readme->getLanguage() =~ /NL/) { 92 89 $UploadURL =$dutchURL; 90 } elsif ($readme->getLanguage() =~ /DE/) { 91 $UploadURL =$germanURL; 93 92 } else { 94 93 $UploadURL =$englishURL; … … 98 97 99 98 sub getSubmissionContents { 100 # !!!!!!101 #my ($parms,$readmepath,$promptspath,$licensepath,$AudioDirName,$readme) = @_;102 99 my ($parms,$readmepath,$promptspath,$licensepath,$AudioDirName,$readme,$tarfile) = @_; 103 # !!!!!!104 100 my $debug = $$parms{"debug"}; 105 101 my ($content); … … 121 117 # confess ("can't extract file:$path_original/$AudioDirName") 122 118 #} 123 $title =~ s/\.zip//; 124 $content = join(" ",@readme); 119 $title =~ s/\.zip//; 120 #!!!!!! 121 #$content = join(" ",@readme); 122 my $tempContent = join(" ",@readme); # for some reason, README has different characert encoding than Prompts and License??? 123 $content = encode("utf8", $tempContent); 124 # !!!!!! 125 125 $content .= "<h2>Prompts:</h2>"; 126 126 $content .= join(" ", @prompts); … … 144 144 #$content =~ s/&/and/g; # CURL (or WebGUI) doesn't like ampersands?? 145 145 # !!!!!! 146 146 147 return (\$content,\$title); 147 148 } … … 164 165 165 166 sub Login { 166 # !!!!!!167 #my ($parms, $username, $identifier) = @_;168 167 my ($parms, $browser, $username, $identifier) = @_; 169 168 my $debug = $$parms{"debug"}; 170 #my ($result, $err);171 #my $post = "op=auth;method=login;username=$username;identifier=$identifier;submit=login";172 173 #my $curl = new WWW::Curl::Easy;174 #$curl->setopt(CURLOPT_URL, $LoginURL);175 #$curl->setopt(CURLOPT_COOKIEJAR, "my_cookies.txt");176 #$curl->setopt(CURLOPT_COOKIEFILE, "my_cookies.txt");177 #$curl->setopt(CURLOPT_CONNECTTIMEOUT, 120);178 #$curl->setopt(CURLOPT_TIMEOUT, 10);179 #$curl->setopt(CURLOPT_FOLLOWLOCATION,1);180 #$curl->setopt(CURLOPT_POST, 1);181 #$curl->setopt(CURLOPT_POSTFIELDS, $post);182 #$curl->setopt(CURLOPT_WRITEFUNCTION, \&chunk );183 #$curl->setopt(CURLOPT_FILE, \$result);184 #$curl->perform;185 #if ($err = $curl->errbuf) {186 # confess ("ERROR: login failed with error: $err\n");187 #}188 #if ($result) {189 # ParseLoginResult($parms, \$result);190 #} else {191 # confess ("ERROR: login failed, no result\n")192 #}193 169 my $result = $browser->post( 194 170 "$LoginURL", … … 215 191 # print "\n\nresult:\n$result\n"; 216 192 } 217 # !!!!!!218 193 } 219 194 … … 221 196 my ($parms, $result) = @_; 222 197 my $debug = $$parms{"debug"}; 223 # !!!!!!!224 #if ($$result =~ /(Hello) <a href=".+">(.+)<\/a>/i) {225 198 if ($result->content =~ /(Hello) <a href=".+">(.+)<\/a>/i) { 226 199 print "login status: successful\n"; 227 200 } else { 228 #confess ("ERROR: cannot parse login result; login probably failed\nresult:$$result\n");229 201 confess ("ERROR: cannot parse login result; login probably failed\nresult:$result->content\n"); 230 202 } 231 # !!!!!!232 203 } 233 204 … … 235 206 my ($parms,$browser,$content,$title,$readme,$tarfile) = @_; 236 207 my $debug = $$parms{"debug"}; 237 #my ($result, $err, $post);238 # if (($tarfile ne "none") and (defined($tarfile)) and ($tarfile ne "")) {239 #$post = "func=editSave&assetId=new&class=WebGUI::Asset::Post::Thread&proceed=showConfirmation&title=$$title&content=test&__storageId_action=upload&storageId_file=\@$tarfile&subscribe=1&submit=save";240 241 #my $curl = new WWW::Curl::Easy;242 #$curl->setopt(CURLOPT_URL, $UploadURL);243 #$curl->setopt(CURLOPT_COOKIEJAR, "my_cookies.txt");244 #$curl->setopt(CURLOPT_COOKIEFILE, "my_cookies.txt");245 #$curl->setopt(CURLOPT_CONNECTTIMEOUT, 120);246 #$curl->setopt(CURLOPT_TIMEOUT, 28800);247 #$curl->setopt(CURLOPT_FOLLOWLOCATION,1);248 #$curl->setopt(CURLOPT_HTTPPOST, 1);249 #$curl->setopt(CURLOPT_POSTFIELDS, $post);250 #$curl->setopt(CURLOPT_WRITEFUNCTION, \&chunk );251 #$curl->setopt(CURLOPT_FILE, \$result);252 #$curl->perform;253 208 my $local_tarfile; 254 209 if (!defined $tarfile) { … … 271 226 'submit' => 'save', 272 227 ], 273 'Content_Type' => 'form-data', 228 'Content_Type' => 'form-data', 229 'charset' => 'UTF-8', 230 274 231 ); 275 #if ($err = $curl->errbuf) {276 # confess ("ERROR: login failed with error: $err");277 #}278 #if ($result) {279 # ParseUploadResult($parms, \$result);280 #} else {281 # confess ("ERROR: Upload failed, no result\n")282 #}283 232 if ($result->is_success) { 284 233 ParseUploadResult($parms, $result); … … 293 242 print "http code:" . $result->status_line. "\n"; 294 243 } 295 296 244 } 297 245 … … 299 247 my ($parms, $result) = @_; 300 248 my $debug = $$parms{"debug"}; 301 302 #if ($$result =~ /(Your post has been received)/i) {303 249 if ($result->content =~ /(Your post has been received)/i) { 304 250 print "upload status: $1\n"; 305 #} elsif ($$result =~ /<h1>(Permission Denied!)<\/h1>/i) {306 251 } elsif ($result->content =~ /<h1>(Permission Denied!)<\/h1>/i) { 307 #print "ERROR: $1\n\nresult:\n$$result\n";308 252 confess "ERROR: $1\n\nresult:\n$result->content\n"; 309 253 } else { 310 #confess ("ERROR: cannot parse upload result; upload probably failed\nresult:$$result\n");311 254 confess ("ERROR: cannot parse upload result; upload probably failed\nresult:$result->content\n"); 312 255 } 313 256 } 314 # !!!!!!315 #sub chunk {316 # my ($data,$pointer)=@_;317 # $$pointer .= $data;318 # return length($data);319 #}320 # !!!!!!321 257 1;