diff options
author | Matthew Lemon <matt@matthewlemon.com> | 2022-09-13 20:47:22 +0100 |
---|---|---|
committer | Matthew Lemon <matt@matthewlemon.com> | 2022-09-13 20:47:22 +0100 |
commit | b31e80034ec923161b91196e169e7e4c261bd4de (patch) | |
tree | e171b485d5d629d10a5eee66009c00b0437b904b /writing_tools/random_line.pl | |
parent | 18588d5bbbb628c7aff04cbfb8b8ad5967c9bd7d (diff) |
clean up a bit and rename
Diffstat (limited to '')
-rw-r--r-- | writing_tools/create_md_links_from_journal_urls.pl (renamed from writing_tools/random_line.pl) | 54 |
1 files changed, 11 insertions, 43 deletions
diff --git a/writing_tools/random_line.pl b/writing_tools/create_md_links_from_journal_urls.pl index 4723f0d..52e78ca 100644 --- a/writing_tools/random_line.pl +++ b/writing_tools/create_md_links_from_journal_urls.pl @@ -12,7 +12,7 @@ use feature qw(say); my $numargs = $#ARGV + 1; sub usage { - say "Pass a search term. All lines in the journal will be matched and URLs quoted will be extracted."; + say "Pass a search term or -all. All lines in the journal will be matched and URLs quoted will be extracted, or -all will do all URLs.."; exit; } @@ -23,16 +23,23 @@ if ($numargs != 1) { my @targetlines; my $searchterm = $ARGV[0]; + my @urls; my $dir = '/home/lemon/Notes/journal'; + foreach my $f (glob("$dir/*.md")) { # printf "%s\n", $f; open my $fh, "<", $f or die "Cannot open that file '$f': $OS_ERROR"; while (<$fh>) { - if ($_ =~ m/$searchterm/) { - # printf " %s", $_; - push @targetlines, $_; + if ($searchterm eq "-all") { + push @targetlines, $_; + } + else { + if ($_ =~ m/$searchterm/) { + # printf " %s", $_; + push @targetlines, $_; + } } } close $fh or die "can't read close file '$f': $OS_ERROR"; @@ -55,15 +62,6 @@ foreach my $line (@targetlines) { my$t = $1; $t =~ s/\.$//; # remove the fullstop if it has one at the end push @urls => striptime($t) - # my $req = HTTP::Request->new(GET => $t); - # $req->header(Accept => "text/html"); - # my $res = $ua->request($req); - # my $p = HTML::HeadParser->new; - # $p->parse($res->content) and print "not finished"; - # print $p->header('Title'), "\n"; - # my $root = HTML::TreeBuilder->new_from_content($res->content); - # my $title = $root->look_down('_tag' => 'title'); - # my $value = $title->attr('value'); } } @@ -87,33 +85,3 @@ foreach my $url (@uniqueurls) { my $title = $p->header('Title'); print create_mdlink($url, $title), "\n"; } - - - -# foreach my $url (@urls) { -# print $url; -# my $req = HTTP::Request->new(GET => $url); -# $req->header(Accept => "text/html"); -# my $res = $ua->request($req); - -# my $root = HTML::TreeBuilder->new_from_content($req->content); - -# print $root; -# # my @elements = $root->look_down(_tag => "title"); -# # foreach my $thing (@elements) { -# # print $thing->as_text, "\n"; -# # } -# } - - - - - - -# if ($res->is_success) { -# $tree->parse($res->as_string); -# } -# else { -# print $res->status_line, "\n"; -# } - |