c4onastick has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I'll be honest, this is my first post here, and I'm fairly new to perl (I come from a PHP background, I'm very excited to start perl!). I've finally found a suitable project to try my (perl) hand at. I'm teaching a lab section of Engineering Computing this semester, and as part of the class, the students are to email me their work (which, so far, consists of excel workbooks). After manually saving 30-some-odd of these today, I said, "There's gotta be a better way". Enter perl. I've been doing some reading on WWW::Mechanize and have successfully implemented it... so far. I'm trying to get it to find all the submitted excel files in my inbox (done), and download them (having trouble with this). Here's what I have so far:
So far, it works, it writes out and everyone is happy, except excel. It wont let me open them (I get a funky ready-only error, I don't think its excel's fault, I think I'm doing something wrong in the perl above). I'll eventually save these with the student's name in the filename (which I can also get from the message), but for now, I need to be able to open them to grade them! Thanks in advance for your help. I really look forward to becoming part of this community! (Next project is a perl script to grade them for me!)#!C:\perl\bin\perl.exe use warnings; use WWW::Mechanize; my $mech = WWW::Mechanize->new(); my $url = 'https://webmail.my_university.edu'; $mech->get($url); # login $mech->submit_form( form_number => 0, fields => { imapuser => 'c4onastick', pass => 'my_password_here', } ); # Navigate back to the first page that contains the most recent messag +es $mech->follow_link(url_regex => qr/page=1/ ); # Find all links (messages) with Lab 2 in the subject my @links = $mech->find_all_links( text_regex => qr/lab\s*2/i ); my $content; foreach my $link (@links) { print $link->url."\n"; print $link->text."\n"; print "Following...\n"; $mech->follow_link( url => $link->url); $mech->follow_link( url_regex => qr/\.xls/i ); #link to the attach +ed excel file $content .= $mech->content; # this might be where it is breaking d +own last; # Jump out after one for testing $mech->back; } mkdir "Eng_files", 0755 or die "Couldn't create directory: $!"; chdir "Eng_files" or die "Can't change directory: $!"; open(FH, ">", "test.xls"); print "Writing out...\n"; print FH $content; print "Done.\n\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Downloading Excel Spreadsheets from Web-based Mail
by Anonymous Monk on Feb 02, 2007 at 07:14 UTC | |
by c4onastick (Friar) on Feb 02, 2007 at 20:31 UTC | |
Re: Downloading Excel Spreadsheets from Web-based Mail
by roboticus (Chancellor) on Feb 02, 2007 at 11:43 UTC |
Back to
Seekers of Perl Wisdom