]> git.donarmstrong.com Git - bin.git/blobdiff - jobs_to_org
fix N days ago support for dates
[bin.git] / jobs_to_org
index 3906309d99383f9737f8734d2bb4783afae97b96..fcdfd35345aab2e61ffc34d3591c0414c6961ad8 100755 (executable)
@@ -56,6 +56,7 @@ use vars qw($DEBUG);
 use Data::Printer;
 use Text::Wrap;
 use POSIX qw(strftime);
+use DateTime;
 
 tie my $uuid, 'OSSP::uuid::tie';
 $uuid= ["v1"];
@@ -99,9 +100,21 @@ my %sites =
                 job_selector => [url_regex => qr{^/naturejobs/science/jobs/\d+-.+}],
                 university => [href => qr{^/naturejobs/science/employer-directory/\d+$}],
                 description => [class=>"job-description"],
-                date => [],
+                date => [_tag => 'dd', sub {$_[0]->as_text() =~ qr/\d+\s+days\s+ago$/},],
                 position => [class=>'job-title heading'],
                },
+     vitae => {url => 'https://chroniclevitae.com/job_search?job_search%5Bdistance_from_zip%5D=10&job_search%5Bemployment_type%5D=Full-time&job_search%5Bposition_type%5D=63',
+               next_selector => [text_regex => qr{Next}, url_regex=>qr{^/job_search}],
+               job_selector => [url_regex => qr{/jobs/\d+-\d+$}],
+               university => [href => qr{/institutions/\d+$}],
+               description => [class => 'job-listing__content__description'],
+               date => [_tag => 'td', sub {$_[0]->as_text() =~ qr/\,\s+20\d{2}$/}],
+               position => [_tag => 'h1',
+                            sub {defined $_[0]->parent()->attr('class') and
+                                     $_[0]->parent()->attr('class') eq
+                                     'page-title page-title--two-col'},
+                           ],
+              },
     );
 
 binmode STDOUT,":utf8";
@@ -123,8 +136,8 @@ sub get_jobs {
         my %seen;
         my @job_urls = grep { ! $seen{ $_->URI()->abs() }++ }
             $m->find_all_links(@{$s->{job_selector}});
-        for my $j_u (@job_urls) {
-            $m->get($j_u);
+        for my $j_u (sort @job_urls) {
+            $m->get($j_u) or next;
             my $university = 'No university';
             eval {
                 $university = $m->tree->look_down(@{$s->{university}})->as_text();
@@ -133,6 +146,11 @@ sub get_jobs {
             eval {
                 $date = $m->tree->look_down(@{$s->{date}})->as_text() // $todays_date if
                     @{$s->{date}};
+                if ($date =~ /^\s*(\d+)\s*days\s*ago\s*$/) {
+                    $date = strftime('%Y-%m-%d %H:%M:%S',
+                                     localtime((DateTime->now() -
+                                                DateTime::Duration->new(days=>$1))->epoch));
+                }
             };
             my $description = 'unknown';
             eval {