aboutsummaryrefslogtreecommitdiffstats
path: root/writing_tools/create_md_links_from_journal_urls.pl
diff options
context:
space:
mode:
authorMatthew Lemon <matt@matthewlemon.com>2022-09-13 21:27:18 +0100
committerMatthew Lemon <matt@matthewlemon.com>2022-09-13 21:27:18 +0100
commit2e18bc6a11af1865192c1c4651928ed461c33437 (patch)
tree47c3d17af9e444378fce19376e9d5045eac08b5e /writing_tools/create_md_links_from_journal_urls.pl
parentb31e80034ec923161b91196e169e7e4c261bd4de (diff)
good enough to generate a list of markdown urls to pipe into file
Diffstat (limited to 'writing_tools/create_md_links_from_journal_urls.pl')
-rw-r--r--writing_tools/create_md_links_from_journal_urls.pl26
1 files changed, 19 insertions, 7 deletions
diff --git a/writing_tools/create_md_links_from_journal_urls.pl b/writing_tools/create_md_links_from_journal_urls.pl
index 52e78ca..a03aa23 100644
--- a/writing_tools/create_md_links_from_journal_urls.pl
+++ b/writing_tools/create_md_links_from_journal_urls.pl
@@ -7,6 +7,8 @@ use HTML::TreeBuilder 5 -weak;
use HTML::HeadParser;
use feature qw(say);
+$| = 1; # turn on autoflush for stdout (https://stackoverflow.com/questions/40608986/print-doesnt-work-while-iterations-are-going-inside-foreach-loop)
+
# How to read each file in a directory $dir
my $numargs = $#ARGV + 1;
@@ -72,16 +74,26 @@ my @uniqueurls = keys %riddups;
sub create_mdlink {
my ($url, $title) = @_;
+ if ($title eq "") {
+ $title = "- UKNOWN TITLE -";
+ }
+
return "[".$title."]"."(".$url.")"
}
+my @mdurls;
+
foreach my $url (@uniqueurls) {
- my $req = HTTP::Request->new(GET => $url);
- $req->header(Accept => "text/html");
- my $res = $ua->request($req);
- my $p = HTML::HeadParser->new;
- $p->parse($res->content) and print "not finished";
- my $title = $p->header('Title');
- print create_mdlink($url, $title), "\n";
+ my $req = HTTP::Request->new(GET => $url);
+ $req->header(Accept => "text/html");
+ my $res = $ua->request($req);
+ my $p = HTML::HeadParser->new;
+ $p->parse($res->content) and print "not finished";
+ my $title = $p->header('Title');
+ push @mdurls => create_mdlink($url, $title);
}
+
+$, = "\n\n- ";
+print "\n\n";
+print @mdurls;