From 24035d8db90a9067fa1842d29a805f615ab1c36d Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Tue, 10 Oct 2017 20:30:26 -0700 Subject: [PATCH] Update udict --- modules/urban | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/modules/urban b/modules/urban index b34c188a..6f2125ef 100755 --- a/modules/urban +++ b/modules/urban @@ -23,6 +23,8 @@ my $usage = "Usage: udict [-m ] [-n \$show_all, 'm=s' => \$match, @@ -30,9 +32,24 @@ my ($ret, $args) = GetOptionsFromString($arguments, 's=s' => \$sort); print "$getopt_error -- $usage" and exit if defined $getopt_error; -print "Missing phrase -- $usage" and exit if @$args == 0; +print "Missing phrase -- $usage" and exit if @$args == 0 and not $match and not $entry; -$args = join(' ', @$args); + +if (@$args == 0) { + open my $fh, "<", "udict.last"; + if ($fh) { + $args = <$fh>; + chomp $args; + close $fh; + } else { + $args = "wtf"; + } +} else { + $args = join(' ', @$args); + open my $fh, ">", "udict.last"; + print $fh "$args\n"; + close $fh; +} my $ud = WebService::UrbanDictionary->new; my $results = $ud->request($args); @@ -79,6 +96,9 @@ sub show_definition { print "$num/$num_entries: "; } + $entry->{'definition'} =~ s/\[(.*?)\]/$1/g; + $entry->{'example'} =~ s/\[(.*?)\]/$1/g if $entry->{'example'}; + print "(+$entry->{'thumbs_up'}/-$entry->{'thumbs_down'}) $entry->{'definition'}\n"; print "$entry->{'example'}\n" if $entry->{'example'}; }