Re: Posting to blogger.com?
Matt Lawrence wrote: The real test is whether chr $u > 255. Of course the data is passed through correctly whether or not perl understands that it's unicode data. I said chr here, but I just noticed that I really meant ord *sigh* Matt
Re: Posting to blogger.com?
On Thu, Jun 3, 2010 at 1:17 PM, Dave Hodgkinson wrote: > On 3 Jun 2010, at 00:52, Mark Fowler wrote: >> On Wed, Jun 2, 2010 at 4:29 PM, Dave Hodgkinson wrote: >>> On 2 Jun 2010, at 21:38, Egor Shipovalov wrote: use File::Slurp; >>> This is the start of most scripts I've been writing recently. >> I dumped this since I started using Path::Class all the time. >> my $content = file("something")->slurp > Ah, slurp("file") is clearly too obscure and difficult. It's not that it's obscure or difficult, it's that since I've already loaded Path::Class and most likely have the file object representing the path already, calling ->slurp on it is the natural way forward for me. I'm not saying you're wrong using File::Slurp, I'm just saying that I don't have it at the top of my module list any more. Of course, TMTOWTDI. Mark.
Re: Posting to blogger.com?
On 3 Jun 2010, at 20:56, Matt Lawrence wrote: > The real test is whether chr $u > 255. Of course the data is passed through > correctly whether or not perl understands that it's unicode data. And thank you to Ilmari and Zefram for the clue bat on all things UTF8 and indeed utf-8.
Re: Posting to blogger.com?
Kieren Diment wrote: On 03/06/2010, at 8:06 PM, Steve Mynott wrote: On Wed, Jun 02, 2010 at 05:52:40PM +0100, Mark Fowler typed: On Wed, Jun 2, 2010 at 4:29 PM, Dave Hodgkinson wrote: On 2 Jun 2010, at 21:38, Egor Shipovalov wrote: use File::Slurp; This is the start of most scripts I've been writing recently. I dumped this since I started using Path::Class all the time. my $content = file("something")->slurp Does it work with UTF-8? File::Slurp seems to, or am I missing something: $ cat > utf 김치 k...@fenchurch>/tmp$ perl -MFile::Slurp -e 'read_file('utf')' k...@fenchurch>/tmp$ perl -w -MFile::Slurp -e '$u = read_file("utf"); write_file("u2", $u)' k...@fenchurch>/tmp$ cat u2 김치 The real test is whether chr $u > 255. Of course the data is passed through correctly whether or not perl understands that it's unicode data. Matt
Re: Posting to blogger.com?
On 03/06/2010, at 8:06 PM, Steve Mynott wrote: > On Wed, Jun 02, 2010 at 05:52:40PM +0100, Mark Fowler typed: > >> On Wed, Jun 2, 2010 at 4:29 PM, Dave Hodgkinson wrote: >> >>> On 2 Jun 2010, at 21:38, Egor Shipovalov wrote: use File::Slurp; >>> >>> This is the start of most scripts I've been writing recently. >> >> I dumped this since I started using Path::Class all the time. >> >> my $content = file("something")->slurp > > Does it work with UTF-8? File::Slurp seems to, or am I missing something: $ cat > utf 김치 k...@fenchurch>/tmp$ perl -MFile::Slurp -e 'read_file('utf')' k...@fenchurch>/tmp$ perl -w -MFile::Slurp -e '$u = read_file("utf"); write_file("u2", $u)' k...@fenchurch>/tmp$ cat u2 김치
Re: Posting to blogger.com?
On Jun 3, 2010, at 5:06 AM, Steve Mynott wrote: > On Wed, Jun 02, 2010 at 05:52:40PM +0100, Mark Fowler typed: > >> On Wed, Jun 2, 2010 at 4:29 PM, Dave Hodgkinson wrote: >> >>> On 2 Jun 2010, at 21:38, Egor Shipovalov wrote: use File::Slurp; >>> >>> This is the start of most scripts I've been writing recently. >> >> I dumped this since I started using Path::Class all the time. >> >> my $content = file("something")->slurp > > Does it work with UTF-8? It does with this patch https://rt.cpan.org/Public/Bug/Display.html?id=58088 my $content = file("something")->slurp(iolayers => ':encoding(utf8)'); Graham.
Re: Posting to blogger.com?
On 3 Jun 2010, at 00:52, Mark Fowler wrote: > On Wed, Jun 2, 2010 at 4:29 PM, Dave Hodgkinson wrote: > >> On 2 Jun 2010, at 21:38, Egor Shipovalov wrote: >>> use File::Slurp; >> >> This is the start of most scripts I've been writing recently. > > I dumped this since I started using Path::Class all the time. > > my $content = file("something")->slurp Ah, slurp("file") is clearly too obscure and difficult.
Re: Posting to blogger.com?
On 3 Jun 2010, at 18:41, Dagfinn Ilmari Mannsåker wrote: > ilm...@ilmari.org (Dagfinn Ilmari Mannsåker) writes: > >> it can't possibly know the encoding of an arbitrary. > > Of an arbitrary file, of course. No, I like the word you just nouned. Retribution for all the verbing that's been going on.
Re: Posting to blogger.com?
ilm...@ilmari.org (Dagfinn Ilmari Mannsåker) writes: > it can't possibly know the encoding of an arbitrary. Of an arbitrary file, of course. -- ilmari "A disappointingly low fraction of the human race is, at any given time, on fire." - Stig Sandbeck Mathisen
Re: Posting to blogger.com?
Steve Mynott writes: > On Wed, Jun 02, 2010 at 05:52:40PM +0100, Mark Fowler typed: > >> On Wed, Jun 2, 2010 at 4:29 PM, Dave Hodgkinson wrote: >> >> > On 2 Jun 2010, at 21:38, Egor Shipovalov wrote: >> >> use File::Slurp; >> > >> > This is the start of most scripts I've been writing recently. >> >> I dumped this since I started using Path::Class all the time. >> >> my $content = file("something")->slurp > > Does it work with UTF-8? What do you mean "work with"? I would expect it to return an octet string and leave the decoding to you, since it can't possibly know the encoding of an arbitrary. > File::Slurp doesn't. Look buddy, doesn't work is a strong statement. Does it sit on the couch all day? Is it making faces at you? Does it want more money? Is it sleeping with your girlfriend? Please be specific! -- ilmari "A disappointingly low fraction of the human race is, at any given time, on fire." - Stig Sandbeck Mathisen
Re: Posting to blogger.com?
On Wed, Jun 02, 2010 at 05:52:40PM +0100, Mark Fowler typed: > On Wed, Jun 2, 2010 at 4:29 PM, Dave Hodgkinson wrote: > > > On 2 Jun 2010, at 21:38, Egor Shipovalov wrote: > >> use File::Slurp; > > > > This is the start of most scripts I've been writing recently. > > I dumped this since I started using Path::Class all the time. > > my $content = file("something")->slurp Does it work with UTF-8? File::Slurp doesn't. -- Steve Mynott
Re: Posting to blogger.com?
On Mon, May 31, 2010 at 06:29, Ovid wrote: > Does anyone have any *working* code (I've seen plenty of failing examples) > they can share which demonstrates making a successful post to blogger? I've > failed with both Net::Blogger and Atompub > (http://stackoverflow.com/questions/2942998/cant-post-with-perls-netblogger). Yeah, it's written in python. http://code.google.com/apis/blogger/docs/1.0/developers_guide_python.html Tool for the job etc... Paul
Re: Posting to blogger.com?
Maybe i m going to burn in hell for this heresy, but if you're interested, I ve got a python script that does what you'd like. Jerome. On 3 Jun 2010 08:26, "Ovid" wrote: - Original Message > From: Egor Shipovalov > Sorry, forgot to men... Actually, WWW::Blogger::XML doesn't say anything about this. Rather hostile documentation. The file's called '.www_blogger_rc' and must be in the AppConfig::Std format like so: username = $username password = $password There's also no option to supply this data programatically. Either you have that file or you're sunk. That's not the real problem, though. I would venture that the dependency on Net::Google::GData is where most people are going to get stuck. It's available at http://backpan.perl.org/authors/id/A/AY/AYOUNG/Net-Google-GData-0.01.tar.gz, but the author's deleted it from the CPAN. That was *real* fun. I'll email him to see what's going on. And it fails its own tests. Lovely. After much fighting, I've finally gotten it to authenticate and I'm now at the "400 Bad Request" stage which, all things considered, is much further than I've gotten. I'll post to my blog when I get a more generic solution. Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Tech blog - http://blogs.perl.org/users/ovid/ Twitter - http://twitter.com/OvidPerl Official Perl 6 Wiki - http://www.perlfoundation.org/perl6
Re: Posting to blogger.com?
- Original Message > From: Egor Shipovalov > Sorry, forgot to mention: you must have a file called something > like .www_blogger in you home directory, containing login credentials. > See perldoc for WWW::Blogger::XML for details. Actually, WWW::Blogger::XML doesn't say anything about this. Rather hostile documentation. The file's called '.www_blogger_rc' and must be in the AppConfig::Std format like so: username = $username password = $password There's also no option to supply this data programatically. Either you have that file or you're sunk. That's not the real problem, though. I would venture that the dependency on Net::Google::GData is where most people are going to get stuck. It's available at http://backpan.perl.org/authors/id/A/AY/AYOUNG/Net-Google-GData-0.01.tar.gz, but the author's deleted it from the CPAN. That was *real* fun. I'll email him to see what's going on. And it fails its own tests. Lovely. After much fighting, I've finally gotten it to authenticate and I'm now at the "400 Bad Request" stage which, all things considered, is much further than I've gotten. I'll post to my blog when I get a more generic solution. Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Tech blog - http://blogs.perl.org/users/ovid/ Twitter - http://twitter.com/OvidPerl Official Perl 6 Wiki - http://www.perlfoundation.org/perl6
Re: Posting to blogger.com?
On Wed, Jun 2, 2010 at 4:29 PM, Dave Hodgkinson wrote: > On 2 Jun 2010, at 21:38, Egor Shipovalov wrote: >> use File::Slurp; > > This is the start of most scripts I've been writing recently. I dumped this since I started using Path::Class all the time. my $content = file("something")->slurp Mark.
Re: Posting to blogger.com?
On 2 Jun 2010, at 21:38, Egor Shipovalov wrote: > > #!/usr/bin/perl > > use strict; > use warnings; > > use Getopt::Long; > use LWP::Simple; > use HTML::Entities; > use URI::Escape; > use XML::Simple; > use File::Slurp; > use Data::Dumper; This is the start of most scripts I've been writing recently. Maybe throw in YAML for some config, Cache::File for speeding up developing requests against slow API's, Log::Log4Perl and probably DateTime for demoronifying dates.
Re: Posting to blogger.com?
Sorry, forgot to mention: you must have a file called something like .www_blogger in you home directory, containing login credentials. See perldoc for WWW::Blogger::XML for details. On Wed, Jun 2, 2010 at 2:38 PM, Egor Shipovalov wrote: > Here it goes. It's not exactly generic because it's designed to be > called from Emacs org-mode, but I hope it will be useful for you. > > # BEGIN CODE > > #!/usr/bin/perl > > use strict; > use warnings; > > use Getopt::Long; > use LWP::Simple; > use HTML::Entities; > use URI::Escape; > use XML::Simple; > use WWW::Blogger::XML; > use File::Slurp; > use Data::Dumper; > > > # Get the options from command line. > Getopt::Long::GetOptions(\ my %opts, 'org', map "$_=s", qw/blog title > categories file/); > > my $post_body = $opts{file} ? File::Slurp::read_file($opts{file}) : join '', > <>; > > if ($opts{org}) { > # Convert tags to categories. > if ($post_body =~ s!(?: )*(.+?)!!s) { > $opts{categories} = $1; > $opts{categories} =~ s! !,!g; > $opts{categories} =~ s!___!-!g; > $opts{categories} =~ s!__! !g; > $opts{categories} = HTML::Entities::decode_entities($opts{categories}); > } > > # Extract post title. > $post_body =~ s!\s*]*>(.+?)\s*!!s; > $opts{title} = HTML::Entities::decode_entities($1); > } > > # Search for a post with such title. Atom API doesn't seem to allow searching, > # so do a normal web search. > my $content = LWP::Simple::get( > "http://$opts{blog}.blogspot.com?q="; > . URI::Escape::uri_escape("\"$opts{title}\"") > ); > my ($blog_id) = $content =~ /[?&]blogID=(\d+)/; > > # Look if a post with specified title is present in search results. > my $post_id; > while ($content =~ m!.+?]+>([^<]+)!sg) { > next unless uc HTML::Entities::decode_entities($2) eq uc $opts{title}; > > # If $post_id is already defined, this must be another post with the same > # title. Therefore, the title isn't unique. Die. > die "Multiple posts found with the title \"$opts{title}\": $post_id, $2" > if defined $post_id; > > # This is the first match, assign the post id. > $post_id = $1; > } > > # Build post as structure for conversion to XML. > my %body = ( > 'xmlns' => 'http://www.w3.org/2005/Atom', > 'content' => { > content => $post_body, > type => 'html', > }, > title => { > content => $opts{title}, > type => 'text', > }, > category => [ > map { > scheme => 'http://www.blogger.com/atom/ns#', > term => $_, > }, > split /\s*,\s*/, ($opts{categories} || '') > ], > ); > > # Create the request. > my $request = HTTP::Request->new( > $post_id ? 'PUT' : 'POST', > $WWW::Blogger::XML::API::url . "/feeds/$blog_id/posts/default/" . > ($post_id || ''), > [ Content_Type => 'application/atom+xml' ], > XML::Simple::XMLout(\%body, RootName => 'entry'), > ); > > # Execute it, dying on failure. > my $result = WWW::Blogger::XML::API::ua_request($request); > die $result->status_line unless $result->is_success; > > # END OF CODE > > On Mon, May 31, 2010 at 2:29 PM, Ovid wrote: >> Does anyone have any *working* code (I've seen plenty of failing examples) >> they can share which demonstrates making a successful post to blogger? I've >> failed with both Net::Blogger and Atompub >> (http://stackoverflow.com/questions/2942998/cant-post-with-perls-netblogger). >> >> Cheers, >> Ovid >> -- >> Buy the book - http://www.oreilly.com/catalog/perlhks/ >> Tech blog - http://blogs.perl.org/users/ovid/ >> Twitter - http://twitter.com/OvidPerl >> Official Perl 6 Wiki - http://www.perlfoundation.org/perl6 >> >> >> >> >
Re: Posting to blogger.com?
Here it goes. It's not exactly generic because it's designed to be called from Emacs org-mode, but I hope it will be useful for you. # BEGIN CODE #!/usr/bin/perl use strict; use warnings; use Getopt::Long; use LWP::Simple; use HTML::Entities; use URI::Escape; use XML::Simple; use WWW::Blogger::XML; use File::Slurp; use Data::Dumper; # Get the options from command line. Getopt::Long::GetOptions(\ my %opts, 'org', map "$_=s", qw/blog title categories file/); my $post_body = $opts{file} ? File::Slurp::read_file($opts{file}) : join '', <>; if ($opts{org}) { # Convert tags to categories. if ($post_body =~ s!(?: )*(.+?)!!s) { $opts{categories} = $1; $opts{categories} =~ s! !,!g; $opts{categories} =~ s!___!-!g; $opts{categories} =~ s!__! !g; $opts{categories} = HTML::Entities::decode_entities($opts{categories}); } # Extract post title. $post_body =~ s!\s*]*>(.+?)\s*!!s; $opts{title} = HTML::Entities::decode_entities($1); } # Search for a post with such title. Atom API doesn't seem to allow searching, # so do a normal web search. my $content = LWP::Simple::get( "http://$opts{blog}.blogspot.com?q="; . URI::Escape::uri_escape("\"$opts{title}\"") ); my ($blog_id) = $content =~ /[?&]blogID=(\d+)/; # Look if a post with specified title is present in search results. my $post_id; while ($content =~ m!.+?]+>([^<]+)!sg) { next unless uc HTML::Entities::decode_entities($2) eq uc $opts{title}; # If $post_id is already defined, this must be another post with the same # title. Therefore, the title isn't unique. Die. die "Multiple posts found with the title \"$opts{title}\": $post_id, $2" if defined $post_id; # This is the first match, assign the post id. $post_id = $1; } # Build post as structure for conversion to XML. my %body = ( 'xmlns' => 'http://www.w3.org/2005/Atom', 'content' => { content => $post_body, type=> 'html', }, title => { content => $opts{title}, type=> 'text', }, category => [ map { scheme => 'http://www.blogger.com/atom/ns#', term => $_, }, split /\s*,\s*/, ($opts{categories} || '') ], ); # Create the request. my $request = HTTP::Request->new( $post_id ? 'PUT' : 'POST', $WWW::Blogger::XML::API::url . "/feeds/$blog_id/posts/default/" . ($post_id || ''), [ Content_Type => 'application/atom+xml' ], XML::Simple::XMLout(\%body, RootName => 'entry'), ); # Execute it, dying on failure. my $result = WWW::Blogger::XML::API::ua_request($request); die $result->status_line unless $result->is_success; # END OF CODE On Mon, May 31, 2010 at 2:29 PM, Ovid wrote: > Does anyone have any *working* code (I've seen plenty of failing examples) > they can share which demonstrates making a successful post to blogger? I've > failed with both Net::Blogger and Atompub > (http://stackoverflow.com/questions/2942998/cant-post-with-perls-netblogger). > > Cheers, > Ovid > -- > Buy the book - http://www.oreilly.com/catalog/perlhks/ > Tech blog - http://blogs.perl.org/users/ovid/ > Twitter - http://twitter.com/OvidPerl > Official Perl 6 Wiki - http://www.perlfoundation.org/perl6 > > > >
Re: Posting to blogger.com?
> That would be fantastic! It appears that blogger no longer has an XMLRPC > interface, so Net::Blogger > is pretty much guaranteed to not work. Working with WWW::Google::API right > now, but still getting nowhere. If you produce something suitably generic I'll do my best to get it linked to (and/or included) the Blogger API docs. N (@google.com) -- http://try-dot-ch.blogspot.com/
Re: Posting to blogger.com?
--- On Tue, 1/6/10, Egor Shipovalov wrote: > From: Egor Shipovalov > I do, but the code is on my laptop at > home. As far as I recall it > doesn't use either of these modules, but some different > one. I'll try > post it here tomorrow about the same time. That would be fantastic! It appears that blogger no longer has an XMLRPC interface, so Net::Blogger is pretty much guaranteed to not work. Working with WWW::Google::API right now, but still getting nowhere. Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Tech blog- http://blogs.perl.org/users/ovid/ Twitter - http://twitter.com/OvidPerl Official Perl 6 Wiki - http://www.perlfoundation.org/perl6
Re: Posting to blogger.com?
I do, but the code is on my laptop at home. As far as I recall it doesn't use either of these modules, but some different one. I'll try post it here tomorrow about the same time. Best regards, Egor Shipovalov. On Mon, May 31, 2010 at 2:29 PM, Ovid wrote: > Does anyone have any *working* code (I've seen plenty of failing examples) > they can share which demonstrates making a successful post to blogger? I've > failed with both Net::Blogger and Atompub > (http://stackoverflow.com/questions/2942998/cant-post-with-perls-netblogger). > > Cheers, > Ovid > -- > Buy the book - http://www.oreilly.com/catalog/perlhks/ > Tech blog - http://blogs.perl.org/users/ovid/ > Twitter - http://twitter.com/OvidPerl > Official Perl 6 Wiki - http://www.perlfoundation.org/perl6 > > > >
Posting to blogger.com?
Does anyone have any *working* code (I've seen plenty of failing examples) they can share which demonstrates making a successful post to blogger? I've failed with both Net::Blogger and Atompub (http://stackoverflow.com/questions/2942998/cant-post-with-perls-netblogger). Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Tech blog- http://blogs.perl.org/users/ovid/ Twitter - http://twitter.com/OvidPerl Official Perl 6 Wiki - http://www.perlfoundation.org/perl6