Guest User

Untitled

a guest
Mar 10th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. use strict;
  2. use warnings;
  3. use Encode ();
  4. use AnyEvent::Twitter;
  5. use AnyEvent::ReverseHTTP 0.04;
  6. use Config::Pit qw/pit_get/;
  7. use HTTP::Request::AsCGI ();
  8. use CGI::Simple ();
  9.  
  10. my $config = pit_get(
  11. "b2t",
  12. require => {
  13. "username" => "your username",
  14. "password" => "your password",
  15. "label" => "your reverse http label",
  16. }
  17. );
  18.  
  19. my $twitty = AnyEvent::Twitter->new(
  20. username => $config->{username},
  21. password => $config->{password},
  22. );
  23.  
  24. my $guard = reverse_http $config->{label}, sub {
  25. my $req = shift;
  26.  
  27. my $c = HTTP::Request::AsCGI->new($req)->setup;
  28. my $q = CGI::Simple->new;
  29.  
  30. my $msg = '[B]'
  31. . join(
  32. ' ',
  33. (
  34. map { Encode::decode_utf8($_) } $q->param('title'), $q->param('url')
  35. )
  36. );
  37. if ($msg =~ /\S/) {
  38. warn "POSTING $msg";
  39. $twitty->update_status($msg, sub {
  40. my ($twitty, $status, $js_status, $error) = @_;
  41. if (defined $error) {
  42. warn "ERROR: $error";
  43. } else {
  44. warn "posted";
  45. }
  46. });
  47. }
  48.  
  49. return "OK";
  50. };
  51.  
  52. AnyEvent->condvar->recv;
  53.  
  54. # Copyright (C) 2009 tokuhirom
  55. # licensed by artistic license.
Add Comment
Please, Sign In to add comment