aboutsummaryrefslogtreecommitdiff
path: root/challenge-161/mark-anderson/raku/create-dictionary.raku
blob: 9f25f002820bafa893a48809465274e20909a932 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env raku

use HTTP::UserAgent :simple;
use DOM::Tiny;

my $url = 'https://github.com/manwar/perlweeklychallenge-club/blob/master/data/dictionary.txt';

getstore($url, 'dictionary.html') unless 'dictionary.html'.IO.e;
 
unless 'dictionary.txt'.IO.e
{
    put 'Be patient - this takes a while...';

    my $dom = DOM::Tiny.parse('dictionary.html'.IO.slurp);

    if my $fh = open 'dictionary.txt', :w 
    { 
        for $dom.find('td') -> $e 
        {
            $fh.put: $e.text if $e.text ~~ /\S/;
        }
        
        $fh.close;
    }
}