Guest User

Untitled

a guest
Mar 14th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. use strict;
  2. use warnings;
  3.  
  4. use AnyEvent;
  5. use AnyEvent::Wassr;
  6. use Encode 'encode_utf8';
  7.  
  8. my $wassr = AnyEvent::Wassr->new(
  9. username => '<your user id>',
  10. password => '<password>',
  11. );
  12.  
  13. sub print_statuses {
  14. my ($wassr, @statuses) = @_;
  15. for my $status (reverse @statuses) {
  16. my $user = encode_utf8 $status->{user}{screen_name};
  17. my $text = encode_utf8 $status->{text};
  18. print "$user: $text\n";
  19. }
  20. }
  21.  
  22. $wassr->reg_cb(
  23. friends_timeline => \&print_statuses,
  24. replies => \&print_statuses,
  25. error => sub {
  26. my ($wassr, $error) = @_;
  27. warn "Error: $error\n";
  28. },
  29. );
  30.  
  31. $wassr->receive_statuses_friends(2);
  32. $wassr->receive_statuses_replies(1);
  33. $wassr->start;
  34.  
  35. my $cv = AE::cv;
  36. my $w = AE::io *STDIN, 0, sub {
  37. my $input = scalar <STDIN>;
  38. chomp($input);
  39. $wassr->update_status(
  40. $input, sub {
  41. my ($wassr, $js_status, $error) = @_;
  42. if (defined $error) {
  43. warn "update error: $error\n";
  44. } else {
  45. my $text = encode_utf8 $js_status->{text};
  46. print qq/update success! "$text"\n/;
  47. }
  48. },
  49. );
  50. };
  51. $cv->recv;
Add Comment
Please, Sign In to add comment