# TTYtter Twitpher gopher<-twitter handler for public timeline # invoke with -lib=... -silent. do NOT use -daemon (see below). # # this is all Ed Finkler's fault. # Cameron Kaiser $Lib_arg = substr($twarg, 0, 25); # no buffer overflow FOR YOU! $Lib_arg =~ s/[^a-zA-Z0-9_]//g; # no shell metacharacters FOR YOU! $Lib_me = "/fun/twitpher"; $dmpause = 0; $Lib_source = (length($Lib_arg)) ? "user \@$Lib_arg" : "the public timeline"; $url = (length($Lib_arg)) ? "http://twitter.com/statuses/user_timeline/$Lib_arg.json" : "http://twitter.com/statuses/public_timeline.json"; $silent = 1; $anonymous = 1; $seven = 1; # after all, this *is* gopher # so that ttytter can find lynx/curl, or it will gripe $ENV{'PATH'} = "/bin:/usr/bin:/usr/local/bin:/usr/pkg/bin"; # dup STDOUT so -silent works, but ve can steell speek! open(LIB_Q, ">&STDOUT"); select(LIB_Q); $|++; $Lib_gwrap = sub { my $itype = shift; my $string = shift; my $host = ($itype ne 'i') ? 'gopher.floodgap.com' : 'error.host'; my $port = ($itype ne 'i') ? 70 : 1; my $sel = shift; print LIB_Q "$itype$string\t$sel\t$host\t$port\r\n"; }; $Lib_gclose = sub { &$Lib_gwrap('i', ''); &$Lib_gwrap(1, "Twitter public timeline via Twitpher", $Lib_me); &$Lib_gwrap('h', "\@${Lib_arg}'s Twitter page (WWW)", "URL:http://twitter.com/$Lib_arg") if (length($Lib_arg)); &$Lib_gwrap('h', "Powered by TTYtter (WWW)", "URL:http://www.floodgap.com/software/ttytter/"); &$Lib_gwrap(1, "Twitpher written by \@doctorlinguist", "$Lib_me?doctorlinguist"); print LIB_Q ".\r\n\r\n"; close(LIB_Q); }; $dmhandle = sub { return 0; # refuse, and shouldn't even happen }; $dmconclude = sub { return 0; # refuse }; $console = sub { &$Lib_gwrap(1, "Floodgap Gopher Fun and Games", "/fun"); while() { chomp; s/SOURCE/$Lib_source/; &$Lib_gwrap('i', $_); } &$Lib_gwrap('i', 'Click a tweet to see more from that user.') unless (length($Lib_arg)); &$Lib_gwrap('i', 'Click replies to see more from the user referenced.') if (length($Lib_arg)); &$Lib_gwrap('i', ' '); sleep 10; # so that we can handle our own timeouts. thus NO -DAEMON. &$Lib_gwrap(1, "** timeout, please reload this page **", (length($Lib_arg)) ? "$Lib_me?$Lib_arg" : $Lib_me); &$Lib_gclose; kill 9, $child; # SIGKILL (SIGINT's too good for them) exit; }; $exception = sub { # is this not working? will investigate for 0.7 my $en = shift; my $et = shift; &$Lib_gwrap('i', "Error $en: $et"); &$conclude; }; $handle = sub { my $ref = shift; my $user = &descape($ref->{'user'}->{'screen_name'}); my $text = &descape($ref->{'text'}); my $string = "<$user> $text -- @{[ &descape($ref->{'created_at'}) ]}"; if (length($Lib_arg)) { if ($text =~ /^\@([a-zA-Z0-9_]+)/) { &$Lib_gwrap('1', $string, "$Lib_me?$1"); } else { &$Lib_gwrap('i', $string); } } else { &$Lib_gwrap('1', $string, "$Lib_me?$user"); } return 1; }; $conclude = sub { &$Lib_gwrap('i', "** No data returned ** Wrong username? **") unless ($last_id || !length($Lib_arg)); &$Lib_gclose; kill 9, $parent; # SIGKILL exit; }; __DATA__ _ _ _ _ | |___ __ _(_) |_ _ __| |_ ___ _ _ | _\ V V / | _| '_ \ ' \/ -_) '_| \__|\_/\_/|_|\__| .__/_||_\___|_| Gopher-Twitter |_| gateway Reload for most current tweets from SOURCE.