I'm trying to automatically post to blogger using Perl's Net::Blogger but it keeps returning false and not posting. The main portion of my code looks like this:
use Net::Blogger;
my $blogger = Net::Blogger->new({
debug => 1,
appkey => '0123456789ABCDEF', # doesn't matter?
blogid => $blogid,
username => $username,
password => $password,
});
my $result = $blogger->newPost({
postbody => \'<p>This is text</p><hr/><p><strong>Whee!</strong></p>',
publish => 1,
});
use Data::Dumper;
print Dumper($result);
Sure enough, $result is 0 and in checking the blog, nothing has been posted. The error I'm getting when I enable debugging is:
Element '' can't be allowed in valid XML message.
Died. at /Library/Perl/5.10.1/SOAP/Lite.pm line 1410.
What am I doing wrong?
If you can suggest an alternative to Net::Blogger, that would be fine.
Update: if I don't enable debugging, it hangs for quite a while when trying to post.
I can understand your frustration, I don't like it when I try to use a CPAN module which is seductively named (i.e. looks like a good scratch for the itch) but is ultimately not useful. However, Net::Blogger had its last update in 2006 so I think it would be incredible if it still worked as originally intended, given that blogger has been evolving over the years.
Per daxim's rec, I made a quick attempt to install Atompub on OS X via CPAN.pm, but failed due to a hard dependency on Perl::Critic, which won't install. I figure I know how to fix this but I'll need a better reason than this to go to the effort.
I saw this note in the Net::Blogger perldoc which if nothing else provides a hint on another module to try, for anyone who didn't feel like beating Atompub into submission:
The Atom API
In January 2004, Blogger announced
their support for the Atom API.
As of this writing (version 0.87) this
package does not support the Atom API.
If you need to do things Atom-ish,
your best bet is to use the XML::Atom
package.
Alternative as you requested: after all the different blogging APIs, a standard in the form of RFC 5023 emerged.
Atompub works fine.
I worked a bit with Net::Logger today and managed to publish an entry into Blogger, the problem is that only the body can be set (no Atom supported as virtualsue told).
Please take a look at my Perl Posting to Blogger blues entry for some help.
Related
Well, at the moment i have two goals.
User don't have Edit bug rights in bugzilla, but he/she should write/post comments on that bug. I think this could be possible by the following API, but I am not sure, since I am new in bugzilla and Perl. http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bug.html#add_comment
I want to import bugs by using importxml.pl, but I don't want new entries in DB. I just want to modify some fields of existing bugs of bugzilla, on the base of bug.xml file which contains bug info.
i.e. perl -T C:\bugzilla\bugzilla\importxml.pl -v C:\bugzilla\bugzilla\mybugs\bug.xml
Might be following API could be helpful, but I am not sure.
http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bug.html#update
So, what are possible ways to achieve these goals ??
As I am thinking, may be i should use the methods of these APIs into existing bugzilla code and my dreams are:
comments would be enabled for the user who don't have bug-edit right.
I'll run the importxml.pl script from command line by passing some parameters and I'll modify some fields of existing bugs.
But I am not sure, either I am thinking right or wrong. I also don't know how to use the method of these APIs??
The email_in.pl script can do the types of things you are asking. However, you will need to create a user that does have permissions to make the changes and you will need to transform the data into a form that email_in.pl understands.
http://www.bugzilla.org/docs/4.2/en/html/api/email_in.html
I can help with the first point:
Here's an excerpt from a a svn_bz_append.pl script (http://www.telegraphics.com.au/svn/svn_bz/trunk/) that I've modified that I use to update bugzilla comments on svn commits. Note that I have this script running on the same machine as the Bugzilla install, as it uses modules from within the Bugzilla directory. I have this working for Bugzilla v 4.2.3.
I've omitted quite a bit of this script to pull out the excerpt below:
use strict;
use warnings;
use Bugzilla;
use Bugzilla::Config;
use Bugzilla::Bug;
use Data::Dumper;
... create/fetch the userid and some bug Ids to work on ...
eg:
my $userid = 1;
my #bugs = ( 1, 2, 3 );
my $message = 'Say something here';
... now loop through the bug ids and add the comment...
foreach my $bugId (#bugs) {
my $user = new Bugzilla::User({ id => $userid})
|| ThrowUserError('invalid_username', { id => $userid}); #get the user from bugzilla
print STDERR 'user: '. Dumper($user); #pretty prints the user object
Bugzilla->set_user($user); #this authenticates the user so that you may perform actions on bugs that the user has permissions to.
my $bug = Bugzilla::Bug->check($bugId); #gets the bug
print STDERR 'bug: '. Dumper($bug); #pretty prints the bug object
$bug->add_comment($message); #adds a comment to the bug
$bug->update(); #updated the bug - don't forget to do this!
}
Please note that the Dumper functions are just using the excellent Data::Dumper module: http://perldoc.perl.org/Data/Dumper.html - you don't need them except for debugging.
The log in info came from: How can I authenticate when using the Bugzilla Perl API in a script?
I believe this may be a bug in the module I am using, or I am just completely overlooking something.
My code is this:
#!/usr/bin/perl
use strict;
use warnings;
use CAM::PDF;
use CAM::PDF::Annot;
sub main()
{
my $pdf = CAM::PDF::Annot->new( 'b.pdf' );
my $otherDoc = CAM::PDF::Annot->new( 'b_an.pdf' );
my $page = 1;
my %refs;
my #list = #{$pdf->getAnnotations($page)};
for my $annotRef (#list){
$otherDoc->appendAnnotation( $page, $pdf, $annotRef, \%refs);
}
$otherDoc->output('pdf_merged.pdf');
}
exit main;
This code was taken almost directly from the synopsis found on the module's CPAN page: http://metacpan.org/pod/CAM::PDF::Annot
The problem comes when I run the script using TWO pdf's with annotations. Using two pdf's without annotations runs. Using one pdf with annotations, and one pdf without annotations, runs. Only when both pdf's have annotations does it error.
The error is: "Can't use string ("46") as an ARRAY ref while "strict refs" in use at /usr/opt/perl5/lib/site_perl/5.10.1/CAM/PDF/Annot.pm line 195"
Line 195 of Annot.pm is:
push #{$annots->{value}}, $pupRef;
Annot.pm is inside the CAM::PDF::Annot module.
Any guidance in fixing this would be greatly appreciated!
P.S. In the error, "string ("x")", x is always a number, and seems to change depending on the pdf and the annotations within the pdf.
And I will try to add any other information that you need to help figure this out!
Whenever I have a problem with a CPAN module, I go to its webpage to try and assess its quality and see if any bugs have already been reported.
http://search.cpan.org/~donatoaz/CAM-PDF-Annot-0.06 shows the following suspicious results:
CPAN Testers PASS (2) FAIL (168) NA (49)
It is surprising that you were able to install the module. No one has reported bugs, but there is clearly a major problem with the code. It seems the author is either unaware of the tester reports (which have been sent to his CPAN email address for more than a year), or has stopped maintaining it.
You could submit a bug report, so at least others will be aware of your issue.
I realize this does not answer your question of how to fix the problem, but even if you do identify a fix, the author may not apply it (in which case, someone could start the process of becoming a co-maintaner).
I'm having a strange problem here. I'm moving a (working) site to a new apache server to which I don't have direct access (I have to go through two people to get stuff done).
The site uses a perl script called adframe to parse html templates. The URLs with which it's called look like /cgi-bin/adframe/index.html?x=something with adframe being the script. The missing suffix never caused any real problems. But on this new Ubuntu server $ENV{'QUERY_STRING'} is always empty. $ENV{'REQUEST_METHOD'} shows up correctly as GET, but the query_string shows nothing ...
Regular *.cgi scripts show the query_string without problems.
From the logs I gathered that the server seems to be running fastcgi, mod_fcgid and the server doesn't even accept .pl as an extension for scripts. I don't have that much experience with server software, but I figured it might be a problem with the server not accepting adframe as a cgi script and thus not passing the query_string correctly ... Can anyone give me a few hints to where I could point the administrator or maybe something I could do in .htaccess myself? Anyway to make sure, adframe is recognized as a cgi script!? (if that's the problem ...)
Any help is appreciated!
thomas
EDIT: I found more details: The server seems to be running a VARNISH cache ... thats's the main difference to my usual configurations ...
Also, the way the script works is, if you call /cgi-bin/adframe/somedir/somefile.html?x=something, $ENV{PATH_INFO} tells which template to parse and $ENV{QUERY_STRING} is, well, the query string. Now the query string is empty, but if I call /cgi-bin/adframe?x=something (without any PATH_INFO), the query string shows up!
Does anyone have an idea what's going on here?
thanks!
Got it. The VARNISH cache strips all the query strings off static content (*.html etc) ... phew
Just ran into the same problem. I am complete newbie in perl scripting.
I tried following:
#values = split (/&/, $ENV{'QUERY_STRING'});
but it didn`t work
this worked:
#values = split (/&/, "$ENV{'QUERY_STRING'}");
just in case if other newbies have ran into the same problem.
Has anyone used the createHITType function in the Perl Amazon Mechanical Turk SDK to add Notification properties to their HIT?
I've managed to get it all working. I can grab the balance from both my sandbox account and the live system. I've successfully created new hits using the various techniques in the samples dir, but I need to enable SetHITTypeNotification, passing on properties that tell Amazon to notify me by email when someone accepts/submits a hit.
I've checked through the documentation on AWS and the rough schema would be this:
<Notification>
<Destination>me#email.com</Destination>
<Transport>Email</Transport>
<Version>2006-10-31</Version>
<EventType>AssignmentAccepted</EventType>
<EventType>AssignmentSubmitted</EventType>
</Notification>
I've done some grep'ing through the various modules looking for notification and came across the BulkSupport.pm module that seems to make reference to notifications contained as a hash within a properties object passed to the createHITType function.
I also think that it is taking these from perhaps a properties file, but I've specifically learnt Perl to use mturk along with another project, so I am now stumped to figure out what to do. I perldoc'ed the crap out of all the modules too, but there is a complete lack of documentation on implementing notifications from what I can find.
I found a solution in perl without the need of the XML structure:
my $mturk2 = Net::Amazon::MechanicalTurk->new(serviceUrl=>"prod");
my $result2 = $mturk2->SetHITTypeNotification(
HITTypeId => 'EXAMPLE00000000000EXAMPLE00000',
Notification => {
Transport => 'Email',
Destination => 'me#email.com',
EventType => 'AssignmentSubmitted',
Version => '2006-05-05'
},
Active => 'true'
);
print $result->toString;
using the module: Net::Amazon::MechanicalTurk
I'm playing around with Win32::IE:Mechanize to try to access some authentication-required sites automatically. So far I've achieved moderate success, for example, I can automatically log in to my yahoo mailbox. But I find many sites are using some kind of image verification mechanism, which is possibly called CAPTCHA. I can do nothing to them. But one of the sites I'm trying to auto access is using a plain-text verification code. It is comnposed of four digits, selectable and copyable. But they're not in the source file which can be fetched using
$mech->content;
I searched for the keyword that appears on the webpage but not in the source file through all the files in the Temporary Internet Files but still can't find it.
Any idea what's going on? I was suspecting that the verification code was somehow hidden in some cookie file but I can't seem to find it :(
The following is the code that completes all the fields requirements except for the verification code:
use warnings;
use Win32::IE::Mechanize;
my $url = "http://www.zjsmap.com/smap/smap_login.jsp";
my $eccode = "myeccode";
my $username = "myaccountname";
my $password = "mypassword";
my $verify = "I can't figure out how to let the script get the code yet"
my $mech = Win32::IE::Mechanize->new(visible=>1);
$mech->get($url);
sleep(1); #avoids undefined value error
$mech->form_name("BaseForm");
$mech->field(ECCODE => $eccode);
$mech->field(MEMBERACCOUNT => $username);
$mech->field(PASSWORD => $password);
$mech->field(verify => $verify);
$mech->click();
Like always any suggestions/comments would be greatly appreciated :)
UPDATE
I've figured out a not-so-smart way to solve this problem. Please comment on my own asnwer posted below. Thanks like always :)
This is the reason why they are there. To stop program like yours to do automated stuff ;-)
A CAPTCHA or Captcha is a type of
challenge-response test used in
computing to ensure that the response
is not generated by a computer.
This appears to be an irrelevant number. The page uses it in 3 places: generating it; displaying it on the form next to the input field for it; and checking for the input value being equal to the random number chosen. That is, it is a client-only check. Still, if you disable javascript it looks like, I'm guessing, important cookies don't get set. If you can execute JavaScript in the context of the page (you should be able to with a get method call and a javascript URI), you could change the value of random_number to f.e. 42 and fill that in on the form.
The code is inserted by JavaScript – disable JS, reload the page and see it disappear. You have to hunt through the JS code to get an idea where it comes from and how to replicate it.
Thanks to james2vegas, zoul and Shoban.
I've finally figured out on my own a not-so-smart but at-least-workable way to solve the problem I described here. I'd like to share it here. I think the approach suggested by #james2vegas is probably much better...but anyway I'm learning along the way.
My approach is this:
Although the verification code is not in the source file but since it is still selectable and copyable, I can let my script copy everything in the login page and then extract the verification code.
To do this, I use the sendkeys functions in the Win32::Guitest module to do "Select All" and "Copy" to the login page.
Then I use Win32:Clipboard to get the clipboard content and then Regexp to extract the code. Something like this:
$verify = Win32::Clipboard::GetText();
$verify =~ s/.* (\d{4}).*/$1/msg;
A few thoughts:
The random number is generated by something like this in Perl
my $random_number = int(rand(8999)) + 1000; #var random_number = rand(1000,10000);
And then it checks if $verify == $random_number. I don't know how to catch the value of one-session-only $random_number. I think it is stored somewhere in the memory. If I can capture the value directly then I wouldn't have gone to so much trouble of using this and that extra module.